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]

fix(utils): keep the tool_choice validator's model argument optional

mateo-berri2bbf34c6520e
diff --git a/litellm/utils.py b/litellm/utils.py
index 17088f0475b..c2dbbda2b68 100644
--- a/litellm/utils.py
+++ b/litellm/utils.py
@@ -8038,7 +8038,7 @@ def validate_chat_completion_user_messages(messages: list[AllMessageValues]):
def validate_chat_completion_tool_choice(
tool_choice: dict | str | None,
- model: str,
+ model: str = "",
) -> dict | str | None:
"""
Confirm the tool choice is passed in the OpenAI format.
diff --git a/tests/litellm_utils_tests/test_validate_tool_choice.py b/tests/litellm_utils_tests/test_validate_tool_choice.py
index b4272af7b90..a9dacf9fa15 100644
--- a/tests/litellm_utils_tests/test_validate_tool_choice.py
+++ b/tests/litellm_utils_tests/test_validate_tool_choice.py
@@ -64,3 +64,11 @@ def test_validate_tool_choice_invalid_type_is_a_400(tool_choice):
) as exc_info:
validate_chat_completion_tool_choice(tool_choice, model=MODEL)
assert exc_info.value.status_code == 400
+
+
+def test_validate_tool_choice_without_model_is_still_a_400():
+ """Callers that predate the model argument keep getting a 400, with an empty model on the error."""
+ with pytest.raises(litellm.BadRequestError, match="Invalid tool choice") as exc_info:
+ validate_chat_completion_tool_choice({"type": "bogus"})
+ assert exc_info.value.status_code == 400
+ assert exc_info.value.model == ""