{"record":{"id":"e7f5c710733ff277","repo":"langchain-ai/langchain","slug":"one-of-examples-and-example-selector-should-be","errorCode":null,"errorMessage":"One of 'examples' and 'example_selector' should be provided","messagePattern":"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":78,"sourceCode":"            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.\n        \"\"\"\n        if self.examples is not None:\n            return self.examples\n        if self.example_selector is not None:","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/few_shot.py#L60-L96","documentation":"Pydantic model_validator error on the few-shot prompt mixin raised when neither `examples` nor `example_selector` is provided at construction. At least one example source is required; both None is invalid.","triggerScenarios":"`FewShotPromptTemplate(example_prompt=..., suffix=...)` with no examples/example_selector kwarg. Note the validator truthiness check: an empty examples list [] is falsy but not None, so it passes; None for both fails.","commonSituations":"Omitting the kwarg entirely, explicitly passing examples=None while intending to set them later (post-init assignment bypasses the validator but then _get_examples raises later).","solutions":["Provide `examples=[{...}, ...]` as a static list at construction.","Or provide an `example_selector` (e.g. LengthBasedExampleSelector, SemanticSimilarityExampleSelector) built over your example bank.","If you truly want zero examples, pass examples=[] (empty list) rather than omitting it."],"exampleFix":"# before\nFewShotPromptTemplate(example_prompt=ex_prompt, suffix=\"{input}\")\n\n# after\nFewShotPromptTemplate(\n    example_prompt=ex_prompt, suffix=\"{input}\", examples=[{\"input\": \"hi\"}]\n)","handlingStrategy":"validation","validationCode":"def has_example_source(kwargs):\n    return \"examples\" in kwargs or \"example_selector\" in kwargs","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass examples (even []) or an example_selector when constructing few-shot templates.","Write a factory function that requires one of the two parameters explicitly."],"tags":["prompts","few-shot","pydantic-validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}