langchain-ai/langgraph · error · TypeError
Object of type is not JSON serializable
Error message
Object of type {type(obj)} is not JSON serializable What it means
Final fallback in _orjson_default: the object passed to JSON serialization is of a type orjson cannot handle natively and the default hook has no conversion rule for it (not a pydantic model, no dict()/model_dump method). The payload contains an unserializable value.
Solutions
- Convert the object to a plain JSON-compatible type (dict/list/str/number) before sending
- Use a custom encoder by dumping with `obj.model_dump()`/`dataclasses.asdict(obj)`
- Replace non-serializable values (datetime, UUID, sets) with str() or native equivalents
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at libs/sdk-py/langgraph_sdk/_shared/utilities.py:91 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/eaa1754882be755c.
Report an issue: GitHub.
Appendix: source
Thrown at libs/sdk-py/langgraph_sdk/_shared/utilities.py:91
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 header
_RUN_METADATA_PATTERN = re.compile(
r"(\/threads\/(?P<thread_id>.+))?\/runs\/(?P<run_id>.+)"
)
def _get_run_metadata_from_response(
response: httpx.Response,
) -> RunCreateMetadata | None:
"""Extract run metadata from the response headers."""
if (content_location := response.headers.get("Content-Location")) and (
match := _RUN_METADATA_PATTERN.search(content_location)
):
return RunCreateMetadata(
run_id=match.group("run_id"),
thread_id=match.group("thread_id") or None,View on GitHub (pinned to 38031739e5)