Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions litellm/types/llms/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AnthropicMessagesToolChoice(TypedDict, total=False):
"additionalProperties": Optional[bool],
"required": Optional[List[str]],
"$defs": Optional[Dict],
"strict": Optional[bool],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mind documenting this new feature @Bradley-Butcher

Here would be great:

},
total=False,
)
Expand Down
75 changes: 75 additions & 0 deletions tests/llm_translation/test_anthropic_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1691,3 +1691,78 @@ def test_anthropic_via_responses_api():

print(f"✓ All {len(events_seen)} events matched expected structure")
print(f"✓ Received {text_delta_count} text delta chunks")

def test_anthropic_strict_parameter_passthrough():
"""Test that the strict parameter in tool parameters is passed through to Anthropic input_schema"""
args = {
"non_default_params": {
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather information",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"},
},
"required": ["location"],
"strict": True,
},
},
}
],
}
}

mapped_params = litellm.AnthropicConfig().map_openai_params(
non_default_params=args["non_default_params"],
optional_params={},
model="claude-sonnet-4-5-20250929",
drop_params=False,
)

# Verify the strict parameter is in the mapped tool's input_schema
assert "tools" in mapped_params
assert len(mapped_params["tools"]) == 1
tool = mapped_params["tools"][0]
assert "input_schema" in tool
assert tool["input_schema"]["strict"] is True

def test_anthropic_strict_not_present():
"""Test that the strict parameter in tool parameters is passed through to Anthropic input_schema"""
args = {
"non_default_params": {
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather information",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"},
},
"required": ["location"],
},
},
}
],
}
}

mapped_params = litellm.AnthropicConfig().map_openai_params(
non_default_params=args["non_default_params"],
optional_params={},
model="claude-sonnet-4-5-20250929",
drop_params=False,
)

# Verify the strict parameter does not exist if it is not passed in
assert "tools" in mapped_params
assert len(mapped_params["tools"]) == 1
tool = mapped_params["tools"][0]
assert "input_schema" in tool
assert "strict" not in tool["input_schema"]
Loading