langchain-ai/langgraph · error · TypeError

Expected a Pydantic model. Got

Error message

Expected a Pydantic model. Got {type(model)}

What it means

get_fields introspects Pydantic models via model_fields (v2) with a __fields__ (v1) fallback; if the object has neither attribute it is not a Pydantic model, so TypeError is raised naming the received type.

Solutions

  1. Pass a Pydantic BaseModel class or instance.
  2. Verify the object is not a dataclass/TypedDict/schema-dict masquerading as a model.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at libs/langgraph/langgraph/_internal/_pydantic.py:51 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of langchain-ai/langgraph@38031739e5 (2026-08-26). Data as JSON: /api/errors/4cce76d2a578e432. Report an issue: GitHub.

Appendix: source

Thrown at libs/langgraph/langgraph/_internal/_pydantic.py:51

@overload
def get_fields(model: type[BaseModel]) -> dict[str, FieldInfo]: ...


@overload
def get_fields(model: BaseModel) -> dict[str, FieldInfo]: ...


def get_fields(
    model: type[BaseModel] | BaseModel,
) -> dict[str, FieldInfo]:
    """Get the field names of a Pydantic model."""
    if hasattr(model, "model_fields"):
        return model.model_fields

    if hasattr(model, "__fields__"):
        return model.__fields__
    msg = f"Expected a Pydantic model. Got {type(model)}"
    raise TypeError(msg)


_SchemaConfig = ConfigDict(
    arbitrary_types_allowed=True, frozen=True, protected_namespaces=()
)

NO_DEFAULT = object()


def _create_root_model(
    name: str,
    type_: Any,
    module_name: str | None = None,
    default_: object = NO_DEFAULT,
) -> type[BaseModel]:
    """Create a base class."""

    def schema(

View on GitHub (pinned to 38031739e5)