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.
Assistant
Now let's verify the change looks correct and check other places referencing "auto-promot" (e.g., docstring in bedrock model file) that might need updates.
Assistant
Now let's write a quick reproduction script to test the fix before running the full test suite.
Assistant
Missing dependencies entirely. Let's set up a venv using uv sync.
Assistant
A venv already exists. Let's just try using it directly.
Assistant
Good, the venv already has things set up. Let's run the reproduction test.
Assistant
This confirms the fix:
strict=Noneno longer auto-promotes to strict-compatible; only explicitstrict=Truegets the strict transformation. Now let's run the existing test suite for bedrock providers/models to see what breaks and confirm nothing unexpected.Assistant
No strict-related tests there. Let's run the full test_bedrock.py in tests/models too, and check the four failing tests in detail to see if we should adjust anything (e.g., additionalProperties still being set even for strict=None due to snapshot including it — that was old behavior, expected to change).
Assistant
These test failures are exactly the tests for the old auto-promotion behavior we're intentionally removing. This is expected and acceptable per instructions. Now let's check the models/test_bedrock.py cassette tests to make sure nothing regressed there (functional integration tests using cassettes).
Assistant
There's
tests/models/bedrock/test_strict_tool_calls.py. Let's look at that.Assistant
Good, these all use explicit strict values, no
strict=Nonepromotion tests with cassettes. Let's run this whole test file.Assistant
All pass. Now let's run the full test_bedrock provider suite and models test_bedrock.py, plus grep for other tests referencing "is_strict_compatible" for Bedrock elsewhere (e.g. models test).
Assistant
Now let's check
tests/test_capabilities.pyandtests/test_tool_search.pywhich grep matched for "strict" + "bedrock".Assistant
Not related to strict promotion; unrelated model list. Let's run these two test files fully to be safe.
Assistant
Now let's also update the four failing tests in
tests/providers/test_bedrock.py— wait, we shouldn't modify tests. Let's double check the diff so far and confirm only bedrock.py provider file changed.Assistant
That's unrelated (service tier). Now let's write a full reproduction with many tools using an Agent with a mocked model to confirm the produced tool specs don't include
strictfor large toolsets.Assistant
This confirms the fix resolves the exact issue: with 73 simple tools using
strict=None, none get auto-promoted to strict, avoiding the Bedrock "Too many strict tools" error.Now let's run the broader test suite related to providers and models to be thorough.
Assistant
These are all pre-existing/unrelated failures (huggingface hub deprecation warnings, code interpreter test unrelated to Bedrock). Not caused by my change. Let's confirm errors too aren't related.
Assistant
Environment-related fixture errors (llamacpp etc.), unrelated to our change. This confirms our change doesn't introduce new failures outside the intentionally affected bedrock strict tests.
Assistant
Now let's also check CHANGELOG.md convention to see whether we should add an entry (some repos require this). Let's check.
Assistant
This is a manually curated breaking-changes list tied to PR numbers, not something I should edit blindly since I don't have a PR number. I'll skip it — not required for resolving the issue.
Let's double check the final diff and run the full pytest for tests directly related to bedrock one more time to confirm final state.
Assistant
Clean. Let's finalize the diff view and remove any leftover temp files (none were created). Let's view the final file section once more.
Assistant
The change looks complete and clean. Let's finalize by reviewing the checklist.
Assistant
Checklist review:
- If an error was reported in the issue description, I have successfully reproduced it. ✅ I reproduced the root cause directly by instantiating
BedrockJsonSchemaTransformerwithstrict=Noneon a simple schema (as used for the 73 tools in the report) and confirmedis_strict_compatiblewasTrue, which via_customize_tool_defwould have setToolDefinition.strict = Truefor every simple tool — exactly the auto-promotion behavior described in the issue that leads to Bedrock's "Too many strict tools" error.
- If an error was reported in the issue description, I have successfully reproduced it. ✅ I reproduced the root cause directly by instantiating
Assistant
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error. ✅ Verified with the 73-tool reproduction script above: after the fix,
strict count: 0 out of 73— none of the simple tool schemas withstrict=Noneget auto-promoted tostrict=True, so Bedrock will no longer reject the request for exceeding the 20-strict-tools limit. Explicit / behavior (tested via existing cassette-based tests in ) is unaffected and all 20 of those tests still pass.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.