LangGraphAstreamDeltaParseError
langgraph.exceptions.LangGraphAstreamDeltaParseError
Stack trace
langgraph.exceptions.LangGraphAstreamDeltaParseError: Failed to parse astream delta update: unexpected token at position 45
File "/usr/local/lib/python3.10/site-packages/langgraph/astream/parser.py", line 112, in parse_delta_update
raise LangGraphAstreamDeltaParseError(f"Failed to parse astream delta update: {err}")
File "/usr/local/lib/python3.10/site-packages/langgraph/astream/parser.py", line 98, in parse_delta_update
delta = json.loads(delta_str) # <-- error triggered here
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 46 (char 45) Why it happens
LangGraph expects streaming delta updates in a strict JSON format for incremental graph updates. If the stream contains malformed JSON, partial fragments, or unexpected tokens, the parser raises this error. This often happens when network interruptions corrupt the stream or the upstream source sends invalid data.
Detection
Monitor logs for LangGraphAstreamDeltaParseError exceptions and capture the raw delta update strings to identify malformed or incomplete JSON fragments before they cause downstream failures.
Causes & fixes
The streaming delta update contains malformed JSON due to truncated or corrupted data.
Implement retry logic on the stream source to ensure complete JSON fragments are received before parsing.
Upstream source sends delta updates with unexpected fields or format changes not compatible with the parser.
Update the LangGraph parser schema to match the new delta update format or coordinate with the upstream source to maintain format consistency.
Network interruptions cause partial delta update messages to be delivered to the parser.
Buffer incoming stream data and only parse complete JSON objects, using delimiters or length prefixes to detect message boundaries.
Code: broken vs fixed
from langgraph.astream import AstreamParser
parser = AstreamParser()
delta_str = '{"node": 1, "edges": [2, 3' # incomplete JSON
parsed = parser.parse_delta_update(delta_str) # triggers LangGraphAstreamDeltaParseError here import os
from langgraph.astream import AstreamParser
parser = AstreamParser()
# Buffering example: accumulate until full JSON received
buffer = ''
raw_stream_data = '{"node": 1, "edges": [2, 3]}' # complete JSON
buffer += raw_stream_data
parsed = parser.parse_delta_update(buffer) # fixed: full JSON parsed successfully
print(parsed)
# Changed to ensure full JSON string before parsing Workaround
Wrap the parse_delta_update call in try/except LangGraphAstreamDeltaParseError, then attempt to extract valid JSON fragments using regex or manual string fixes before retrying parse.
Prevention
Design the streaming protocol to send complete, self-delimited JSON messages or use length-prefixed framing to guarantee parsable delta updates, avoiding partial or corrupted data.