langchain-ai/langchain · error · ValueError
Only one of example_prompt and example_prompt_path should be
Error message
Only one of example_prompt and example_prompt_path should be specified.
What it means
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.
Source
Thrown at libs/core/langchain_core/prompts/loading.py:170
def _load_few_shot_prompt(
config: dict[str, Any], *, allow_dangerous_paths: bool = False
) -> FewShotPromptTemplate:
"""Load the "few shot" prompt from the config."""
# Load the suffix and prefix templates.
config = _load_template(
"suffix", config, allow_dangerous_paths=allow_dangerous_paths
)
config = _load_template(
"prefix", config, allow_dangerous_paths=allow_dangerous_paths
)
# Load the example prompt.
if "example_prompt_path" in config:
if "example_prompt" in config:
msg = (
"Only one of example_prompt and example_prompt_path should "
"be specified."
)
raise ValueError(msg)
example_prompt_path = Path(config.pop("example_prompt_path"))
if not allow_dangerous_paths:
_validate_path(example_prompt_path)
config["example_prompt"] = load_prompt(
example_prompt_path, allow_dangerous_paths=allow_dangerous_paths
)
else:
config["example_prompt"] = load_prompt_from_config(
config["example_prompt"], allow_dangerous_paths=allow_dangerous_paths
)
# Load the examples.
config = _load_examples(config, allow_dangerous_paths=allow_dangerous_paths)
config = _load_output_parser(config)
return FewShotPromptTemplate(**config)
def _load_prompt(
config: dict[str, Any], *, allow_dangerous_paths: bool = FalseView on GitHub (pinned to e32fa9a52e)
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.
Example fix
# before
# {"_type": "few_shot", "example_prompt": {...},
# "example_prompt_path": "ep.json", ...}
load_prompt('prompt.json') # ValueError
# after
# {"_type": "few_shot", "example_prompt": {"_type": "prompt",
# "template": "Q: {q}\nA: {a}", "input_variables": ["q", "a"]}, ...}
load_prompt('prompt.json') Defensive patterns
Strategy: validation
Validate before calling
if 'example_prompt' in config and 'example_prompt_path' in config:
del config['example_prompt_path'] # inline wins; or raise
load_prompt_from_config(config) Type guard
def has_no_example_prompt_conflict(config: dict) -> bool:
return not ('example_prompt' in config and 'example_prompt_path' in config) Prevention
- Pick one representation (inline config or path) per few-shot config and lint for the pair.
- Review merged config diffs for duplicated source keys.
When it happens
Trigger: A few-shot config JSON containing both `"example_prompt"` and `"example_prompt_path"` keys, loaded via `load_prompt`.
Common situations: Editing a working config and pasting in an example-prompt config without deleting the old path key; merging prompt configs from two sources.
Related errors
- Invalid examples format. Only list or string are supported.
- Both `{var_name}_path` and `{var_name}` cannot be provided.
- Loading {config_type} prompt not supported
- Unsupported template file format: '{resolved_path.suffix}'.
- Invalid file format. Only json or yaml formats are supported
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/c8c1c6861060ef90.
Report an issue: GitHub.