Skip to content

fix(py/plugins/amazon-bedrock): keep and replay signed reasoning with empty text - #6842

Closed
hkarmoush wants to merge 1 commit into
genkit-ai:mainfrom
hkarmoush:hkarmoush-fix-py-bedrock-empty-signed-reasoning
Closed

hkarmoush wants to merge 1 commit into
genkit-ai:mainfrom
hkarmoush:hkarmoush-fix-py-bedrock-empty-signed-reasoning

Conversation

@hkarmoush

Copy link
Copy Markdown
Contributor

Same bug as #6798 / #6839, Bedrock flavor.

Claude can return a reasoning block with empty text and a valid signature, mostly on the turn after a tool call. On Bedrock that block was lost in two places:

  • streaming: _blocks_to_parts only kept a reasoning block if it had text or redacted content, so a signature-only block disappeared (the non-streaming _reasoning_block_to_part already keeps it)
  • request: _reasoning_part_to_blocks required text and signature, so even a non-streamed part was dropped on replay

With thinking enabled, a tool-use turn has to start with its thinking block, so the next request in the tool loop can fail.

Now streaming keeps the block when it has a signature, and the request side sends reasoningText {text: '', signature} when there's a signature. Unsigned reasoning is still dropped, and a redacted-only part still only sends redactedContent.

One thing I couldn't check: I don't have AWS access set up, so I haven't confirmed live that Converse accepts reasoningText.text as an empty string. Anthropic's own API accepts the empty thinking block it produced, and Bedrock hands it back to the same model, so I expect it to work, but it'd be great if someone with Bedrock access could run a thinking + tool call turn against it.

Tests:

  • converters: signed empty reasoning encodes as reasoningText with text: ''; a response with [reasoning(''), toolUse] round trips to the request with the reasoning block first; unsigned empty reasoning is still dropped
  • stream: a signature-only reasoning block becomes a reasoning part with the signature in metadata

uv run pytest packages/genkit-amazon-bedrock/tests passes (477 passed, 24 skipped), ruff, pyright and ty are clean.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the Amazon Bedrock integration to correctly handle and preserve signed reasoning blocks that contain empty text (e.g., when Claude signs an empty thinking block at the start of a tool-use turn). This is handled in both the converters and stream processing modules, and corresponding unit tests have been added to verify the round-trip behavior and streaming scenarios. I have no feedback to provide as there are no review comments.

@hkarmoush

Copy link
Copy Markdown
Contributor Author

@huangjeff5 could you take a look when you have a moment? Bedrock was dropping signed reasoning blocks that came back with empty text, so this keeps and replays them. Same fix as #6839 for Anthropic.

… empty text

Claude on Bedrock can return a reasoning block with empty text and a
valid signature. The streaming path dropped it because it only kept
blocks with text or redacted content, and the request side dropped it
again because it required both text and a signature. With thinking
enabled, a tool-use turn has to start with that block, so the next
request in a tool loop could fail.

Keep signed blocks when streaming, as the non-streaming path already
does, and send signed reasoning back even when its text is empty.
Unsigned reasoning is still dropped.
@hkarmoush
hkarmoush force-pushed the hkarmoush-fix-py-bedrock-empty-signed-reasoning branch from 4c94aa9 to 5ce80fd Compare November 13, 2026 07:38
@MichaelDoyle

Copy link
Copy Markdown
Contributor

Closing as subsumed: the Amazon Bedrock signed reasoning changes here were folded directly into #6839.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants