Skip to content

fix(anthropic): bypass model_dump on content_block_stop#2953

Merged
chaynabors merged 1 commit into
strands-agents:mainfrom
chaynabors:agent-tasks/1865-anthropic-content-block-stop
Jun 25, 2026
Merged

fix(anthropic): bypass model_dump on content_block_stop#2953
chaynabors merged 1 commit into
strands-agents:mainfrom
chaynabors:agent-tasks/1865-anthropic-content-block-stop

Conversation

@chaynabors

Copy link
Copy Markdown
Member

Anthropic SDK 0.84.0+ types stream events as ParsedMessageStreamEvent, which makes content_block_stop carry a generic ParsedTextBlock that does not match the discriminated union, triggering six Pydantic serialization warnings per invocation. The fix mirrors the existing message_stop workaround from #1746: build the minimal {type, index} dict that format_chunk already consumes instead of round-tripping through model_dump.

Fixes #1865.

@github-actions github-actions Bot added size/xs python Pull requests that update python code area-model Related to models or model providers bug Something isn't working labels Jun 24, 2026
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@awsarron awsarron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add test coverage

@chaynabors chaynabors force-pushed the agent-tasks/1865-anthropic-content-block-stop branch from c423414 to 3cb6c3a Compare June 25, 2026 17:04
@chaynabors chaynabors force-pushed the agent-tasks/1865-anthropic-content-block-stop branch from 3cb6c3a to 599a752 Compare June 25, 2026 17:35
@github-actions github-actions Bot added size/s and removed size/xs labels Jun 25, 2026
@mkmeral

mkmeral commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

/strands review

Comment thread strands-py/src/strands/models/anthropic.py
@github-actions

Copy link
Copy Markdown
Contributor

Assessment: Approve

Small, focused bugfix that correctly mirrors the established message_stop workaround (#1746) to suppress Pydantic serialization warnings on content_block_stop. I verified the fix and ran the tests locally (passing). One minor maintainability suggestion left inline.

Review Notes
  • Correctness: The targeted bypass is right — content_block_stop is the event that carries the accumulated ParsedTextBlock failing the discriminated union, and format_chunk already consumes the minimal {type, index} dict. The other else-branch events don't carry the offending block, so this should fully resolve [BUG] Strands Agent AnthropicModel emits Pydantic serialization warnings with Anthropic SDK v0.84.0 #1865.
  • Testing: Good regression guard — model_dump() is wired to emit the warning, so a regression to the else branch would fail the test. Coverage confirmed by Codecov.
  • Maintainability: The new branch lacks the WHY comment its message_stop sibling has (inline note).

Nicely scoped fix that follows the existing precedent.

@chaynabors chaynabors merged commit c5f72ca into strands-agents:main Jun 25, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-model Related to models or model providers bug Something isn't working python Pull requests that update python code size/s

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Strands Agent AnthropicModel emits Pydantic serialization warnings with Anthropic SDK v0.84.0

3 participants