{"record":{"id":"05ad00db1da094e1","repo":"langchain-ai/langchain","slug":"got-unsupported-file-type-file-path-suffix","errorCode":null,"errorMessage":"Got unsupported file type {file_path.suffix}","messagePattern":"Got unsupported file type (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/loading.py","lineNumber":270,"sourceCode":"def _load_prompt_from_file(\n    file: str | Path,\n    encoding: str | None = None,\n    *,\n    allow_dangerous_paths: bool = False,\n) -> BasePromptTemplate[str]:\n    \"\"\"Load prompt from file.\"\"\"\n    # Convert file to a Path object.\n    file_path = Path(file)\n    # Load from either json or yaml.\n    if file_path.suffix == \".json\":\n        with file_path.open(encoding=encoding) as f:\n            config = json.load(f)\n    elif file_path.suffix.endswith((\".yaml\", \".yml\")):\n        with file_path.open(encoding=encoding) as f:\n            config = yaml.safe_load(f)\n    else:\n        msg = f\"Got unsupported file type {file_path.suffix}\"\n        raise ValueError(msg)\n    # Load the prompt from the config now.\n    return load_prompt_from_config(config, allow_dangerous_paths=allow_dangerous_paths)\n\n\ndef _load_chat_prompt(\n    config: dict[str, Any],\n    *,\n    allow_dangerous_paths: bool = False,  # noqa: ARG001\n) -> ChatPromptTemplate:\n    \"\"\"Load chat prompt from config.\"\"\"\n    messages = config.pop(\"messages\")\n    template = messages[0][\"prompt\"].pop(\"template\") if messages else None\n    config.pop(\"input_variables\")\n\n    if not template:\n        msg = \"Can't load chat prompt without template\"\n        raise ValueError(msg)\n","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/loading.py#L252-L288","documentation":"`_load_prompt_from_file` dispatches on the file suffix: `.json` is parsed with `json.load`, `.yaml`/`.yml` with `yaml.safe_load`; every other suffix raises `ValueError: Got unsupported file type {suffix}`. Prompt files on disk must therefore be JSON or YAML.","triggerScenarios":"`load_prompt('prompt.toml')`, `load_prompt('prompt.txt')`, `load_prompt('prompt')` (no suffix), or a misnamed file like `prompt.json.txt`.","commonSituations":"Naming mistakes (double extensions from download/save dialogs); attempting to load a raw `.txt` template file directly; config tooling writing `.toml`/`.ini`.","solutions":["Wrap the template in a proper config: `{\"_type\": \"prompt\", \"template\": \"<contents>\", \"input_variables\": [...]}` and save as `.json` or `.yaml`.","Fix the extension (e.g. remove a stray `.txt` so the file ends in `.json`).","For plain template text, load it in code: `PromptTemplate.from_file('prompt.txt')` instead of `load_prompt`."],"exampleFix":"# before\nload_prompt('greeting.txt')  # ValueError: Got unsupported file type .txt\n\n# after\nfrom langchain_core.prompts import PromptTemplate\nprompt = PromptTemplate.from_file('greeting.txt')  # raw template file\n# or write greeting.json: {\"_type\": \"prompt\", \"template\": \"Hi {name}\", \"input_variables\": [\"name\"]}","handlingStrategy":"validation","validationCode":"from pathlib import Path\nsuffix = Path(path).suffix\nif suffix not in {'.json', '.yaml', '.yml'}:\n    raise ValueError(f'prompt file must be .json/.yaml/.yml, got {suffix!r}')\nload_prompt(path)","typeGuard":"def is_supported_prompt_file(path: str | Path) -> bool:\n    return Path(path).suffix in {'.json', '.yaml', '.yml'}","tryCatchPattern":null,"preventionTips":["Use load_prompt only for structured JSON/YAML configs; use PromptTemplate.from_file for raw template text.","Watch for double extensions (prompt.json.txt) produced by editors and downloads."],"tags":["prompts","loading","file-format"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}