langchain-ai/langchain · error · ValueError
Unsupported Pydantic schema: {pydantic_schema}
Error message
Unsupported Pydantic schema: {pydantic_schema} What it means
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.
Source
Thrown at libs/core/langchain_core/output_parsers/openai_functions.py:302
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):
"""Parse an output as an attribute of a Pydantic object."""
attr_name: str
"""The name of the attribute to return."""
@override
def parse_result(self, result: list[Generation], *, partial: bool = False) -> Any:
"""Parse the result of an LLM call to a JSON object.
Args:
result: The result of the LLM call.
partial: Whether to parse partial JSON objects.
Returns:View on GitHub (pinned to e32fa9a52e)
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
Example fix
# before
pydantic_schema = {"create_person": PersonModel, "create_book": BookDataclass}
# after
from pydantic import BaseModel
class Book(BaseModel):
title: str
pydantic_schema = {"create_person": PersonModel, "create_book": Book} Defensive patterns
Strategy: type-guard
Validate before calling
from pydantic import BaseModel, v1
ok = all(
isinstance(v, type) and (issubclass(v, BaseModel) or issubclass(v, v1.BaseModel))
for v in pydantic_schema.values()
) Type guard
from pydantic import BaseModel, v1
def all_valid_schemas(d: dict) -> bool:
return all(isinstance(v, type) and (issubclass(v, BaseModel) or issubclass(v, v1.BaseModel)) for v in d.values()) Prevention
- Validate every dict value at init before binding tools
- Register tools only from a single, typed source of truth
When it happens
Trigger: A dict schema mapping function names to non-BaseModel classes (dataclasses, plain classes), or values replaced at runtime after validator checks.
Common situations: Hand-built schema dicts mixing BaseModel subclasses with helper classes; plugin systems registering arbitrary callables as 'schemas'.
Related errors
- Unsupported Pydantic schema with args_only: {self.pydantic_s
- If multiple pydantic schemas are provided then args_only sho
- Dict Pydantic schema unsupported with args_only: {self.pydan
- Unsupported model version for PydanticOutputParser: {self.py
- Either data or path must be provided
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/bf3457bee1bf1d59.
Report an issue: GitHub.