{"record":{"id":"bf3457bee1bf1d59","repo":"langchain-ai/langchain","slug":"unsupported-pydantic-schema-pydantic-schema","errorCode":null,"errorMessage":"Unsupported Pydantic schema: {pydantic_schema}","messagePattern":"Unsupported Pydantic schema: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/output_parsers/openai_functions.py","lineNumber":302,"sourceCode":"                msg = (  # type: ignore[unreachable]\n                    \"Unsupported Pydantic schema with args_only: \"\n                    f\"{self.pydantic_schema}\"\n                )\n                raise ValueError(msg)\n        else:\n            fn_name = result_[\"name\"]\n            args = result_[\"arguments\"]\n            if isinstance(self.pydantic_schema, dict):\n                pydantic_schema = self.pydantic_schema[fn_name]\n            else:\n                pydantic_schema = self.pydantic_schema\n            if issubclass(pydantic_schema, BaseModel):\n                pydantic_args = pydantic_schema.model_validate_json(args)\n            elif issubclass(pydantic_schema, BaseModelV1):\n                pydantic_args = pydantic_schema.parse_raw(args)\n            else:\n                msg = f\"Unsupported Pydantic schema: {pydantic_schema}\"  # type: ignore[unreachable]\n                raise ValueError(msg)\n        return pydantic_args\n\n\nclass PydanticAttrOutputFunctionsParser(PydanticOutputFunctionsParser):\n    \"\"\"Parse an output as an attribute of a Pydantic object.\"\"\"\n\n    attr_name: str\n    \"\"\"The name of the attribute to return.\"\"\"\n\n    @override\n    def parse_result(self, result: list[Generation], *, partial: bool = False) -> Any:\n        \"\"\"Parse the result of an LLM call to a JSON object.\n\n        Args:\n            result: The result of the LLM call.\n            partial: Whether to parse partial JSON objects.\n\n        Returns:","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/output_parsers/openai_functions.py#L284-L320","documentation":"Defensive branch on the multi-schema path of PydanticOutputFunctionsParser.parse_result: after selecting the schema (from the dict by function name, or the single schema), it is neither a pydantic v2 BaseModel nor a v1 BaseModelV1 subclass, so its arguments cannot be validated. Like error 187, this is marked unreachable for well-typed inputs.","triggerScenarios":"A dict schema mapping function names to non-BaseModel classes (dataclasses, plain classes), or values replaced at runtime after validator checks.","commonSituations":"Hand-built schema dicts mixing BaseModel subclasses with helper classes; plugin systems registering arbitrary callables as 'schemas'.","solutions":["Ensure every value in the pydantic_schema dict is a Pydantic BaseModel subclass (v1 or v2)","Add an init-time check over dict values (all(issubclass(v, BaseModel) for v in schema.values())) to fail fast instead of at parse time"],"exampleFix":"# before\npydantic_schema = {\"create_person\": PersonModel, \"create_book\": BookDataclass}\n\n# after\nfrom pydantic import BaseModel\nclass Book(BaseModel):\n    title: str\npydantic_schema = {\"create_person\": PersonModel, \"create_book\": Book}","handlingStrategy":"type-guard","validationCode":"from pydantic import BaseModel, v1\nok = all(\n    isinstance(v, type) and (issubclass(v, BaseModel) or issubclass(v, v1.BaseModel))\n    for v in pydantic_schema.values()\n)","typeGuard":"from pydantic import BaseModel, v1\n\ndef all_valid_schemas(d: dict) -> bool:\n    return all(isinstance(v, type) and (issubclass(v, BaseModel) or issubclass(v, v1.BaseModel)) for v in d.values())","tryCatchPattern":null,"preventionTips":["Validate every dict value at init before binding tools","Register tools only from a single, typed source of truth"],"tags":["openai-functions","pydantic","type-mismatch"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}