langchain-ai/langchain · error · ValueError
Unsupported Pydantic schema with args_only
Error message
Unsupported Pydantic schema with args_only: {self.pydantic_schema} What it means
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.
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
Example fix
# before
parser = PydanticOutputFunctionsParser(pydantic_schema=MyDataclass, args_only=True)
# after
from pydantic import BaseModel
class MySchema(BaseModel):
name: str
parser = PydanticOutputFunctionsParser(pydantic_schema=MySchema, args_only=True) Defensive patterns
Strategy: type-guard
Validate before calling
from pydantic import BaseModel from langchain_core.utils.pydantic import is_basemodel_subclass assert is_basemodel_subclass(schema), "schema must be a BaseModel subclass"
Type guard
from pydantic import BaseModel, v1
def is_pydantic_model(cls: object) -> bool:
return isinstance(cls, type) and (issubclass(cls, BaseModel) or issubclass(cls, v1.BaseModel)) Prevention
- Type-check schemas at wiring time, not at parse time
- Keep schemas as real BaseModel subclasses; convert dataclasses with pydantic.TypeAdapter-inspired tooling
When it happens
Trigger: 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).
Common situations: Refactoring from Pydantic to dataclasses/TypedDict but leaving the parser wired in; dynamically constructed schemas from plugins that are not real BaseModel subclasses.
Related errors
- Unsupported Pydantic schema
- Dict Pydantic schema unsupported with args_only
- If multiple pydantic schemas are provided then args_only…
- Unsupported model version for PydanticOutputParser
- args_schema must be a subclass of pydantic BaseModel or a…
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/6a6b69a3d7e36c7f.
Report an issue: GitHub.
Appendix: source
Thrown at libs/core/langchain_core/output_parsers/openai_functions.py:288
result_ = super().parse_result(result)
pydantic_args: PydanticBaseModel
if self.args_only:
if isinstance(self.pydantic_schema, dict):
msg = (
"Dict Pydantic schema unsupported with args_only: "
f"{self.pydantic_schema}"
)
raise ValueError(msg)
if issubclass(self.pydantic_schema, BaseModel):
pydantic_args = self.pydantic_schema.model_validate_json(result_)
elif issubclass(self.pydantic_schema, BaseModelV1):
pydantic_args = self.pydantic_schema.parse_raw(result_)
else:
msg = ( # type: ignore[unreachable]
"Unsupported Pydantic schema with args_only: "
f"{self.pydantic_schema}"
)
raise ValueError(msg)
else:
fn_name = result_["name"]
args = result_["arguments"]
if isinstance(self.pydantic_schema, dict):
pydantic_schema = self.pydantic_schema[fn_name]
else:
pydantic_schema = self.pydantic_schema
if issubclass(pydantic_schema, BaseModel):
pydantic_args = pydantic_schema.model_validate_json(args)
elif issubclass(pydantic_schema, BaseModelV1):
pydantic_args = pydantic_schema.parse_raw(args)
else:
msg = f"Unsupported Pydantic schema: {pydantic_schema}" # type: ignore[unreachable]
raise ValueError(msg)
return pydantic_args
class PydanticAttrOutputFunctionsParser(PydanticOutputFunctionsParser):View on GitHub (pinned to e32fa9a52e)