diff --git a/litellm/llms/anthropic/chat/transformation.py b/litellm/llms/anthropic/chat/transformation.py index 8d6aa4b6b24..e597577f900 100644 --- a/litellm/llms/anthropic/chat/transformation.py +++ b/litellm/llms/anthropic/chat/transformation.py @@ -676,7 +676,12 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig): **input_schema_filtered ) - _strict = tool["function"].get("strict") or _input_schema.get("strict") + _function_strict = tool["function"].get("strict") + _strict = ( + _function_strict + if _function_strict is not None + else _input_schema.get("strict") + ) _tool = AnthropicMessagesTool( name=tool["function"]["name"], diff --git a/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py b/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py index 65c0f953115..231b8c9192b 100644 --- a/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py +++ b/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py @@ -4799,3 +4799,28 @@ def test_map_tool_helper_strict_false_omits_field(): result, _ = config._map_tool_helper(tool) assert result is not None assert "strict" not in result + + +def test_map_tool_helper_strict_false_function_overrides_parameters_true(): + """strict=False on function level must not be overridden by a leftover + strict=True in parameters.""" + config = AnthropicConfig() + + tool = { + "type": "function", + "function": { + "name": "get_weather", + "description": "Get weather", + "strict": False, + "parameters": { + "type": "object", + "properties": {"city": {"type": "string"}}, + "strict": True, + }, + }, + } + + result, _ = config._map_tool_helper(tool) + assert result is not None + assert "strict" not in result + assert "strict" not in result["input_schema"]