langchain-ai/langgraph · error · TypeError
Cannot JSON-serialize type object: {obj!r}. Did you mean to
Error message
Cannot JSON-serialize type object: {obj!r}. Did you mean to pass an instance of the object instead?
Received type: {obj!r} What it means
Error "Cannot JSON-serialize type object: {obj!r}. Did you mean to pass an instance of the object instead? Received type: {obj!r}" thrown in langchain-ai/langgraph.
Source
Thrown at libs/sdk-py/langgraph_sdk/_shared/utilities.py:76
if header in custom_headers:
raise ValueError(f"Cannot set reserved header '{header}'")
headers = {
"User-Agent": f"langgraph-sdk-py/{langgraph_sdk.__version__}",
**custom_headers,
}
resolved_api_key = _get_api_key(api_key)
if resolved_api_key:
headers["x-api-key"] = resolved_api_key
return headers
def _orjson_default(obj: Any) -> Any:
is_class = isinstance(obj, type)
if hasattr(obj, "model_dump") and callable(obj.model_dump):
if is_class:
raise TypeError(
f"Cannot JSON-serialize type object: {obj!r}. Did you mean to pass an instance of the object instead?"
f"\nReceived type: {obj!r}"
)
return obj.model_dump()
elif hasattr(obj, "dict") and callable(obj.dict):
if is_class:
raise TypeError(
f"Cannot JSON-serialize type object: {obj!r}. Did you mean to pass an instance of the object instead?"
f"\nReceived type: {obj!r}"
)
return obj.dict()
elif isinstance(obj, (set, frozenset)):
return list(obj)
else:
raise TypeError(f"Object of type {type(obj)} is not JSON serializable")
# Compiled regex pattern for extracting run metadata from Content-Location headerView on GitHub (pinned to 38031739e5)
When it happens
Trigger: Thrown at libs/sdk-py/langgraph_sdk/_shared/utilities.py:76 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/ec890414f79dbed7.
Report an issue: GitHub.