{"record":{"id":"3e9173742e499663","repo":"langchain-ai/langchain","slug":"loading-templates-with-template-format-format","errorCode":null,"errorMessage":"Loading templates with '{template_format}' format is no longer supported since it can lead to arbitrary code execution. Please migrate to using the 'f-string' template format, which does not suffer from this issue.","messagePattern":"Loading templates with '(.+?)' format is no longer supported since it can lead to arbitrary code execution\\. Please migrate to using the 'f-string' template format, which does not suffer from this issue\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/loading.py","lineNumber":206,"sourceCode":"    config: dict[str, Any], *, allow_dangerous_paths: bool = False\n) -> PromptTemplate:\n    \"\"\"Load the prompt template from config.\"\"\"\n    # Load the template from disk if necessary.\n    config = _load_template(\n        \"template\", config, allow_dangerous_paths=allow_dangerous_paths\n    )\n    config = _load_output_parser(config)\n\n    template_format = config.get(\"template_format\", \"f-string\")\n    if template_format == \"jinja2\":\n        # Disabled due to:\n        # https://github.com/langchain-ai/langchain/issues/4394\n        msg = (\n            f\"Loading templates with '{template_format}' format is no longer supported \"\n            f\"since it can lead to arbitrary code execution. Please migrate to using \"\n            f\"the 'f-string' template format, which does not suffer from this issue.\"\n        )\n        raise ValueError(msg)\n\n    return PromptTemplate(**config)\n\n\n@deprecated(\n    since=\"1.2.21\",\n    removal=\"2.0.0\",\n    alternative=\"Use `dumpd`/`dumps` from `langchain_core.load` to serialize \"\n    \"prompts and `load`/`loads` to deserialize them.\",\n)\ndef load_prompt(\n    path: str | Path,\n    encoding: str | None = None,\n    *,\n    allow_dangerous_paths: bool = False,\n) -> BasePromptTemplate[str]:\n    \"\"\"Unified method for loading a prompt from LangChainHub or local filesystem.\n","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/loading.py#L188-L224","documentation":"When loading a `prompt`-type config, `_load_prompt` explicitly rejects `template_format: \"jinja2\"` because untrusted Jinja2 templates can execute arbitrary Python code (CVE-class issue tracked in langchain issue #4394). Loading was disabled at deserialization time even though in-code Jinja2 `PromptTemplate`s still work.","triggerScenarios":"Loading a prompt config/Hub file whose `template_format` is `jinja2` (or omitting nothing — default is `f-string`, so only an explicit `jinja2` triggers it) via `load_prompt`/`load_prompt_from_config`.","commonSituations":"Legacy Hub prompts written with Jinja2; teams that preferred Jinja2 syntax and serialized prompts to disk; loading third-party prompt packs that use `{{ var }}` syntax.","solutions":["Rewrite the template to f-string syntax (`{var}` instead of `{{ var }}`, removing Jinja filters) and set `template_format` to `f-string` or remove the key.","If you must use Jinja2, construct the template in code — `PromptTemplate.from_template(t, template_format='jinja2')` — from a source you trust, rather than via the config loader.","Sanitize/audit any third-party template before hand-converting it."],"exampleFix":"# before\n# {\"_type\": \"prompt\", \"template\": \"Hello {{ name | upper }}\",\n#  \"template_format\": \"jinja2\", \"input_variables\": [\"name\"]}\nload_prompt('prompt.json')  # ValueError\n\n# after\n# {\"_type\": \"prompt\", \"template\": \"Hello {name}\",\n#  \"input_variables\": [\"name\"]}\nload_prompt('prompt.json')","handlingStrategy":"validation","validationCode":"tf = config.get('template_format', 'f-string')\nif tf == 'jinja2':\n    raise ValueError(\n        'Refusing to load jinja2 template from config (code execution risk); '\n        'convert to f-string first.'\n    )\nload_prompt_from_config(config)","typeGuard":"def is_safe_template_format(fmt: str) -> bool:\n    return fmt in {'f-string', 'mustache'}","tryCatchPattern":null,"preventionTips":["Never load Jinja2 prompt configs from untrusted sources; convert to f-string before storing.","Audit third-party prompt packs for template_format: jinja2 before loading."],"tags":["prompts","security","jinja2","loading","code-execution"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}