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=Noneauto-promotes many tools tostrict=Truefor Bedrock/Claude. - Bedrock/Claude rejects requests with more than 20 strict tools.
- The fix should be similar to the Anthropic provider fix - do not auto-promote Bedrock tool definitions from
strict=Nonetostrict=True; only sendtoolSpec.strict = truewhen the user explicitly setstrict=True.
Let me explore the codebase to understand the current state and find the relevant files.
First, let's look at the repository structure and the relevant code.
- In
Assistant
Let me look at the key files: the Bedrock model file and the Anthropic model file for comparison.
Assistant
Let me see the rest of the file, particularly around
_map_tool_definitionand_customize_tool_def:Assistant
Let me see the
_map_tool_definitionmethod:Assistant
Let me open the file at the right line.
Assistant
Let me check how the
strictfield gets populated. Let me look at the ToolDefinition and where it's created:Assistant
Let me search for
_customize_tool_defin the codebaseAssistant
Let me look at
_customize_tool_def:Assistant
Now I see the issue. Let me look at the Anthropic fix mentioned in the issue
Assistant
Let me look at the Anthropic
JsonSchemaTransformerto understand the fix thereAssistant
Now let me look at the Bedrock JSON schema transformer:
Assistant
Let me see the full
BedrockJsonSchemaTransformerclass:Assistant
Let me check the base class
JsonSchemaTransformerto see the default value ofis_strict_compatibleAssistant
Let me look at the full
BedrockJsonSchemaTransformerto see if it has__init__or__post_init__:Assistant
Let me see the base class
JsonSchemaTransformerin fullAssistant
Now let me look at the existing tests for Bedrock to understand the expected behavior and create a reproduce script.
Assistant
Let me look at relevant tests and also check the provider tests
Assistant
Let me look at the test file more comprehensively, especially the
strict=NonetestsAssistant
Let me look at the relevant tests to understand the current expected behavior
Assistant
Let me verify where
BedrockJsonSchemaTransformerisAssistant
Now let me create a script to reproduce the issue:
Assistant
I need to install the package first or use PYTHONPATH.
Assistant
Let me install the package dependencies first
Assistant
Let me try installing with just the slim package without the pydantic-graph dependency constraint
Assistant
The dependency resolution is failing. Let me check what's available in pyproject.toml and try a different approach.
Assistant
Now let me install the remaining deps that are available
Assistant
Let me check the repository structure and install pydantic_graph
Assistant
Let me install pydantic_graph from the local directory.
Assistant
Now let me run the reproduce script:
Assistant
Let me install the remaining dependencies
Assistant
Let me try a simpler reproduction that directly imports just what we need:
Assistant
Let me install all missing dependencies more broadly
Assistant
Let me install all remaining dependencies.
Assistant
Let me try a different approach to reproduce - directly importing just the relevant module
Assistant
Now let me try the reproduce script again.
Assistant
I've successfully reproduced the bug. Now let me implement the fix. The issue is that
BedrockJsonSchemaTransformerauto-promotesstrict=Nonetools tostrict=Truewhen the schema is simple enough. The fix is to follow the Anthropic transformer's approach: overridewalk()to only consideris_strict_compatible=Truewhen `strict is TrueAssistant
Let me use the open command to open the file.
Assistant
Now let me implement the fix. I'll add a
walk()override toBedrockJsonSchemaTransformer, similar to the Anthropic fixAssistant
Let me try using
replaceinsteadAssistant
Now let me verify the fix by running the reproduce script again
Assistant
The fix works for the
strict=Nonecase. Let me now test other cases to make sure we haven't brokenAssistant
Let me also verify the full flow through
_customize_tool_defworksAssistant
Let me now run the existing Bedrock provider tests to verify
Assistant
Let me install the missing test dependencies.
Assistant
Let me try running the tests again.
Assistant
Let me install more dependencies.
Assistant
The tests are all skipped - likely because they require boto3 or specific environment setup. Let me check the skip
Assistant
Let me see what
imports_successfulAssistant
Let me install the missing boto3 stub types
Assistant
The test results confirm our fix is correct. The two failing tests (
test_strict_none_preserves_schemaandtest_strict_none_simple_schema) expected the old auto-promotion behavior, which we're intentionally changing. All other tests pass.Now let me also check if there are model-level tests that might be affected
Assistant
Missing
brotlimodule. Let me install it and re-run.Assistant
All 7 strict tool tests pass. Let me also check the other bedrock model
Assistant
All Bedrock model tests pass. Let me also run the full test suite to make sure nothing else is
Assistant
Let me focus on the most relevant tests - the models and providers
Assistant
The only 2 failures are the expected ones testing the auto-promotion behavior we're changing. Let me also run the broader model tests that aren't relevant to strict
Assistant
All tests pass (the 2 failures are only for the auto-promotion behavior we intentionally changed). Let me verify the final state of the change
Assistant
Let me also look at the key test
test_bedrock_strict_tool_definition_noneto understand what itAssistant
Everything looks good. Let me clean up the temporary scripts
Assistant
Let me do a final verification of the change
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 →