{"record":{"id":"8401f9d8deb29c4d","repo":"langchain-ai/langchain","slug":"invalid-file-format-only-json-or-yaml-formats-are","errorCode":null,"errorMessage":"Invalid file format. Only json or yaml formats are supported.","messagePattern":"Invalid file format\\. Only json or yaml formats are supported\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/loading.py","lineNumber":134,"sourceCode":"\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)\n            elif path.suffix in {\".yaml\", \".yml\"}:\n                examples = yaml.safe_load(f)\n            else:\n                msg = \"Invalid file format. Only json or yaml formats are supported.\"\n                raise ValueError(msg)\n        config[\"examples\"] = examples\n    else:\n        msg = \"Invalid examples format. Only list or string are supported.\"\n        raise ValueError(msg)  # noqa:TRY004\n    return config\n\n\ndef _load_output_parser(config: dict[str, Any]) -> dict[str, Any]:\n    \"\"\"Load output parser.\"\"\"\n    if config_ := config.get(\"output_parser\"):\n        if output_parser_type := config_.get(\"_type\") != \"default\":\n            msg = f\"Unsupported output parser {output_parser_type}\"\n            raise ValueError(msg)\n        config[\"output_parser\"] = StrOutputParser(**config_)\n    return config\n\n\ndef _load_few_shot_prompt(","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/loading.py#L116-L152","documentation":"In `_load_examples`, when a few-shot config gives `examples` as a string path, the loader opens the file and parses it by suffix: `.json` via `json.load`, `.yaml`/`.yml` via `yaml.safe_load`. Any other suffix raises `ValueError: Invalid file file format...` because there is no parser for it.","triggerScenarios":"A few-shot prompt config with `\"examples\": \"data/examples.csv\"` (or `.txt`, `.jsonl`, no suffix, etc.) loaded via `load_prompt`.","commonSituations":"Examples maintained in CSV/JSONL by a data team and referenced directly; renaming example files during a refactor; miscounting `.jsonl` as JSON.","solutions":["Convert the examples file to `.json` (a JSON array of objects) or `.yaml`/`.yml`.","Inline the examples list directly in the config under `\"examples\": [ ... ]`.","For JSONL, merge records into one JSON array: `json.dumps([json.loads(l) for l in open(f)])`."],"exampleFix":"# before\n# {\"_type\": \"few_shot\", \"examples\": \"examples.csv\", ...}\nload_prompt('prompt.json')  # ValueError\n\n# after\n# convert to examples.json: [{\"q\": \"...\", \"a\": \"...\"}, ...]\n# {\"_type\": \"few_shot\", \"examples\": \"examples.json\", ...}\nload_prompt('prompt.json')","handlingStrategy":"validation","validationCode":"from pathlib import Path\nif isinstance(config.get('examples'), str):\n    suffix = Path(config['examples']).suffix\n    if suffix not in {'.json', '.yaml', '.yml'}:\n        raise ValueError(f'examples file must be .json/.yaml/.yml, got {suffix}')\nload_prompt_from_config(config)","typeGuard":"def is_supported_examples_file(path: str | Path) -> bool:\n    return Path(path).suffix in {'.json', '.yaml', '.yml'}","tryCatchPattern":null,"preventionTips":["Keep few-shot example datasets as a single JSON array or YAML list.","Convert CSV/JSONL example exports before wiring them into prompt configs."],"tags":["prompts","loading","file-format","few-shot"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}