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
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
Let me understand the issue:
- In
pydantic-ai-slim==1.101.0,ToolDefinition.strict=Noneis being auto-promoted tostrict=Truefor simple schemas in the Bedrock provider. - Bedrock/Claude rejects requests with more than 20 strict tools.
- The fix should be similar to what was done for the Anthropic provider - don't auto-promote Bedrock tool definitions from
strict=Nonetostrict=True; only sendtoolSpec.strict = truewhen the user explicitly setstrict=True.
Let me explore the repository structure and understand the codebase.
- In
Assistant
Let me look at the key files mentioned in the issue.
Assistant
Let me do one command at a time.
Assistant
The file was truncated. Let me look for the specific functions mentioned.
Assistant
Let me look at the
_map_tool_definitionfunction around line 496.Assistant
Now let me find
_customize_tool_defwhich the issue mentions.Assistant
Let me look at the `_customize_tool_def
Assistant
Let me check how the Anthropic provider handles this.
Assistant
Now let me check the Bedrock schema transformer.
Assistant
Let me look at the Bedrock transformer class.
Assistant
Let me check the base
JsonSchemaTransformerclass to understand the default value of `is_strict_comAssistant
Let me check how the transformer is specified for Bedrock models.
Assistant
Now I understand the issue. Let me also check the Anthropic fix for
Assistant
Let me check the base class
JsonSchemaTransformerfor referenceAssistant
Now I have a clear understanding of the issue. Let me implement the fix. The problem is in
BedrockJsonSchemaTransformer.transform()— whenstrict=None, it auto-promotesis_strict_compatibletoTruefor simple schemas, which then causes_customize_tool_defto setstrict=Trueon tools, and then_map_tool_definitionsendsstrict: trueto Bedrock, hitting the 20-tool limit.The fix: add
self.is_strict_compatible = self.strict is Trueat the beginning oftransform(), just like the Anthropic transformerAssistant
Now let me apply the fix. I'll add
self.is_strict_compatible = self.strict is Trueat the start oftransform()and update the docstring:Assistant
Good. Now let me verify the change and run related tests.
Assistant
Let me look at the test file for the relevant test cases.
Assistant
Let me continue reading the tests to find the ones related to
strict=Nonebehavior.Assistant
I can see there are tests that expect
is_strict_compatible is Truewhenstrict=None. I need to update these tests to reflect the new behavior. Let me look at the full test file for all affectedAssistant
Let me read the tests to understand which ones are affected.
Assistant
Let me also check for tests in other files that test the strict-none auto-promotion
Assistant
I need to update the two tests that expected
is_strict_compatible is Truewhenstrict=None. Let me read them and update.Assistant
Now let me verify my change by looking at the diff:
Assistant
Let me verify that the output object handling won't be affected by checking the
prepare_requestmethod in the Bedrock model:Assistant
Let me do a quick sanity check by writing a script to verify the behavior
Assistant
I need to install the package first. Let me check if there's a virtual environment or how to install.
Assistant
Let me check the environment more carefully.
Assistant
It seems pip is not available or there's an issue. Let me try a different approach.
Assistant
The package depends on
pydantic-graphat a dev version. Let me check if there's a local pydantic-graph directory.Assistant
There are local packages:
pydantic_ai_slim,pydantic_graph,pydantic_evals. Let me check if there's a uv or something to manage the dependencies, or try installing from the local directory.Assistant
Now let me run the verification script:
Assistant
Let me install boto3 and then test
Assistant
Now let me run the verification script.
Assistant
The fix works correctly. Let me also verify that the schema transformations still work correctly when
strict=None.Assistant
The schema transformations still work correctly while
is_strict_compatibleisFalse. Now let me run the Bedrock tests to see the status.Assistant
Let me install the test dependencies
Assistant
Let me install more test de
Assistant
Let me install the missing plugin
Assistant
All tests are skipped. Let me check why:
Assistant
Let me check why tests are being
Assistant
Let me check how the conftest determines bedrock is installed.
Assistant
The skip reason was "bedrock not installed". Let me check how the test checks this. It may be checking for credentials or the ability to import boto3. Let me look for the skip marker in the conftest or the test
<|DSML|tool_calls> <|DSML|invoke name="bash_terminal"> <|DSML|parameter name="command" string="true">grep -rn "bedrock not installed|skip.*bedrock" /pydantic-ai/tests/</|DSML|parameter> </|DSML|invoke> </|DSML|tool_calls>
Assistant
Let me check the
imports_successfulfunction used by the testAssistant
Let me find
imports_successfulAssistant
Let me check the imports in the test file.
Assistant
The test requires
mypy_boto3_bedrock_runtime. Let me check thetry_importfunctionAssistant
It's fine - the tests require
mypy_boto3_bedrock_runtimewhich we don't need to install. The skip is correct. My change is verified via the manual test above.Let me also verify by looking at the
models/__init__.pyto confirm how the_customize_tool_defworks with the change:The key test is:
- When
strict=Nonein Bedrock,is_strict_compatibleisFalse→_customize_tool_defsets tool'sstrict = False→_map_tool_definitiondoes NOT addstrict: true→ no 20-tool limit hit.
This addresses the issue described.
Let me also double-check one more edge case: what about the Anthropic transformer in the Bedrock context? No, the Bedrock provider uses
BedrockJsonSchemaTransformer, not the Anthropic one. Each provider has its own transformer.Let me verify my change is complete by reviewing the final diff one more time.My change looks good. Let me do a final review of the diff to make sure it's clean:
- When
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
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →