From 9fe0819e778205471623de56218ae4293aef8df6 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Sat, 31 Jan 2026 11:21:40 -0800 Subject: [PATCH] _add_web_search_tool --- .../litellm_responses_transformation/transformation.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/litellm/completion_extras/litellm_responses_transformation/transformation.py b/litellm/completion_extras/litellm_responses_transformation/transformation.py index 44006f79fe3..57bd05124aa 100644 --- a/litellm/completion_extras/litellm_responses_transformation/transformation.py +++ b/litellm/completion_extras/litellm_responses_transformation/transformation.py @@ -744,13 +744,18 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge): if "tools" not in responses_api_request or responses_api_request["tools"] is None: responses_api_request["tools"] = [] + # Get the tools list with proper type narrowing + tools = responses_api_request["tools"] + if tools is None: + tools = [] + responses_api_request["tools"] = tools + web_search_tool: Dict[str, Any] = {"type": "web_search"} if isinstance(web_search_options, dict): web_search_tool.update(web_search_options) - # After the check above, tools is guaranteed to be a list # Cast to Any to match the expected union type for tools list items - responses_api_request["tools"].append(cast(Any, web_search_tool)) + tools.append(cast(Any, web_search_tool)) def _transform_response_format_to_text_format( self, response_format: Union[Dict[str, Any], Any]