ISSUE DESCRIPTION Bedrock: strict=None auto-promotes many tools to strict and hits…
- User
ISSUE DESCRIPTION
Bedrock:
strict=Noneauto-promotes many tools to strict and hits provider limitInitial Checks
- I'm using the latest version of Pydantic AI
- I've searched for my issue in the issue tracker before opening this issue
Description
Summary
pydantic-ai-slim==1.101.0can now fail Bedrock Claude requests with many tools becauseToolDefinition.strict=Noneis inferred asstrict=Truefor simple schemas. Bedrock/Claude rejects requests with more than 20 strict tools (source):ValidationException: Too many strict tools (73). The maximum number of strict tools supported is 20.This is a behavior regression for callers that did not explicitly opt into strict tool definitions.
What happened
A production agent sends 73 function tools to Bedrock. Before 1.101.0 these tools were sent as normal, non-strict Bedrock tools.
After 1.101.0, these tool definitions have strict=None, and the Bedrock schema transformer infers many/all simple schemas as strict-compatible. _customize_tool_def() then replaces strict=None with strict=True, and BedrockConverseModel._map_tool_definition() sends toolSpec.strict = true. Bedrock rejects the request because it only supports 20 strict tools.
Disclosure: I authored #4237 ✋ . My tests and vcr cassettes didn't account for the >20-tool case.
Expected behavior
For Bedrock, strict=None should not silently turn large toolsets into strict toolsets that violate Bedrock limits.
Possible fixes:
Similar to Anthropic, do not auto-promote Bedrock tool definitions from strict=None to strict=True; only send toolSpec.strict = true when the user explicitly set strict=True.
Workaround
Callers can explicitly set strict=False on Bedrock tool definitions, but this requires every application with larger Bedrock toolsets to discover and patch the behavior.
Minimal, Reproducible Example
Logfire Trace
No response
Python, Pydantic AI & LLM client version
- Python: 3.14
- Pydantic AI: 1.101.0
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /pydantic-ai, current file: none) bash-$
- Assistant
I'll start by exploring the repository structure and locating the Bedrock-related code that handles
strict=Nonetool definitions. - Assistant
Next I'll inspect Bedrock's tool strict handling and compare it to Anthropic's approach.
- Assistant
Hmm, rg didn't find anything? Maybe the path is wrong or tools aren't installed. Let me try grep.
- Assistant
Let me look at the schema transformer and _customize_tool_def
- Assistant
I found the relevant provider code; next I'll compare how Bedrock and Anthropic handle auto-promotion of
strict. - Assistant
I'll read the rest of the Bedrock schema transformer and the related tests next.
- Assistant
I opened the wrong file with goto. Let me open bedrock provider fully.
- Assistant
I'll inspect the existing Bedrock provider and strict-tool tests to see what behavior they currently expect.
- Assistant
Let me check how
is_strict_compatibledefaults in the base transformer and what the Anthropic tests cover. - Assistant
I'll inspect how NativeOutput and the tool-definition mapping interact with Bedrock's strict handling.
- Assistant
There's already a unit test covering
strict=None; I'll read it and trace prepare_request's tool customization path. - Assistant
Checking the base
JsonSchemaTransformerbehavior for defaults and howwalk/transforminteract. - Assistant
I need to confirm the order of tool/output customization relative to Bedrock's
prepare_requestforce tostrict=True. - Assistant
I'll update
BedrockJsonSchemaTransformersostrict=Noneno longer auto-promotes tools to strict mode. - Assistant
The replace didn't match because those lines weren't in view; I'll open that section and reapply the edit.
- Assistant
Now I'll edit lines 61-113.
- Assistant
Next I'll write a small reproduction script to confirm many
strict=Nonetools no longer get auto-promoted. - Assistant
The script had leftover junk; cleaning it up and rerunning.
- Assistant
I need to check how the Bedrock profile is obtained.
- Assistant
Let me simplify the test script.
- Assistant
The main fix is working (0/73 strict). I'll check the profile assertion next.
- Assistant
I'll run the still-valid Bedrock strict tests and scan the docs for outdated auto-promotion wording.
- Assistant
I'll run the
strict_nonecases and the Bedrock strict-tool model tests to see what still fails. - Assistant
I'll run the Bedrock native-output tests and the remaining provider tests that should still pass under the new behavior.
- Assistant
I'll scan the Bedrock docs for any language about auto-promoting default-strict tools.
- Assistant
I'll tidy the docstring so it matches the Anthropic transformer's style more closely.
- Assistant
One more check: I'll verify tool customization through the full model
prepare_requestpath.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →