Skip to content

fix(streaming): return None from parsed_snapshot() for non-JSON text - #1973

Open
intertermux-code wants to merge 1 commit into
anthropics:mainfrom
intertermux-code:fix/1961-parsed-snapshot-valueerror
Open

intertermux-code wants to merge 1 commit into
anthropics:mainfrom
intertermux-code:fix/1961-parsed-snapshot-valueerror

Conversation

@intertermux-code

Copy link
Copy Markdown

Fixes #1961.

parsed_snapshot() ran the accumulated snapshot through jiter.from_json unguarded, so ordinary prose — and the empty first delta of every text block — raised ValueError, and non-object JSON came back mistyped as Dict[str, Any].

It now returns None unless the snapshot parses as a JSON object. The annotation is widened to Optional[Dict[str, Any]] and the method gets the docstring it was missing. The JSON-object path is unchanged, including mid-stream partials, so examples/structured_outputs_streaming.py keeps working.

Added regression tests for both TextEvent and ParsedBetaTextEvent.

TextEvent.parsed_snapshot() (and ParsedBetaTextEvent.parsed_snapshot())
ran the accumulated snapshot through jiter.from_json with no guard, so
ordinary prose - and the empty first delta - raised ValueError, and
non-object JSON came back mistyped as Dict[str, Any]. Return None
unless the snapshot parses as a JSON object; the JSON-object path,
including mid-stream partials, is unchanged.

Fixes anthropics#1961.
@intertermux-code
intertermux-code requested a review from a team as a code owner October 5, 2026 05:50

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextEvent.parsed_snapshot() raises ValueError on ordinary text (and on the empty first delta), and its return annotation is wrong for non-object JSON

1 participant