Stop advertising `CodeExecutionTool` on the Bedrock `AnthropicModel` clients
Closes #11513
Why
AnthropicModel.profile advertised CodeExecutionTool on the Bedrock Anthropic clients, but both Bedrock APIs reject every code execution tool version with a 400 (#11513). Live probes (2026-10-28):
| Client | Models × versions probed | Result |
|---|---|---|
AsyncAnthropic (direct) | claude-sonnet-4-5 × 20250825/20260120, claude-haiku-4-5 × 20250825 | accepted |
AsyncAnthropicBedrock (legacy InvokeModel) | claude-sonnet-4-5, claude-opus-4-8 × both; claude-haiku-4-5 × 20250825 | 400 (Input tag ... does not match any of the expected tags / tool type ... is not supported for this model) |
AsyncAnthropicBedrockMantle (Bedrock Messages API) | claude-opus-5-5, claude-sonnet-5 × both; claude-haiku-4-5 × 20250825 | 400 (tool type ... is not supported for this model) |
This follows the existing _*_UNSUPPORTED_CLIENTS pattern: a new _CODE_EXECUTION_UNSUPPORTED_CLIENTS = (AsyncAnthropicBedrock, AsyncAnthropicBedrockMantle) drops the tool from supported_native_tools in AnthropicModel.profile, so a run that asks for it raises a UserError before sending (or omits it when optional=True). Vertex AI, Foundry and Claude Platform on AWS (AsyncAnthropicAWS) weren't probed and are unchanged.
Thanks to @rscholz98, whose #11534 gated the legacy client; the Bedrock Messages API turned out to reject the tool too (Anthropic's "Claude Platform on AWS" is AsyncAnthropicAWS, not AsyncAnthropicBedrockMantle).
New public surface
none
User-visible behavior
agent = Agent(AnthropicModel('anthropic.claude-opus-5-5', provider=AnthropicProvider(anthropic_client=AsyncAnthropicBedrockMantle())),
capabilities=[NativeTool(CodeExecutionTool())])
await agent.run('...')
# before: ModelRequestRejectedError 400 "tool type 'code_execution_20260120' is not supported for this model"
# after: UserError "Native tool(s) ['CodeExecutionTool'] not supported by this model. ..."
Verification
test_code_execution_tool_client_gating: per-clientsupported_native_toolssnapshot, and theUserErroron both Bedrock clients.test_code_execution_tool_rejected_by_bedrock: 5 recorded 400s across both Bedrock APIs and both tool versions.- Both are in
tests/models/anthropic/test_code_execution_clients.py. Ran locally:tests/models/anthropic/andtests/models/test_anthropic.py; pyright on touched files.
What changes for existing users
On the Bedrock clients, a request that would have failed with a provider 400 now fails earlier with a UserError; nothing changes on any other client.
PR decisions
2026-10-28 · gate both Bedrock clients, not only legacy · iter -
- Decision: _CODE_EXECUTION_UNSUPPORTED_CLIENTS = (AsyncAnthropicBedrock, AsyncAnthropicBedrockMantle)
- Why: Live probe 2026-10-28: Mantle rejects code_execution_20250825/20260120 on opus-5-5, sonnet-5, haiku-4-5 with 400; contributor PR #11534 assumed Mantle = Claude Platform on AWS (that is AsyncAnthropicAWS)
- Source: https://github.com/pydantic/pydantic-ai/issues/11513
2026-10-28 · leave Vertex/Foundry/AsyncAnthropicAWS ungated · iter -
- Decision: Not probed (no credentials enabled), so unchanged
- Why: Root AGENTS.md: extend only to surfaces where the defect is reproduced
- Source: https://github.com/pydantic/pydantic-ai/issues/11513
2026-10-28 · count_tokens test uses CodeExecutionTool(optional=True) · iter -
- Decision: Bedrock rows of test_count_tokens_server_tools_by_client now leave the tool out instead of raising
- Why: The test pins count_tokens server-tool dropping; code execution no longer reaches Bedrock at all
- Source: https://github.com/pydantic/pydantic-ai/issues/11513
2026-10-28 · pre-push review 1 of 3 at e8ab50199ae3c16f9b5de84291031adb9433a4e6 · iter -
- Decision: reserved; dispatching
- Why: tree aef6ee039cf7ce95216c2e82bbfb59197f7031cd; scope 3817d208c2..HEAD (full branch, first review)
- Source: https://github.com/pydantic/pydantic-ai/tree/bedrock-code-execution-unsupported
2026-10-28 · pre-push review 1 of 3 at e8ab50199ae3c16f9b5de84291031adb9433a4e6 · iter -
- Decision: one finding dismissed with evidence: unused request_capture param is required (request.getfixturevalue on the async-fixture chain raised RuntimeError without it; same pattern as test_anthropic_web_tools_rejected_by_bedrock_messages_api)
- Why: tree aef6ee039cf7ce95216c2e82bbfb59197f7031cd; scope 3817d208c2..e8ab50199a full branch
- Source: https://github.com/pydantic/pydantic-ai/tree/bedrock-code-execution-unsupported
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.
Posted by CLAI on Douwe's behalf.