From d2831ab70901de885e57a084581b916c86a56bf6 Mon Sep 17 00:00:00 2001 From: ege-arhan Date: Fri, 25 Sep 2026 06:04:11 +0000 Subject: [PATCH 1/4] fix(utils): pass allowed_tools tool_choice through to providers Chat completions rejected the allowed_tools shape before it reached the provider, even though OpenAI accepts it. Keep the nested payload intact. --- litellm/utils.py | 6 ++++++ .../test_validate_tool_choice.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/litellm/utils.py b/litellm/utils.py index 4ea0769ea11..b751b9c0e1d 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -8328,6 +8328,12 @@ def validate_chat_completion_tool_choice( if tool_choice_type in ("auto", "none", "required") and "function" not in tool_choice: return tool_choice_type + # OpenAI also allows constraining which tools the model may call: + # {"type": "allowed_tools", "allowed_tools": {"mode": ..., "tools": [...]}}. + # Pass it through untouched so downstream providers see the full payload. + if tool_choice_type == "allowed_tools" and isinstance(tool_choice.get("allowed_tools"), dict): + return tool_choice + # Standard OpenAI format: {"type": "function", "function": {...}} if tool_choice.get("type") is None or tool_choice.get("function") is None: raise BadRequestError( diff --git a/tests/litellm_utils_tests/test_validate_tool_choice.py b/tests/litellm_utils_tests/test_validate_tool_choice.py index a9dacf9fa15..a28aee87c48 100644 --- a/tests/litellm_utils_tests/test_validate_tool_choice.py +++ b/tests/litellm_utils_tests/test_validate_tool_choice.py @@ -36,6 +36,25 @@ def test_validate_tool_choice_cursor_format(): assert validate_chat_completion_tool_choice({"type": "required"}, model=MODEL) == "required" +def test_validate_tool_choice_allowed_tools_passthrough(): + """Chat completions accepts the allowed_tools shape and keeps its payload intact.""" + tool_choice = { + "type": "allowed_tools", + "allowed_tools": { + "mode": "required", + "tools": [{"type": "function", "function": {"name": "get_time"}}], + }, + } + assert validate_chat_completion_tool_choice(tool_choice, model=MODEL) is tool_choice + + +def test_validate_tool_choice_allowed_tools_without_payload_is_a_400(): + """allowed_tools without its nested object stays a caller error.""" + tool_choice = {"type": "allowed_tools"} + with pytest.raises(litellm.BadRequestError, match="Invalid tool choice"): + validate_chat_completion_tool_choice(tool_choice, model=MODEL) + + @pytest.mark.parametrize( "tool_choice", [ From 25d675330cc178cde9a0325b461afa33c824ad05 Mon Sep 17 00:00:00 2001 From: ege-arhan Date: Thu, 22 Oct 2026 15:31:25 +0000 Subject: [PATCH 2/4] fix(utils): silence basedpyright noise on allowed_tools guard --- litellm/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index 37f8aecf631..36f3fcd637a 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -9055,7 +9055,10 @@ def validate_chat_completion_tool_choice( # OpenAI also allows constraining which tools the model may call: # {"type": "allowed_tools", "allowed_tools": {"mode": ..., "tools": [...]}}. # Pass it through untouched so downstream providers see the full payload. - if tool_choice_type == "allowed_tools" and isinstance(tool_choice.get("allowed_tools"), dict): + if tool_choice_type == "allowed_tools" and isinstance( + tool_choice.get("allowed_tools"), # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] + dict, + ): return tool_choice # Standard OpenAI format: {"type": "function", "function": {...}} From 8f3a0894c2b8d21a517a8d8ea8141b9bc905920e Mon Sep 17 00:00:00 2001 From: ege-arhan Date: Thu, 22 Oct 2026 17:31:01 +0000 Subject: [PATCH 3/4] fix(utils): add reason to pyright ignore for allowed_tools guard --- litellm/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index 36f3fcd637a..f863d7c285e 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -9056,7 +9056,7 @@ def validate_chat_completion_tool_choice( # {"type": "allowed_tools", "allowed_tools": {"mode": ..., "tools": [...]}}. # Pass it through untouched so downstream providers see the full payload. if tool_choice_type == "allowed_tools" and isinstance( - tool_choice.get("allowed_tools"), # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] + tool_choice.get("allowed_tools"), # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] # raw dict payload dict, ): return tool_choice From 512df37a9721bfdd9d24058b8537849a40f67eb2 Mon Sep 17 00:00:00 2001 From: ege-arhan Date: Thu, 22 Oct 2026 18:27:37 +0000 Subject: [PATCH 4/4] fix(utils): narrow pyright ignore to the flagged line in allowed_tools guard --- litellm/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index f863d7c285e..9b9fb07fb7c 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -9059,7 +9059,7 @@ def validate_chat_completion_tool_choice( tool_choice.get("allowed_tools"), # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] # raw dict payload dict, ): - return tool_choice + return tool_choice # pyright: ignore[reportUnknownVariableType] # narrowed raw dict payload # Standard OpenAI format: {"type": "function", "function": {...}} if tool_choice.get("type") is None or tool_choice.get("function") is None: