Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

merge: resolve conflict with litellm_internal_staging in anthropic transformation tests

mateod6005a1876a2
diff --cc tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py
index b56e6c41f23,c4df46dea83..2a955845861
--- a/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py
+++ b/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py
@@@ -6210,105 -6209,43 +6210,147 @@@ def test_disabled_thinking_omitted_only
assert request["thinking"] == {"type": "disabled"}
+ "tool_choice",
+ ["required", {"type": "required"}, {"type": "function", "function": {"name": "get_weather"}}],
+)
+def test_forced_tool_choice_raises_clean_error_on_fable_5_1_without_drop_params(
+ local_model_cost_map, tool_choice, monkeypatch
+):
+ """Fable 5.1 400s on tool_choice type any/tool (thinking is always on and a
+ forced call would skip it); without drop_params the caller gets a clean
+ client-side 400 that explains the workaround, not a provider error."""
+ monkeypatch.setattr(litellm, "drop_params", False)
+ config = AnthropicConfig()
+
+ with pytest.raises(litellm.utils.UnsupportedParamsError, match="forced tool use"):
+ config.map_openai_params(
+ non_default_params={"tool_choice": tool_choice},
+ optional_params={},
+ model="claude-fable-5-1",
+ drop_params=False,
+ )
+
+
+ "tool_choice",
+ ["required", {"type": "required"}, {"type": "function", "function": {"name": "get_weather"}}],
+)
+def test_forced_tool_choice_downgraded_to_auto_on_fable_5_1_with_drop_params(
+ local_model_cost_map, tool_choice
+):
+ config = AnthropicConfig()
+
+ result = config.map_openai_params(
+ non_default_params={"tool_choice": tool_choice},
+ optional_params={},
+ model="claude-fable-5-1",
+ drop_params=True,
+ )
+
+ assert result["tool_choice"] == {"type": "auto"}
+
+
+def test_forced_tool_choice_downgrade_keeps_parallel_tool_calls_flag(local_model_cost_map):
+ config = AnthropicConfig()
+
+ result = config.map_openai_params(
+ non_default_params={"tool_choice": "required", "parallel_tool_calls": False},
+ optional_params={},
+ model="claude-fable-5-1",
+ drop_params=True,
+ )
+
+ assert result["tool_choice"] == {"type": "auto", "disable_parallel_tool_use": True}
+
+
[email protected]("tool_choice, expected_type", [("auto", "auto"), ("none", "none")])
+def test_unforced_tool_choice_forwarded_on_fable_5_1(
+ local_model_cost_map, tool_choice, expected_type, monkeypatch
+):
+ monkeypatch.setattr(litellm, "drop_params", False)
+ config = AnthropicConfig()
+
+ result = config.map_openai_params(
+ non_default_params={"tool_choice": tool_choice},
+ optional_params={},
+ model="claude-fable-5-1",
+ drop_params=False,
+ )
+
+ assert result["tool_choice"]["type"] == expected_type
+
+
[email protected]("model", ["claude-fable-5", "claude-opus-5", "claude-sonnet-5"])
+def test_forced_tool_choice_forwarded_on_models_that_support_it(
+ local_model_cost_map, model, monkeypatch
+):
+ monkeypatch.setattr(litellm, "drop_params", False)
+ config = AnthropicConfig()
+
+ result = config.map_openai_params(
+ non_default_params={"tool_choice": "required"},
+ optional_params={},
+ model=model,
+ drop_params=True,
+ )
+
+ assert result["tool_choice"] == {"type": "any"}
+
+
+def test_forced_tool_choice_gating_driven_by_model_map_flag(local_model_cost_map, monkeypatch):
+ """The gate must read ``supports_forced_tool_use`` from the model map, not
+ the model name: a flagged entry gates a model whose name says nothing."""
+ monkeypatch.setitem(litellm.model_cost, "claude-zeta-9", {"supports_forced_tool_use": False})
+ config = AnthropicConfig()
+
+ result = config.map_openai_params(
+ non_default_params={"tool_choice": "required"},
+ optional_params={},
+ model="claude-zeta-9",
+ drop_params=True,
+ )
+
+ assert result["tool_choice"] == {"type": "auto"}
++
++
+ def test_anthropic_drop_params_keeps_format_only_output_config(monkeypatch):
+ """``drop_params=True`` must not consume ``output_config.format``: the drop
+ gate is an effort gate and ``format`` is a structured-output field."""
+ monkeypatch.setattr(litellm, "drop_params", True)
+ config = AnthropicConfig()
+ schema_format = {
+ "type": "json_schema",
+ "schema": {"type": "object", "properties": {"z": {"type": "integer"}}},
+ }
+
+ result = config.transform_request(
+ model="claude-3-haiku-20240307",
+ messages=[{"role": "user", "content": "Hello"}],
+ optional_params={"output_config": {"format": schema_format}},
+ litellm_params={},
+ headers={},
+ )
+
+ assert result.get("output_config") == {"format": schema_format}
+
+
+ def test_anthropic_drop_params_reduces_mixed_output_config_to_format(monkeypatch):
+ """``drop_params=True`` drops the effort key on unsupported models but keeps
+ ``format`` so structured outputs still reach the provider."""
+ monkeypatch.setattr(litellm, "drop_params", True)
+ config = AnthropicConfig()
+ schema_format = {
+ "type": "json_schema",
+ "schema": {"type": "object", "properties": {"z": {"type": "integer"}}},
+ }
+
+ result = config.transform_request(
+ model="claude-3-haiku-20240307",
+ messages=[{"role": "user", "content": "Hello"}],
+ optional_params={"output_config": {"effort": "low", "format": schema_format}},
+ litellm_params={},
+ headers={},
+ )
+
+ assert result.get("output_config") == {"format": schema_format}