feat(bedrock): add tool_runner support with message sanitization #1107
+109
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR enables the
tool_runnerAPI on AWS Bedrock by adding message sanitization to strip Bedrock-unsupported fields.Fixes #1106
Problem
When using
client.beta.messages.tool_runner()with Bedrock, the SDK adds internal tracking fields that Bedrock's stricter API validation rejects with 400 errors:Root Cause
tool_runnernot exposed: The BedrockMessagesclass only delegatescreate, nottool_runnerparsed_outputrejection: The SDK's.parse()method addsparsed_outputto text blocks for structured output trackingcallerrejection: The SDK addscallerto tool_use blocks for code execution featuresSolution
tool_runnerdelegation - Expose the tool_runner API on Bedrock clients_sanitize_for_bedrock()helper - Strip unsupported fields from message content blockscreate,parse,streammethods - Apply sanitization transparently before API callsThe sanitization is applied at the Bedrock layer so it doesn't affect direct Anthropic API usage.
Changes
BEDROCK_UNSUPPORTED_FIELDSset for extensibility_sanitize_for_bedrock()sanitization functioncreate,parse,streammethods with sanitizationtool_runnerdelegation to both sync and async classesTested Features
tool_runnerAPI access on Bedrocktoken_threshold)parsed_outputfield sanitizationcallerfield sanitizationExample Usage
Test plan
tool_runnerworks with Bedrock after patchparsed_outputorcallerfieldscreatefunctionality still works🤖 Generated with Claude Code