{"record":{"id":"6a6b69a3d7e36c7f","repo":"langchain-ai/langchain","slug":"unsupported-pydantic-schema-with-args-only-self","errorCode":null,"errorMessage":"Unsupported Pydantic schema with args_only: {self.pydantic_schema}","messagePattern":"Unsupported Pydantic schema with args_only: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/output_parsers/openai_functions.py","lineNumber":288,"sourceCode":"        result_ = super().parse_result(result)\n        pydantic_args: PydanticBaseModel\n        if self.args_only:\n            if isinstance(self.pydantic_schema, dict):\n                msg = (\n                    \"Dict Pydantic schema unsupported with args_only: \"\n                    f\"{self.pydantic_schema}\"\n                )\n                raise ValueError(msg)\n            if issubclass(self.pydantic_schema, BaseModel):\n                pydantic_args = self.pydantic_schema.model_validate_json(result_)\n            elif issubclass(self.pydantic_schema, BaseModelV1):\n                pydantic_args = self.pydantic_schema.parse_raw(result_)\n            else:\n                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):","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/output_parsers/openai_functions.py#L270-L306","documentation":"Defensive unreachable branch in PydanticOutputFunctionsParser.parse_result: with args_only=True, the schema passed the issubclass checks for neither pydantic v2 BaseModel nor pydantic.v1 BaseModelV1, so validation of the raw JSON cannot proceed. The type system marks it unreachable because schema type is constrained, but a non-BaseModel object (or something spoofing issubclass) reaches it at runtime.","triggerScenarios":"Passing an object that is not a Pydantic BaseModel subclass as pydantic_schema while bypassing type checking (e.g. dataclasses, TypedDict, arbitrary classes combined with model_construct or forged state).","commonSituations":"Refactoring from Pydantic to dataclasses/TypedDict but leaving the parser wired in; dynamically constructed schemas from plugins that are not real BaseModel subclasses.","solutions":["Pass a real Pydantic BaseModel subclass (v1 or v2) as pydantic_schema","If using dataclasses or TypedDict, switch to PydanticOutputParser/JsonOutputParser appropriate for that type or convert the schema to a BaseModel"],"exampleFix":"# before\nparser = PydanticOutputFunctionsParser(pydantic_schema=MyDataclass, args_only=True)\n\n# after\nfrom pydantic import BaseModel\nclass MySchema(BaseModel):\n    name: str\nparser = PydanticOutputFunctionsParser(pydantic_schema=MySchema, args_only=True)","handlingStrategy":"type-guard","validationCode":"from pydantic import BaseModel\nfrom langchain_core.utils.pydantic import is_basemodel_subclass\nassert is_basemodel_subclass(schema), \"schema must be a BaseModel subclass\"","typeGuard":"from pydantic import BaseModel, v1\n\ndef is_pydantic_model(cls: object) -> bool:\n    return isinstance(cls, type) and (issubclass(cls, BaseModel) or issubclass(cls, v1.BaseModel))","tryCatchPattern":null,"preventionTips":["Type-check schemas at wiring time, not at parse time","Keep schemas as real BaseModel subclasses; convert dataclasses with pydantic.TypeAdapter-inspired tooling"],"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"}