From 7c2e2111c0cc3372ca0ce911d0b6d45c22794d7f Mon Sep 17 00:00:00 2001 From: Cesar Garcia <128240629+Chesars@users.noreply.github.com> Date: Mon, 8 Dec 2025 23:36:46 -0300 Subject: [PATCH] fix(router): handle tools=None in filter_web_search_deployments (#17684) Fixes #17672 Changed `request_kwargs.get("tools", [])` to `request_kwargs.get("tools") or []` to handle the case where tools is explicitly set to None. --- litellm/router_utils/common_utils.py | 2 +- .../router_utils/test_router_utils_common_utils.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/litellm/router_utils/common_utils.py b/litellm/router_utils/common_utils.py index 15725e30d04..10acc343abd 100644 --- a/litellm/router_utils/common_utils.py +++ b/litellm/router_utils/common_utils.py @@ -110,7 +110,7 @@ def filter_web_search_deployments( return healthy_deployments is_web_search_request = False - tools = request_kwargs.get("tools", []) + tools = request_kwargs.get("tools") or [] for tool in tools: # These are the two websearch tools for OpenAI / Azure. if tool.get("type") == "web_search" or tool.get("type") == "web_search_preview": diff --git a/tests/test_litellm/router_utils/test_router_utils_common_utils.py b/tests/test_litellm/router_utils/test_router_utils_common_utils.py index f73609d47ba..8ff1ba45cc2 100644 --- a/tests/test_litellm/router_utils/test_router_utils_common_utils.py +++ b/tests/test_litellm/router_utils/test_router_utils_common_utils.py @@ -248,6 +248,11 @@ class TestFilterWebSearchDeployments: result = filter_web_search_deployments(sample_deployments, {"tools": []}) assert result == sample_deployments + def test_none_tools_returns_all(self, sample_deployments): + """When tools is explicitly None, return all deployments (regression test for #17672)""" + result = filter_web_search_deployments(sample_deployments, {"tools": None}) + assert result == sample_deployments + def test_non_web_search_tools_returns_all(self, sample_deployments): """When tools don't include web_search, return all deployments""" request_kwargs = {"tools": [{"type": "function", "function": {}}]}