Skip to content

fix: correct content_block_delta deserialization in streaming#1653

Open
Oxygen56 wants to merge 1 commit into
anthropics:mainfrom
Oxygen56:fix/content-block-delta-streaming-941
Open

fix: correct content_block_delta deserialization in streaming#1653
Oxygen56 wants to merge 1 commit into
anthropics:mainfrom
Oxygen56:fix/content-block-delta-streaming-941

Conversation

@Oxygen56
Copy link
Copy Markdown

@Oxygen56 Oxygen56 commented Jun 5, 2026

Fixes content_block_delta event deserialization during streaming.

Fixes #941

Fix handling of content_block_delta event variants during
streaming to prevent dropped events.

The root cause: when construct_type() is called with both an
Annotated-wrapped type AND explicit metadata, get_origin() returns
'Annotated' rather than the inner union type, causing none of the
type-check branches to match. The function then falls through to
return value, yielding a raw dict instead of a proper model.

Two-part fix:
1. construct_type(): Always unwrap Annotated from type_, even when
   metadata was explicitly passed by _construct_field.
2. _build_discriminated_union_meta(): Also unwrap Annotated from the
   union parameter, so get_args() yields individual variant types
   rather than (UnionType, metadata).

Fixes anthropics#941

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Oxygen56 Oxygen56 requested a review from a team as a code owner June 5, 2026 17:26
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.

content_block_delta event not deserialized correctly during streaming

1 participant