{"record":{"id":"dc3704d299c7b54e","repo":"langchain-ai/langchain","slug":"one-of-examples-and-example-selector-should-be-dc3704","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_with_templates.py","lineNumber":76,"sourceCode":"\n        Returns:\n            `[\"langchain\", \"prompts\", \"few_shot_with_templates\"]`\n        \"\"\"\n        return [\"langchain\", \"prompts\", \"few_shot_with_templates\"]\n\n    @model_validator(mode=\"before\")\n    @classmethod\n    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        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    @model_validator(mode=\"after\")\n    def template_is_valid(self) -> Self:\n        \"\"\"Check that prefix, suffix, and input variables are consistent.\"\"\"\n        if self.validate_template:\n            input_variables = self.input_variables\n            expected_input_variables = set(self.suffix.input_variables)\n            expected_input_variables |= set(self.partial_variables)\n            if self.prefix is not None:\n                expected_input_variables |= set(self.prefix.input_variables)\n            missing_vars = expected_input_variables.difference(input_variables)\n            if missing_vars:\n                msg = (\n                    f\"Got input_variables={input_variables}, but based on \"\n                    f\"prefix/suffix expected {expected_input_variables}\"\n                )","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/few_shot_with_templates.py#L58-L94","documentation":"Pydantic before-validator on FewShotPromptWithTemplates raised when neither `examples` nor `example_selector` is given. This legacy template class (extra='forbid') requires exactly one example source up front.","triggerScenarios":"`FewShotPromptWithTemplates(example_prompt=..., suffix=...)` with the examples kwarg omitted, or both explicitly None.","commonSituations":"Porting old langchain prompt YAML to core; minimal-construction attempts that plan to assign examples later.","solutions":["Pass examples=[...] (even [] if you want none) at construction.","Or pass an example_selector instance.","Note extra='forbid': any additional unknown kwarg will also fail, so check config keys too."],"exampleFix":"# before\nFewShotPromptWithTemplates(\n    example_prompt=PromptTemplate(...), suffix=\"{input}\"\n)\n\n# after\nFewShotPromptWithTemplates(\n    example_prompt=PromptTemplate(...), suffix=\"{input}\", examples=[]\n)","handlingStrategy":"validation","validationCode":"def has_example_source(kwargs):\n    return \"examples\" in kwargs or \"example_selector\" in kwargs","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass examples=[] explicitly when no examples are needed.","Remember FewShotPromptWithTemplates is extra='forbid': unknown kwargs also fail validation."],"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"}