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
I'll start by exploring the repository structure and locating the Bedrock-related code that handles tool strict mode.
- Assistant
Next I'll inspect how Bedrock and Anthropic handle
strict=Noneon tool definitions. - Assistant
Hmm empty result? Let me try differently.
- Assistant
rg is not available, let me use grep.
- Assistant
Let me look at the Bedrock schema transformer and how customize_tool_def works.
- Assistant
I'll open the Bedrock provider and compare it with Anthropic's strict handling.
- Assistant
Let me continue reading the BedrockJsonSchemaTransformer.
- Assistant
Let me read Anthropic’s transformer and the Bedrock strict-tool tests to match the expected behavior.
- Assistant
There's already a test expecting
strict=None→ no strict field — I'll read that next. - Assistant
Let me continue reading this test file and the transformer tests.
- Assistant
I'll re-read Bedrock's NativeOutput handling and the related transformer tests.
- Assistant
Next I'll inspect the base transformer and how
_customize_tool_defpromotesstrict. - Assistant
Looking at the tests more carefully - the provider unit tests currently expect
is_strict_compatible=Trueforstrict=None. But the integration test saysstrict=None → no strict fieldwhich only w...I need to update the BedrockJsonSchemaTransformer so thatis_strict_compatiblereturns True only whenstrictis explicitly True, rather than treating None as auto-promotable. This prevents the 20-tool limit violation while keeping the existing behavior for NativeOutput (which forces strict=True).The doc string mentions auto-promotion was intentional for PR #4237, but we need to revert that for Bedrock to match Anthropic's approach.
Let me start by examining the current implementation of BedrockJsonSchemaTransformer. I should look at the file where it's defined.
Let me check the current code structure.
- Assistant
I'll read the remaining Bedrock transformer tests and check git history around #4237.
- Assistant
Checking OpenAI's transformer and whether Bedrock docs mention auto-promotion.
- Assistant
Checking docs/changelog mentions of auto-promotion, then applying the fix.
- Assistant
Implementing the fix so Bedrock no longer auto-promotes
strict=Nonetostrict=True. - Assistant
I'll update the transform method and docstring to match Anthropic behavior.
- Assistant
Verifying the fix with a temporary reproduction script.
- Assistant
Confirming NativeOutput still forces
strict=Truevia prepare_request. - Assistant
Running the Bedrock transformer tests that should still pass and checking which fail due to expected behavior changes.
- Assistant
The four failing tests are exactly the auto-promotion cases we’re intentionally changing. Checking the final diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.