From 6f4fbe412120eaf402d73aec84453f5992ce0aca Mon Sep 17 00:00:00 2001 From: arpan sahu <28574248+arpansahu@users.noreply.github.com> Date: Thu, 27 Aug 2026 07:28:13 +0530 Subject: [PATCH] fix(snowflake): reject invalid Claude tool_choice strings Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: arpan sahu <28574248+arpansahu@users.noreply.github.com> --- litellm/llms/snowflake/chat/transformation.py | 7 ++++++- .../chat/test_snowflake_chat_transformation.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/litellm/llms/snowflake/chat/transformation.py b/litellm/llms/snowflake/chat/transformation.py index 0968185b084..bc391e83f7d 100644 --- a/litellm/llms/snowflake/chat/transformation.py +++ b/litellm/llms/snowflake/chat/transformation.py @@ -322,7 +322,12 @@ class SnowflakeConfig(SnowflakeBaseConfig, OpenAIGPTConfig): "required": {"type": "any"}, "none": {"type": "none"}, } - return mapping.get(tool_choice, {"type": "auto"}) + if tool_choice not in mapping: + raise ValueError( + "Unsupported tool_choice value for Snowflake Claude model: " + f"{tool_choice!r}. Expected one of: auto, required, none." + ) + return mapping[tool_choice] elif isinstance(tool_choice, dict): if tool_choice.get("type") == "function": func: Final = tool_choice.get("function", {}) diff --git a/tests/test_litellm/llms/snowflake/chat/test_snowflake_chat_transformation.py b/tests/test_litellm/llms/snowflake/chat/test_snowflake_chat_transformation.py index a182656e4a8..0bb4a72d709 100644 --- a/tests/test_litellm/llms/snowflake/chat/test_snowflake_chat_transformation.py +++ b/tests/test_litellm/llms/snowflake/chat/test_snowflake_chat_transformation.py @@ -118,6 +118,21 @@ class TestSnowflakeToolTransformation: f"got {transformed_request['tool_choice']}" ) + def test_claude_rejects_invalid_string_tool_choice(self): + """ + Test that invalid string tool_choice values are not silently downgraded to auto. + """ + config = SnowflakeConfig() + + with pytest.raises(ValueError, match="Unsupported tool_choice value"): + config.transform_request( + model="snowflake/claude-sonnet-4-5", + messages=[{"role": "user", "content": "Test"}], + optional_params={"tool_choice": "requried"}, + litellm_params={}, + headers={}, + ) + def test_transform_response_with_tool_calls(self): """ Test that standard OpenAI tool_calls response format is parsed correctly.