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

This commit is contained in:
mateo-berri 2026-09-15 07:00:33 -07:00
parent 76488beaf8
commit 2bbf34c652
2 changed files with 9 additions and 1 deletions

View file

@ -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.

View file

@ -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 == ""