mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-22 00:31:44 +00:00
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.
This commit is contained in:
parent
0b966ff825
commit
b67bf3cce3
2 changed files with 31 additions and 1 deletions
|
|
@ -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"],
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue