Skip to content

Checkpoint serialization rejects fractions.Fraction and complex (TypeError) though Decimal is supported #8185

Description

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I am sure that this is a bug in LangGraph rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangGraph.
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Related Issues / PRs

JsonPlusSerializer already supports Decimal, UUID, datetime, Path, IP addresses, etc.; Fraction and complex are the gap.

Reproduction Steps / Example Code (Python)

from decimal import Decimal
from fractions import Fraction
from langgraph.checkpoint.serde.jsonplus import JsonPlusSerializer

s = JsonPlusSerializer()

s.loads_typed(s.dumps_typed(Decimal("1.5")))   # OK -> Decimal('1.5')
s.loads_typed(s.dumps_typed(Fraction(1, 3)))    # TypeError: Type is not msgpack serializable: Fraction
s.loads_typed(s.dumps_typed(complex(1, 2)))     # TypeError: Type is not msgpack serializable: complex

Error Message and Stack Trace (if applicable)

TypeError: Type is not msgpack serializable: Fraction
TypeError: Type is not msgpack serializable: complex

Description

JsonPlusSerializer special-cases many stdlib types in _msgpack_default (libs/checkpoint/langgraph/checkpoint/serde/jsonplus.py) — including Decimal — but not fractions.Fraction or the builtin complex. Since neither is natively serializable by ormsgpack, both fall through to default and raise TypeError.

The effect: a graph whose checkpointed state contains a Fraction (exact rational arithmetic) or a complex number (scientific / signal-processing agents) cannot be checkpointed at all — put/aput raises. This is an inconsistency with the already-supported Decimal, and both have an obvious lossless representation.

I'm happy to fix this by adding Fraction and complex handlers to _msgpack_default that mirror the existing Decimal handler (encode via constructor args, reconstruct with the standard constructor), with round-trip tests. Glad to align on the approach first.

System Info

langgraph-checkpoint on main; default JsonPlusSerializer (msgpack path). Python 3.12.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions