jinja2_formatter#
- langchain_core.prompts.string.jinja2_formatter(template: str, **kwargs: Any) str [source]#
Format a template using jinja2.
- Security warning:
As of LangChain 0.0.329, this method uses Jinja2’s SandboxedEnvironment by default. However, this sand-boxing should be treated as a best-effort approach rather than a guarantee of security. Do not accept jinja2 templates from untrusted sources as they may lead to arbitrary Python code execution.
- Parameters:
template (str) – The template string.
**kwargs (Any) – The variables to format the template with.
- Returns:
The formatted string.
- Raises:
ImportError – If jinja2 is not installed.
- Return type:
str