From b67bf3cce3f09b609068537757f0bdad306a48f8 Mon Sep 17 00:00:00 2001 From: Jonathan Wrede Date: Sat, 9 May 2026 20:46:45 +0000 Subject: [PATCH] fix: use is-None chaining so strict=False is not swallowed by or When strict=False is set at the function level and strict=True remains in parameters, the or operator treats False as falsy and falls through to the parameters value. Use is-None chaining so the function-level value always takes precedence when explicitly set. --- litellm/llms/anthropic/chat/transformation.py | 7 +++++- .../test_anthropic_chat_transformation.py | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) 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"]