{"record":{"id":"200abf3a9439b5fe","repo":"langchain-ai/langchain","slug":"unsupported-template-file-format-resolved-path","errorCode":null,"errorMessage":"Unsupported template file format: '{resolved_path.suffix}'. Only '.txt' files are supported.","messagePattern":"Unsupported template file format: '(.+?)'\\. Only '\\.txt' files are supported\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/loading.py","lineNumber":111,"sourceCode":"        if var_name in config:\n            msg = f\"Both `{var_name}_path` and `{var_name}` cannot be provided.\"\n            raise ValueError(msg)\n        # Pop the template path from the config.\n        template_path = Path(config.pop(f\"{var_name}_path\"))\n        if not allow_dangerous_paths:\n            _validate_path(template_path)\n        # Resolve symlinks before checking the suffix so that a symlink named\n        # \"exploit.txt\" pointing to a non-.txt file is caught.\n        resolved_path = template_path.resolve()\n        # Load the template.\n        if resolved_path.suffix == \".txt\":\n            template = resolved_path.read_text(encoding=\"utf-8\")\n        else:\n            msg = (\n                f\"Unsupported template file format: '{resolved_path.suffix}'. \"\n                \"Only '.txt' files are supported.\"\n            )\n            raise ValueError(msg)\n        # Set the template variable to the extracted variable.\n        config[var_name] = template\n    return config\n\n\ndef _load_examples(\n    config: dict[str, Any], *, allow_dangerous_paths: bool = False\n) -> dict[str, Any]:\n    \"\"\"Load examples if necessary.\"\"\"\n    if isinstance(config[\"examples\"], list):\n        pass\n    elif isinstance(config[\"examples\"], str):\n        path = Path(config[\"examples\"])\n        if not allow_dangerous_paths:\n            _validate_path(path)\n        with path.open(encoding=\"utf-8\") as f:\n            if path.suffix == \".json\":\n                examples = json.load(f)","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/loading.py#L93-L129","documentation":"When a prompt config points at a template file via `template_path` (or `prefix_path`/`suffix_path`), `_load_template` reads the file only if its resolved suffix is `.txt`; any other extension raises this `ValueError`. The path is resolved (symlinks included) before the check, so a symlink named `x.txt` pointing to a non-`.txt` target is also caught.","triggerScenarios":"Config with `\"template_path\": \"templates/tmpl.j2\"` (or `.md`, `.jinja`, no extension, etc.). Also when `template_path` is a `.txt` symlink whose resolved target has a different suffix.","commonSituations":"Teams storing prompts as `.j2`/`.jinja`/`.md` files; editors auto-appending extensions; symlinks from a `.txt` name into a templates directory with different naming.","solutions":["Rename the template file to end in `.txt` (contents can still be any template syntax).","Inline the template into the config under `template` instead of using `template_path`.","Fix symlinks so both the link name and the resolved target end in `.txt`."],"exampleFix":"# before\n# {\"_type\": \"prompt\", \"template_path\": \"prompts/greet.j2\"}\nload_prompt('prompt.json')  # ValueError\n\n# after\n# rename file to prompts/greet.txt\n# {\"_type\": \"prompt\", \"template_path\": \"prompts/greet.txt\"}\nload_prompt('prompt.json')","handlingStrategy":"validation","validationCode":"from pathlib import Path\nfor key in ('template_path', 'prefix_path', 'suffix_path'):\n    if key in config:\n        p = Path(config[key]).resolve()\n        if p.suffix != '.txt':\n            raise ValueError(f'{key} must reference a .txt file, got {p.suffix}')\nload_prompt_from_config(config)","typeGuard":"def is_txt_path(path: str | Path) -> bool:\n    return Path(path).resolve().suffix == '.txt'","tryCatchPattern":null,"preventionTips":["Standardize all template files referenced by configs on the `.txt` extension.","Avoid symlinks into differently-named template files."],"tags":["prompts","loading","file-format","config"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}