{"record":{"id":"9d80d803e174109f","repo":"langchain-ai/langchain","slug":"both-var-name-path-and-var-name-cannot-be","errorCode":null,"errorMessage":"Both `{var_name}_path` and `{var_name}` cannot be provided.","messagePattern":"Both `(.+?)_path` and `(.+?)` cannot be provided\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/loading.py","lineNumber":95,"sourceCode":"\n    if config_type not in type_to_loader_dict:\n        msg = f\"Loading {config_type} prompt not supported\"\n        raise ValueError(msg)\n\n    prompt_loader = type_to_loader_dict[config_type]\n    return prompt_loader(config, allow_dangerous_paths=allow_dangerous_paths)\n\n\ndef _load_template(\n    var_name: str, config: dict[str, Any], *, allow_dangerous_paths: bool = False\n) -> dict[str, Any]:\n    \"\"\"Load template from the path if applicable.\"\"\"\n    # Check if template_path exists in config.\n    if f\"{var_name}_path\" in config:\n        # If it does, make sure template variable doesn't also exist.\n        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","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/loading.py#L77-L113","documentation":"In `_load_template`, a prompt config may specify a template either inline (`template: ...`) or by file (`template_path: ...`), but not both. Supplying both `{var_name}` and `{var_name}_path` (e.g. `template` and `template_path`, or `prefix` and `prefix_path`) raises this `ValueError` because the loader would not know which source wins.","triggerScenarios":"A JSON/YAML prompt config containing both `\"template\"` and `\"template_path\"` keys (or `prefix`+`prefix_path`, `suffix`+`suffix_path` in few-shot configs), passed to `load_prompt`/`load_prompt_from_config`.","commonSituations":"Editing a config that originally used `template_path` by pasting the template text in but forgetting to delete the path key; merging config files by hand; leftovers from template extraction tooling.","solutions":["Delete one of the two keys: keep `template` with the inline text, or keep `template_path` pointing at a `.txt` file.","If you merged configs programmatically, add a pre-check that pops duplicate keys before loading."],"exampleFix":"# before\n# prompt.json\n# {\"_type\": \"prompt\", \"template\": \"Hi {name}\", \"template_path\": \"t.txt\",\n#  \"input_variables\": [\"name\"]}\nload_prompt('prompt.json')  # ValueError\n\n# after\n# {\"_type\": \"prompt\", \"template\": \"Hi {name}\", \"input_variables\": [\"name\"]}\nload_prompt('prompt.json')","handlingStrategy":"validation","validationCode":"for var in ('template', 'prefix', 'suffix'):\n    if var in config and f'{var}_path' in config:\n        del config[f'{var}_path']  # inline value wins; or raise\nload_prompt_from_config(config)","typeGuard":"def has_no_inline_path_conflict(config: dict, var: str) -> bool:\n    return not (var in config and f'{var}_path' in config)","tryCatchPattern":null,"preventionTips":["Adopt a convention: configs use either all-inline or all-path references, never mixed.","Lint prompt configs in CI for key-pair conflicts (template/template_path etc.)."],"tags":["prompts","loading","config","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}