Skip to content

fix(bedrock): normalize empty toolResult content arrays in _format_bedrock_messages#2123

Open
ghhamel wants to merge 2 commits intostrands-agents:mainfrom
ghhamel:fix/normalize-empty-tool-result-content
Open

fix(bedrock): normalize empty toolResult content arrays in _format_bedrock_messages#2123
ghhamel wants to merge 2 commits intostrands-agents:mainfrom
ghhamel:fix/normalize-empty-tool-result-content

Conversation

@ghhamel
Copy link
Copy Markdown

@ghhamel ghhamel commented Apr 14, 2026

Description

Some model providers (e.g., Nemotron) reject toolResult blocks with content: [] via the Bedrock Converse API, while others (e.g., Claude) accept them. When a tool returns an empty result (common with MCP tools like awslabs/postgres-mcp-server), the SDK passes the empty content array through to the Converse API unchanged, causing a ValidationException on strict models.

This PR normalizes empty toolResult.content arrays to [{"text": ""}] in _format_bedrock_messages, following the same pattern as:

  • The TypeScript SDK's _formatMessages in bedrock.ts, which already filters empty content
  • Existing Python SDK normalizations in the same function (SDK_UNKNOWN_MEMBER filtering, DeepSeek reasoningContent dropping)

Related Issues

Fixes #2122

Documentation PR

N/A

Type of Change

Bug fix

Testing

  • Added test_format_bedrock_messages_normalizes_empty_tool_result_content — verifies empty toolResult.content is replaced with [{"text": ""}]

  • Added test_format_bedrock_messages_preserves_nonempty_tool_result_content — verifies non-empty content is not modified

  • All 129 existing test_bedrock.py tests pass with no regressions

  • Verified fix against live Bedrock endpoints: Nemotron succeeds with the fix, Claude continues to work unchanged

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

ghhamel added 2 commits April 14, 2026 12:55
…drock_messages

Some model providers (e.g., Nemotron) reject toolResult blocks with
content: [] via the Bedrock Converse API, while others (e.g., Claude)
accept them. This causes a ValidationException when the SDK passes
empty tool result content through to the Converse API unchanged.

Normalize empty toolResult content arrays to [{"text": ""}] in
_format_bedrock_messages, following the same pattern as the TypeScript
SDK's _formatMessages in bedrock.ts and existing Python SDK
normalizations (SDK_UNKNOWN_MEMBER filtering, DeepSeek reasoningContent).

Fixes strands-agents#2122
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.

[BUG] Empty toolResult content array causes ValidationException with Nemotron (and potentially other strict models) via Bedrock Converse API

1 participant