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 check that
walkis a proper override point in the base class and doesn't break super's logic.Assistant
Good,
walk()override pattern matches Anthropic's usage. Now let's check tests for bedrock provider to see what may break, and update tests/cassettes if needed (though we shouldn't modify tests, per instructions - but let's check if tests will fail incorrectly due to bug fix, that's expected and acceptable per instructions).Assistant
Now let's run full bedrock test suite (models + providers) to see overall state.
Assistant
Now let's also confirm end-to-end using
_customize_tool_defand_map_tool_definitionto make sure strict stays False/None for many tools.Assistant
Now confirm
_map_tool_definitionwon't setstrictfield, avoiding the Bedrock 20-tool limit issue.Assistant
Now let's run the full bedrock-related test suite once more, and also check ruff/type-check for the file we edited.
Assistant
Now let's run the full bedrock test files once more and view the diff.
Assistant
The 4 remaining test failures are exactly the tests that assert the old buggy auto-promotion behavior (that
strict=Noneschemas get promoted tostrict=True), which the issue explicitly wants removed. These are expected to fail per the issue's fix and per the instructions (existing tests testing now-changed intended behavior don't need to be "fixed").Let's double check CHANGELOG/docs mention this transformer to update if necessary.
Assistant
That's unrelated (server-side tiers, not schema strict). No doc updates needed there. Let's clean up pycache artifacts we may have introduced (not necessary) and finalize.
Assistant
Good — only the intended file is modified. Let's go through the checklist explicitly.
Assistant
This looks good. Now going through the checklist explicitly:
- Reproduced the reported error: Confirmed via scripts and the pre-existing test suite (e.g.
test_strict_none_simple_schemaassertedis_strict_compatible is Trueforstrict=None) that a simple schema withstrict=Nonewas being auto-promoted to strict-compatible, which is exactly the regression that leads Bedrock to mark toolsstrict: trueand eventually exceed the 20-strict-tool provider limit. - Confirmed the fix resolves it: After the change,
BedrockJsonSchemaTransformer(..., strict=None).is_strict_compatibleis now alwaysFalse(mirroring Anthropic's provider), and_customize_tool_defnow leaves as / instead of , so will no longer set unless the caller explicitly opted in. Verified with reproduction scripts.
- Reproduced the reported error: Confirmed via scripts and the pre-existing test suite (e.g.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.