{"record":{"id":"c8c1c6861060ef90","repo":"langchain-ai/langchain","slug":"only-one-of-example-prompt-and-example-prompt-path","errorCode":null,"errorMessage":"Only one of example_prompt and example_prompt_path should be specified.","messagePattern":"Only one of example_prompt and example_prompt_path should be specified\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/loading.py","lineNumber":170,"sourceCode":"def _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.\n    config = _load_template(\n        \"suffix\", config, allow_dangerous_paths=allow_dangerous_paths\n    )\n    config = _load_template(\n        \"prefix\", config, allow_dangerous_paths=allow_dangerous_paths\n    )\n    # Load the example prompt.\n    if \"example_prompt_path\" in config:\n        if \"example_prompt\" in config:\n            msg = (\n                \"Only one of example_prompt and example_prompt_path should \"\n                \"be specified.\"\n            )\n            raise ValueError(msg)\n        example_prompt_path = Path(config.pop(\"example_prompt_path\"))\n        if not allow_dangerous_paths:\n            _validate_path(example_prompt_path)\n        config[\"example_prompt\"] = load_prompt(\n            example_prompt_path, allow_dangerous_paths=allow_dangerous_paths\n        )\n    else:\n        config[\"example_prompt\"] = load_prompt_from_config(\n            config[\"example_prompt\"], allow_dangerous_paths=allow_dangerous_paths\n        )\n    # Load the examples.\n    config = _load_examples(config, allow_dangerous_paths=allow_dangerous_paths)\n    config = _load_output_parser(config)\n    return FewShotPromptTemplate(**config)\n\n\ndef _load_prompt(\n    config: dict[str, Any], *, allow_dangerous_paths: bool = False","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/loading.py#L152-L188","documentation":"In `_load_few_shot_prompt`, the example prompt may be given inline (`example_prompt: {...config...}`) or by file (`example_prompt_path: ...`), but not both — supplying both keys raises this `ValueError`, mirroring the template/template_path exclusivity rule.","triggerScenarios":"A few-shot config JSON containing both `\"example_prompt\"` and `\"example_prompt_path\"` keys, loaded via `load_prompt`.","commonSituations":"Editing a working config and pasting in an example-prompt config without deleting the old path key; merging prompt configs from two sources.","solutions":["Delete one key: keep the inline `example_prompt` config dict, or keep `example_prompt_path` pointing at another prompt JSON/YAML file.","Add a config lint step that rejects files containing both keys before loading."],"exampleFix":"# before\n# {\"_type\": \"few_shot\", \"example_prompt\": {...},\n#  \"example_prompt_path\": \"ep.json\", ...}\nload_prompt('prompt.json')  # ValueError\n\n# after\n# {\"_type\": \"few_shot\", \"example_prompt\": {\"_type\": \"prompt\",\n#   \"template\": \"Q: {q}\\nA: {a}\", \"input_variables\": [\"q\", \"a\"]}, ...}\nload_prompt('prompt.json')","handlingStrategy":"validation","validationCode":"if 'example_prompt' in config and 'example_prompt_path' in config:\n    del config['example_prompt_path']  # inline wins; or raise\nload_prompt_from_config(config)","typeGuard":"def has_no_example_prompt_conflict(config: dict) -> bool:\n    return not ('example_prompt' in config and 'example_prompt_path' in config)","tryCatchPattern":null,"preventionTips":["Pick one representation (inline config or path) per few-shot config and lint for the pair.","Review merged config diffs for duplicated source keys."],"tags":["prompts","loading","few-shot","config","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}