{"record":{"id":"b23d1b31873ee714","repo":"langchain-ai/langchain","slug":"invalid-examples-format-only-list-or-string-are-s","errorCode":null,"errorMessage":"Invalid examples format. Only list or string are supported.","messagePattern":"Invalid examples format\\. Only list or string are supported\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/loading.py","lineNumber":138,"sourceCode":"    \"\"\"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(\n    config: dict[str, Any], *, allow_dangerous_paths: bool = False\n) -> FewShotPromptTemplate:\n    \"\"\"Load the \"few shot\" prompt from the config.\"\"\"\n    # Load the suffix and prefix templates.","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/loading.py#L120-L156","documentation":"`_load_examples` accepts `examples` in exactly two shapes: a list (inline examples) or a string (path to a `.json`/`.yaml` file). Anything else — a dict, number, None, nested object — raises this `ValueError`, since the loader has no way to interpret it as examples.","triggerScenarios":"A few-shot config with `\"examples\": {\"0\": {...}}` (dict), `\"examples\": null`, or `\"examples\": 5`. Note a missing `examples` key raises `KeyError` earlier at `config[\"examples\"]`; this error is for a present-but-wrong-typed value.","commonSituations":"YAML configs where a single example collapses into a dict instead of a one-element list; JSON `null` for optional examples; feeding an `example_selector` config dict where examples were expected.","solutions":["Wrap the value in a list: `\"examples\": [{ ... }]`.","Remove the `examples` key entirely if you mean to have zero examples (and expect a `KeyError` — prefer an empty list `[]` which passes).","If examples live in a file, use the string path form with a `.json`/`.yaml` suffix."],"exampleFix":"# before\n# examples.yaml content loaded into config as:\n# {\"examples\": {\"q\": \"hi\", \"a\": \"hello\"}}\n\n# after\n# {\"examples\": [{\"q\": \"hi\", \"a\": \"hello\"}]}","handlingStrategy":"type-guard","validationCode":"ex = config.get('examples')\nif not isinstance(ex, (list, str)):\n    raise ValueError('examples must be a list or a file-path string')\nload_prompt_from_config(config)","typeGuard":"def is_valid_examples(examples: object) -> bool:\n    return isinstance(examples, (list, str))","tryCatchPattern":null,"preventionTips":["Write YAML examples as a list of mappings; a single mapping collapses to a dict and fails.","Use [] rather than null for zero examples."],"tags":["prompts","loading","config","few-shot","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}