[PR #1168] [CLOSED] Support serialization/deserialization of bytes when using a checkpointer #1924

Closed
opened 2026-02-20 17:45:52 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/langgraph/pull/1168
Author: @balvisio
Created: 7/30/2024
Status: Closed

Base: mainHead: dev/ba/support-ser-de-serialize-bytes


📝 Commits (1)

  • 260d6e7 Support serialization/deserialization of bytes

📊 Changes

1 file changed (+4 additions, -0 deletions)

View changed files

📝 libs/langgraph/langgraph/serde/jsonplus.py (+4 -0)

📄 Description

If the graph State contains bytes and a checkpointer is being used, the serialization fails with a TypeError:

from typing_extensions import TypedDict

from typing import Optional

from langgraph.checkpoint.sqlite import SqliteSaver
from langgraph.graph import StateGraph, START, END


class State(TypedDict):
    my_bytes: Optional[bytes]


def my_func(state: State):
    return {"my_bytes": bytes([0, 1])}


graph_builder = StateGraph(State)
graph_builder.add_node("my_func", my_func)
graph_builder.add_edge(START, "my_func")
graph_builder.add_edge("my_func", END)

memory = SqliteSaver.from_conn_string(":memory:")
config = {
    "configurable": {
        "thread_id": "1",
    },
}

graph = graph_builder.compile(checkpointer=memory)

graph.invoke({"my_bytes": None}, config=config)

graph.get_state(config)

Fails with:

    raise TypeError(
TypeError: Object of type bytes is not JSON serializable

This PR fixes the issue by adding a new branch to encode/decode the bytes into a "utf-8" strings for serialization/deserialization.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/langgraph/pull/1168 **Author:** [@balvisio](https://github.com/balvisio) **Created:** 7/30/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `dev/ba/support-ser-de-serialize-bytes` --- ### 📝 Commits (1) - [`260d6e7`](https://github.com/langchain-ai/langgraph/commit/260d6e74974f4cfb28cd00d85cb3c8b61706aac8) Support serialization/deserialization of bytes ### 📊 Changes **1 file changed** (+4 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `libs/langgraph/langgraph/serde/jsonplus.py` (+4 -0) </details> ### 📄 Description If the graph State contains bytes and a checkpointer is being used, the serialization fails with a `TypeError`: ``` from typing_extensions import TypedDict from typing import Optional from langgraph.checkpoint.sqlite import SqliteSaver from langgraph.graph import StateGraph, START, END class State(TypedDict): my_bytes: Optional[bytes] def my_func(state: State): return {"my_bytes": bytes([0, 1])} graph_builder = StateGraph(State) graph_builder.add_node("my_func", my_func) graph_builder.add_edge(START, "my_func") graph_builder.add_edge("my_func", END) memory = SqliteSaver.from_conn_string(":memory:") config = { "configurable": { "thread_id": "1", }, } graph = graph_builder.compile(checkpointer=memory) graph.invoke({"my_bytes": None}, config=config) graph.get_state(config) ``` Fails with: ``` raise TypeError( TypeError: Object of type bytes is not JSON serializable ``` This PR fixes the issue by adding a new branch to encode/decode the bytes into a "utf-8" strings for serialization/deserialization. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-20 17:45:52 -05:00
yindo closed this issue 2026-02-20 17:45:52 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#1924