{"record":{"id":"30b9058f96e1c33d","repo":"langchain-ai/langchain","slug":"only-one-of-examples-and-example-selector-shou","errorCode":null,"errorMessage":"Only one of 'examples' and 'example_selector' should be provided","messagePattern":"Only one of 'examples' and 'example_selector' should be provided","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/few_shot.py","lineNumber":74,"sourceCode":"    def check_examples_and_selector(cls, values: dict[str, Any]) -> Any:\n        \"\"\"Check that one and only one of `examples`/`example_selector` are provided.\n\n        Args:\n            values: The values to check.\n\n        Returns:\n            The values if they are valid.\n\n        Raises:\n            ValueError: If neither or both `examples` and `example_selector` are\n                provided.\n            ValueError: If both `examples` and `example_selector` are provided.\n        \"\"\"\n        examples = values.get(\"examples\")\n        example_selector = values.get(\"example_selector\")\n        if examples and example_selector:\n            msg = \"Only one of 'examples' and 'example_selector' should be provided\"\n            raise ValueError(msg)\n\n        if examples is None and example_selector is None:\n            msg = \"One of 'examples' and 'example_selector' should be provided\"\n            raise ValueError(msg)\n\n        return values\n\n    def _get_examples(self, **kwargs: Any) -> list[dict[str, Any]]:\n        \"\"\"Get the examples to use for formatting the prompt.\n\n        Args:\n            **kwargs: Keyword arguments to be passed to the example selector.\n\n        Returns:\n            List of examples.\n\n        Raises:\n            ValueError: If neither `examples` nor `example_selector` are provided.","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/few_shot.py#L56-L92","documentation":"Pydantic model_validator error on FewShotPromptTemplate / FewShotChatMessagePromptTemplate (the _FewShotPromptTemplateMixin validator) raised when both `examples` and `example_selector` are set. The class needs exactly one source of examples because formatting would be ambiguous otherwise.","triggerScenarios":"`FewShotPromptTemplate(..., examples=[...], example_selector=LengthBasedExampleSelector(...))` at construction time (sync or async usage; validation runs on init).","commonSituations":"Starting with a static examples list, later adding a SemanticSimilarityExampleSelector for dynamic selection and forgetting to remove the list; copying config objects and merging fields.","solutions":["Delete one of the two: keep `examples` for static lists, or `example_selector` for dynamic selection.","If you need a fallback, implement the fallback inside a custom BaseExampleSelector instead of setting both fields."],"exampleFix":"# before\nFewShotPromptTemplate(\n    ..., examples=[...],\n    example_selector=LengthBasedExampleSelector(...),\n)\n\n# after\nFewShotPromptTemplate(\n    ..., example_selector=LengthBasedExampleSelector(...),\n)","handlingStrategy":"validation","validationCode":"def exactly_one_example_source(examples, example_selector):\n    return (examples is not None) ^ (example_selector is not None)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat examples and example_selector as mutually exclusive in constructors and config schemas.","When migrating to a selector, delete the static list in the same commit."],"tags":["prompts","few-shot","pydantic-validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}