langchain-ai/langgraph · error · TypeError
Expected a type, got
Error message
Expected a type, got {type(obj)}. What it means
get_cached_annotated_keys asserts its argument is a class (it inspects __mro__ and __annotations__); a non-type instance was passed, so a TypeError naming the offending type is raised before annotation caching proceeds.
Solutions
- Pass the class itself (e.g. MyState), not an instance, to the annotated-keys helper.
- Check the calling code for accidental instance-vs-class confusion.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at libs/langgraph/langgraph/_internal/_fields.py:213 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/125e0a6bad8249f8.
Report an issue: GitHub.
Appendix: source
Thrown at libs/langgraph/langgraph/_internal/_fields.py:213
def get_cached_annotated_keys(obj: type[Any]) -> tuple[str, ...]:
"""Return cached annotated keys for a Python class."""
if obj in ANNOTATED_KEYS_CACHE:
return ANNOTATED_KEYS_CACHE[obj]
if isinstance(obj, type):
keys: list[str] = []
for base in reversed(obj.__mro__):
ann = base.__dict__.get("__annotations__")
# In Python 3.14+, Pydantic models use descriptors for __annotations__
# so we need to fall back to getattr if __dict__.get returns None
if ann is None:
ann = getattr(base, "__annotations__", None)
if ann is None or isinstance(ann, types.GetSetDescriptorType):
continue
keys.extend(ann.keys())
return ANNOTATED_KEYS_CACHE.setdefault(obj, tuple(keys))
else:
raise TypeError(f"Expected a type, got {type(obj)}. ")
View on GitHub (pinned to 38031739e5)