From 9597d3cabdbd973bf6eebfb0bb088fd74404723f Mon Sep 17 00:00:00 2001 From: agustin18 Date: Sun, 27 Sep 2026 19:14:50 +0000 Subject: [PATCH 1/6] fix(websearch): strip Claude Code instructional prefix in short-circuit search Signed-off-by: agustin18 --- .../websearch_interception/handler.py | 26 ++++++++- .../test_websearch_short_circuit.py | 57 +++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/litellm/integrations/websearch_interception/handler.py b/litellm/integrations/websearch_interception/handler.py index a38b8bed595..86f82a2af48 100644 --- a/litellm/integrations/websearch_interception/handler.py +++ b/litellm/integrations/websearch_interception/handler.py @@ -8,6 +8,7 @@ server-side using litellm router's search tools. import asyncio import math +import re import uuid from collections.abc import AsyncIterator, Mapping, Sequence from dataclasses import dataclass @@ -97,6 +98,11 @@ WEBSEARCH_NATIVE_BLOCKS_METADATA_KEY: Final = "websearch_native_blocks" _RESPONSE_CONTENT_FIELD: Final = "content" +_CLAUDE_CODE_SEARCH_PREFIX_RE: Final = re.compile( + r"^\s*(?:Perform\s+a\s+)?(?:web\s+)?search\s+for\s+(?:the\s+)?query:\s*", + re.IGNORECASE, +) + _ResponseT: Final = TypeVar("_ResponseT") @@ -293,6 +299,20 @@ class WebSearchInterceptionLogger(CustomLogger): """ return validated_max_agentic_loops(max_agentic_loops, field="websearch_interception_params.max_agentic_loops") + @classmethod + def _extract_short_circuit_query(cls, raw_message: str) -> str: + """Extract the intended search terms from a short-circuit user message. + + Clients such as Claude Code format standalone WebSearch requests with an + instructional wrapper (e.g. 'Perform a web search for the query: '). + Strip known instructional prefixes so the search backend receives only + the intended search terms rather than query wrapper keywords. + """ + cleaned = _CLAUDE_CODE_SEARCH_PREFIX_RE.sub("", raw_message).strip() + if (cleaned.startswith('"') and cleaned.endswith('"')) or (cleaned.startswith("'") and cleaned.endswith("'")): + cleaned = cleaned[1:-1].strip() + return cleaned if cleaned else raw_message.strip() + async def try_short_circuit_search( self, model: str, @@ -363,7 +383,11 @@ class WebSearchInterceptionLogger(CustomLogger): get_last_user_message, ) - query: Final = get_last_user_message(cast(list[AllMessageValues], messages)) + raw_query: Final = get_last_user_message(cast(list[AllMessageValues], messages)) + if not raw_query: + return None + + query: Final = self._extract_short_circuit_query(raw_query) if not query: return None diff --git a/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py b/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py index 4f707856fc9..8991d2a12fd 100644 --- a/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py +++ b/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py @@ -394,6 +394,63 @@ class TestShortCircuitEntryPoint: text_block = next(b for b in result["content"] if b["type"] == "text") assert text_block["text"] == "results" + @pytest.mark.asyncio + @pytest.mark.parametrize( + "raw_prompt,expected_query", + [ + ( + "Perform a web search for the query: LiteLLM latest version release", + "LiteLLM latest version release", + ), + ( + 'Perform a web search for the query: "who is the maintainer of litellm"', + "who is the maintainer of litellm", + ), + ( + " perform a web search for the query: fastapi SSE streaming ", + "fastapi SSE streaming", + ), + ( + "Search for the query: python 3.13 changelog", + "python 3.13 changelog", + ), + ( + "Search for Claude Code releases", + "Search for Claude Code releases", + ), + ], + ) + async def test_short_circuits_strips_claude_code_instructional_prefix( + self, raw_prompt, expected_query + ): + """Claude Code wraps standalone searches in 'Perform a web search for the query: ...'. + The short-circuit path must extract only the actual query terms so search backends + receive the intended query rather than instructional prefix words. + """ + logger = WebSearchInterceptionLogger(enabled_providers=["github_copilot"]) + + with patch.object( + logger, "_execute_search", new_callable=AsyncMock + ) as mock_search: + mock_search.return_value = ("Results", None) + + result = await logger.try_short_circuit_search( + model="github_copilot/claude-sonnet-4", + messages=[{"role": "user", "content": raw_prompt}], + tools=[ + {"type": "web_search_20250305", "name": "web_search", "max_uses": 8} + ], + custom_llm_provider="github_copilot", + ) + + assert result is not None + mock_search.assert_called_once_with(expected_query) + tool_use_block = next( + (b for b in result["content"] if b["type"] == "server_tool_use"), None + ) + if tool_use_block is not None: + assert tool_use_block["input"]["query"] == expected_query + class TestShortCircuitSafeguardResults: """A short-circuited reply never reaches the backend, so the proxy answers Claude Code's safeguards itself.""" From b39ab6610bbf52d8b7fbd9a513bb6c4fb370d2c5 Mon Sep 17 00:00:00 2001 From: agustin18 Date: Sun, 27 Sep 2026 19:22:14 +0000 Subject: [PATCH 2/6] fix(websearch): preserve quotes for unwrapped search queries Signed-off-by: agustin18 --- litellm/integrations/websearch_interception/handler.py | 7 +++++-- .../test_websearch_short_circuit.py | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/litellm/integrations/websearch_interception/handler.py b/litellm/integrations/websearch_interception/handler.py index 86f82a2af48..47b6395639d 100644 --- a/litellm/integrations/websearch_interception/handler.py +++ b/litellm/integrations/websearch_interception/handler.py @@ -308,8 +308,11 @@ class WebSearchInterceptionLogger(CustomLogger): Strip known instructional prefixes so the search backend receives only the intended search terms rather than query wrapper keywords. """ - cleaned = _CLAUDE_CODE_SEARCH_PREFIX_RE.sub("", raw_message).strip() - if (cleaned.startswith('"') and cleaned.endswith('"')) or (cleaned.startswith("'") and cleaned.endswith("'")): + prefix = _CLAUDE_CODE_SEARCH_PREFIX_RE.match(raw_message) + cleaned = (raw_message[prefix.end() :] if prefix else raw_message).strip() + if prefix and ( + (cleaned.startswith('"') and cleaned.endswith('"')) or (cleaned.startswith("'") and cleaned.endswith("'")) + ): cleaned = cleaned[1:-1].strip() return cleaned if cleaned else raw_message.strip() diff --git a/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py b/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py index 8991d2a12fd..d1fd52f3b5c 100644 --- a/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py +++ b/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py @@ -418,6 +418,14 @@ class TestShortCircuitEntryPoint: "Search for Claude Code releases", "Search for Claude Code releases", ), + ( + '"LiteLLM latest version release"', + '"LiteLLM latest version release"', + ), + ( + "'fastapi SSE streaming'", + "'fastapi SSE streaming'", + ), ], ) async def test_short_circuits_strips_claude_code_instructional_prefix( From 8c67048b8791ec895fbda005e2bbd4a5444879c9 Mon Sep 17 00:00:00 2001 From: agustin18 Date: Sun, 27 Sep 2026 19:33:24 +0000 Subject: [PATCH 3/6] test(websearch): replace mock with pure unit tests and cover empty queries Signed-off-by: agustin18 --- .../websearch_interception/handler.py | 3 +- .../test_websearch_short_circuit.py | 198 +++++++++--------- 2 files changed, 99 insertions(+), 102 deletions(-) diff --git a/litellm/integrations/websearch_interception/handler.py b/litellm/integrations/websearch_interception/handler.py index 47b6395639d..899d7301e7f 100644 --- a/litellm/integrations/websearch_interception/handler.py +++ b/litellm/integrations/websearch_interception/handler.py @@ -314,7 +314,8 @@ class WebSearchInterceptionLogger(CustomLogger): (cleaned.startswith('"') and cleaned.endswith('"')) or (cleaned.startswith("'") and cleaned.endswith("'")) ): cleaned = cleaned[1:-1].strip() - return cleaned if cleaned else raw_message.strip() + return cleaned if (cleaned or prefix) else raw_message.strip() + async def try_short_circuit_search( self, diff --git a/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py b/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py index d1fd52f3b5c..eb4159c45ea 100644 --- a/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py +++ b/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py @@ -27,9 +27,7 @@ class TestTryShortCircuitSearch: """Single web_search_20250305 tool → short-circuit fires""" logger = WebSearchInterceptionLogger(enabled_providers=["github_copilot"]) - with patch.object( - logger, "_execute_search", new_callable=AsyncMock - ) as mock_search: + with patch.object(logger, "_execute_search", new_callable=AsyncMock) as mock_search: mock_search.return_value = ( "Title: Result\nURL: https://example.com\nSnippet: test", None, @@ -114,9 +112,7 @@ class TestTryShortCircuitSearch: result = await logger.try_short_circuit_search( model="github_copilot/claude-sonnet-5.5", messages=[{"role": "user", "content": "Search for something"}], - tools=[ - {"type": "web_search_20250305", "name": "web_search", "max_uses": 8} - ], + tools=[{"type": "web_search_20250305", "name": "web_search", "max_uses": 8}], custom_llm_provider="github_copilot", ) @@ -130,16 +126,12 @@ class TestTryShortCircuitSearch: use the agentic loop which includes a follow-up LLM synthesis step. The short-circuit must not fire for them. """ - logger = WebSearchInterceptionLogger( - enabled_providers=["bedrock", "github_copilot"] - ) + logger = WebSearchInterceptionLogger(enabled_providers=["bedrock", "github_copilot"]) result = await logger.try_short_circuit_search( model="bedrock/us.anthropic.claude-sonnet-4-5-20250929-v1:0", messages=[{"role": "user", "content": "Search for something"}], - tools=[ - {"type": "web_search_20250305", "name": "web_search", "max_uses": 8} - ], + tools=[{"type": "web_search_20250305", "name": "web_search", "max_uses": 8}], custom_llm_provider="bedrock", ) @@ -153,30 +145,49 @@ class TestTryShortCircuitSearch: result = await logger.try_short_circuit_search( model="github_copilot/claude-sonnet-5.5", messages=[], - tools=[ - {"type": "web_search_20250305", "name": "web_search", "max_uses": 8} - ], + tools=[{"type": "web_search_20250305", "name": "web_search", "max_uses": 8}], custom_llm_provider="github_copilot", ) assert result is None + @pytest.mark.asyncio + @pytest.mark.parametrize( + "empty_prompt", + [ + " ", + "Perform a web search for the query: ", + 'Perform a web search for the query: ""', + ], + ) + async def test_does_not_short_circuit_empty_or_whitespace_user_message( + self, empty_prompt: str + ): + """User message that is whitespace or empty query → returns None without executing search.""" + logger = WebSearchInterceptionLogger(enabled_providers=["github_copilot"]) + + result = await logger.try_short_circuit_search( + model="github_copilot/claude-sonnet-4", + messages=[{"role": "user", "content": empty_prompt}], + tools=[{"type": "web_search_20250305", "name": "web_search", "max_uses": 8}], + custom_llm_provider="github_copilot", + ) + + assert result is None + + @pytest.mark.asyncio async def test_search_failure_returns_error_text(self): """Search failure → response with error message, not exception""" logger = WebSearchInterceptionLogger(enabled_providers=["github_copilot"]) - with patch.object( - logger, "_execute_search", new_callable=AsyncMock - ) as mock_search: + with patch.object(logger, "_execute_search", new_callable=AsyncMock) as mock_search: mock_search.side_effect = RuntimeError("Tavily API error") result = await logger.try_short_circuit_search( model="github_copilot/claude-sonnet-5.5", messages=[{"role": "user", "content": "Search for something"}], - tools=[ - {"type": "web_search_20250305", "name": "web_search", "max_uses": 8} - ], + tools=[{"type": "web_search_20250305", "name": "web_search", "max_uses": 8}], custom_llm_provider="github_copilot", ) @@ -189,9 +200,7 @@ class TestTryShortCircuitSearch: """Synthetic response has all required AnthropicMessagesResponse fields""" logger = WebSearchInterceptionLogger(enabled_providers=["github_copilot"]) - with patch.object( - logger, "_execute_search", new_callable=AsyncMock - ) as mock_search: + with patch.object(logger, "_execute_search", new_callable=AsyncMock) as mock_search: mock_search.return_value = ("search results here", None) result = await logger.try_short_circuit_search( @@ -219,6 +228,66 @@ class TestTryShortCircuitSearch: # --------------------------------------------------------------------------- +class TestQueryExtraction: + """Direct unit tests for query extraction without application test doubles.""" + + @pytest.mark.parametrize( + "raw_prompt,expected_query", + [ + ( + "Perform a web search for the query: LiteLLM latest version release", + "LiteLLM latest version release", + ), + ( + 'Perform a web search for the query: "who is the maintainer of litellm"', + "who is the maintainer of litellm", + ), + ( + " perform a web search for the query: fastapi SSE streaming ", + "fastapi SSE streaming", + ), + ( + "Search for the query: python 3.13 changelog", + "python 3.13 changelog", + ), + ( + "web search for query: litellm", + "litellm", + ), + ( + "Search for Claude Code releases", + "Search for Claude Code releases", + ), + ( + '"LiteLLM latest version release"', + '"LiteLLM latest version release"', + ), + ( + "'fastapi SSE streaming'", + "'fastapi SSE streaming'", + ), + ( + "Perform a web search for the query: ", + "", + ), + ( + 'Perform a web search for the query: ""', + "", + ), + ( + "", + "", + ), + ], + ) + def test_extract_short_circuit_query_strips_claude_code_prefix(self, raw_prompt: str, expected_query: str): + """Claude Code wraps standalone searches in 'Perform a web search for the query: ...'. + _extract_short_circuit_query must extract only the actual query terms and preserve + exact-phrase quotes when no wrapper was present, without application doubles. + """ + assert WebSearchInterceptionLogger._extract_short_circuit_query(raw_prompt) == expected_query + + # --------------------------------------------------------------------------- # Integration with entry point # --------------------------------------------------------------------------- @@ -252,9 +321,7 @@ class TestShortCircuitEntryPoint: ) logger = WebSearchInterceptionLogger(enabled_providers=["github_copilot"]) - with patch.object( - logger, "_execute_search", new_callable=AsyncMock - ) as mock_search: + with patch.object(logger, "_execute_search", new_callable=AsyncMock) as mock_search: mock_search.return_value = ("results", None) with patch("litellm.callbacks", [logger]): result = await _try_websearch_short_circuit( @@ -280,9 +347,7 @@ class TestShortCircuitEntryPoint: ) logger = WebSearchInterceptionLogger(enabled_providers=["github_copilot"]) - with patch.object( - logger, "_execute_search", new_callable=AsyncMock - ) as mock_search: + with patch.object(logger, "_execute_search", new_callable=AsyncMock) as mock_search: mock_search.return_value = ("streaming results", None) with patch("litellm.callbacks", [logger]): result = await _try_websearch_short_circuit( @@ -345,9 +410,7 @@ class TestShortCircuitEntryPoint: ) logger = WebSearchInterceptionLogger(enabled_providers=["github_copilot"]) - with patch.object( - logger, "_execute_search", new_callable=AsyncMock - ) as mock_search: + with patch.object(logger, "_execute_search", new_callable=AsyncMock) as mock_search: mock_search.return_value = ("streaming results", None) with patch("litellm.callbacks", [logger]): # Simulate what anthropic_messages() does: original_stream=True @@ -375,9 +438,7 @@ class TestShortCircuitEntryPoint: ) logger = WebSearchInterceptionLogger(enabled_providers=["github_copilot"]) - with patch.object( - logger, "_execute_search", new_callable=AsyncMock - ) as mock_search: + with patch.object(logger, "_execute_search", new_callable=AsyncMock) as mock_search: mock_search.return_value = ("results", None) with patch("litellm.callbacks", [logger]): # Simulate the caller having derived custom_llm_provider from @@ -394,71 +455,6 @@ class TestShortCircuitEntryPoint: text_block = next(b for b in result["content"] if b["type"] == "text") assert text_block["text"] == "results" - @pytest.mark.asyncio - @pytest.mark.parametrize( - "raw_prompt,expected_query", - [ - ( - "Perform a web search for the query: LiteLLM latest version release", - "LiteLLM latest version release", - ), - ( - 'Perform a web search for the query: "who is the maintainer of litellm"', - "who is the maintainer of litellm", - ), - ( - " perform a web search for the query: fastapi SSE streaming ", - "fastapi SSE streaming", - ), - ( - "Search for the query: python 3.13 changelog", - "python 3.13 changelog", - ), - ( - "Search for Claude Code releases", - "Search for Claude Code releases", - ), - ( - '"LiteLLM latest version release"', - '"LiteLLM latest version release"', - ), - ( - "'fastapi SSE streaming'", - "'fastapi SSE streaming'", - ), - ], - ) - async def test_short_circuits_strips_claude_code_instructional_prefix( - self, raw_prompt, expected_query - ): - """Claude Code wraps standalone searches in 'Perform a web search for the query: ...'. - The short-circuit path must extract only the actual query terms so search backends - receive the intended query rather than instructional prefix words. - """ - logger = WebSearchInterceptionLogger(enabled_providers=["github_copilot"]) - - with patch.object( - logger, "_execute_search", new_callable=AsyncMock - ) as mock_search: - mock_search.return_value = ("Results", None) - - result = await logger.try_short_circuit_search( - model="github_copilot/claude-sonnet-4", - messages=[{"role": "user", "content": raw_prompt}], - tools=[ - {"type": "web_search_20250305", "name": "web_search", "max_uses": 8} - ], - custom_llm_provider="github_copilot", - ) - - assert result is not None - mock_search.assert_called_once_with(expected_query) - tool_use_block = next( - (b for b in result["content"] if b["type"] == "server_tool_use"), None - ) - if tool_use_block is not None: - assert tool_use_block["input"]["query"] == expected_query - class TestShortCircuitSafeguardResults: """A short-circuited reply never reaches the backend, so the proxy answers Claude Code's safeguards itself.""" From 0034cf73ca8ab6867a852981306d7ce345ccd216 Mon Sep 17 00:00:00 2001 From: agustin18 Date: Sun, 27 Sep 2026 19:38:26 +0000 Subject: [PATCH 4/6] style(websearch): fix ruff formatting blank line in handler Signed-off-by: agustin18 --- litellm/integrations/websearch_interception/handler.py | 1 - 1 file changed, 1 deletion(-) diff --git a/litellm/integrations/websearch_interception/handler.py b/litellm/integrations/websearch_interception/handler.py index 899d7301e7f..b59b29de0cf 100644 --- a/litellm/integrations/websearch_interception/handler.py +++ b/litellm/integrations/websearch_interception/handler.py @@ -316,7 +316,6 @@ class WebSearchInterceptionLogger(CustomLogger): cleaned = cleaned[1:-1].strip() return cleaned if (cleaned or prefix) else raw_message.strip() - async def try_short_circuit_search( self, model: str, From e3ffd7786e156031250c903e368241f296c112f5 Mon Sep 17 00:00:00 2001 From: agustin18 Date: Sun, 27 Sep 2026 19:57:45 +0000 Subject: [PATCH 5/6] refactor(websearch): enforce Final annotations, prevent rebinding, and retain e2e coverage Signed-off-by: agustin18 --- .../websearch_interception/handler.py | 16 ++++--- .../test_websearch_short_circuit.py | 43 +++++++++++++++++-- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/litellm/integrations/websearch_interception/handler.py b/litellm/integrations/websearch_interception/handler.py index b59b29de0cf..1dcca27d30d 100644 --- a/litellm/integrations/websearch_interception/handler.py +++ b/litellm/integrations/websearch_interception/handler.py @@ -308,13 +308,17 @@ class WebSearchInterceptionLogger(CustomLogger): Strip known instructional prefixes so the search backend receives only the intended search terms rather than query wrapper keywords. """ - prefix = _CLAUDE_CODE_SEARCH_PREFIX_RE.match(raw_message) - cleaned = (raw_message[prefix.end() :] if prefix else raw_message).strip() - if prefix and ( - (cleaned.startswith('"') and cleaned.endswith('"')) or (cleaned.startswith("'") and cleaned.endswith("'")) + prefix_match: Final[re.Match[str] | None] = _CLAUDE_CODE_SEARCH_PREFIX_RE.match(raw_message) + stripped_prefix: Final[str] = ( + raw_message[prefix_match.end() :].strip() if prefix_match is not None else raw_message.strip() + ) + if prefix_match is not None and ( + (stripped_prefix.startswith('"') and stripped_prefix.endswith('"')) + or (stripped_prefix.startswith("'") and stripped_prefix.endswith("'")) ): - cleaned = cleaned[1:-1].strip() - return cleaned if (cleaned or prefix) else raw_message.strip() + return stripped_prefix[1:-1].strip() + + return stripped_prefix if (stripped_prefix or prefix_match is not None) else raw_message.strip() async def try_short_circuit_search( self, diff --git a/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py b/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py index eb4159c45ea..928178801bc 100644 --- a/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py +++ b/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py @@ -160,9 +160,7 @@ class TestTryShortCircuitSearch: 'Perform a web search for the query: ""', ], ) - async def test_does_not_short_circuit_empty_or_whitespace_user_message( - self, empty_prompt: str - ): + async def test_does_not_short_circuit_empty_or_whitespace_user_message(self, empty_prompt: str): """User message that is whitespace or empty query → returns None without executing search.""" logger = WebSearchInterceptionLogger(enabled_providers=["github_copilot"]) @@ -175,7 +173,6 @@ class TestTryShortCircuitSearch: assert result is None - @pytest.mark.asyncio async def test_search_failure_returns_error_text(self): """Search failure → response with error message, not exception""" @@ -455,6 +452,44 @@ class TestShortCircuitEntryPoint: text_block = next(b for b in result["content"] if b["type"] == "text") assert text_block["text"] == "results" + @pytest.mark.asyncio + @pytest.mark.parametrize( + "raw_prompt,expected_query", + [ + ( + "Perform a web search for the query: LiteLLM latest version release", + "LiteLLM latest version release", + ), + ( + 'Perform a web search for the query: "who is the maintainer of litellm"', + "who is the maintainer of litellm", + ), + ( + '"LiteLLM latest version release"', + '"LiteLLM latest version release"', + ), + ], + ) + async def test_short_circuits_strips_claude_code_instructional_prefix(self, raw_prompt: str, expected_query: str): + """Verify end-to-end that try_short_circuit_search forwards the cleaned query to search.""" + logger = WebSearchInterceptionLogger(enabled_providers=["github_copilot"]) + + with patch.object(logger, "_execute_search", new_callable=AsyncMock) as mock_search: + mock_search.return_value = ("Results", None) + + result = await logger.try_short_circuit_search( + model="github_copilot/claude-sonnet-4", + messages=[{"role": "user", "content": raw_prompt}], + tools=[{"type": "web_search_20250305", "name": "web_search", "max_uses": 8}], + custom_llm_provider="github_copilot", + ) + + assert result is not None + mock_search.assert_called_once_with(expected_query) + tool_use_block = next((b for b in result["content"] if b["type"] == "server_tool_use"), None) + if tool_use_block is not None: + assert tool_use_block["input"]["query"] == expected_query + class TestShortCircuitSafeguardResults: """A short-circuited reply never reaches the backend, so the proxy answers Claude Code's safeguards itself.""" From d45cf5d6a17a5162983055c5b9349771a7e5c05d Mon Sep 17 00:00:00 2001 From: agustin18 Date: Sun, 27 Sep 2026 20:56:07 +0000 Subject: [PATCH 6/6] test(websearch): assert server_tool_use block unconditionally Signed-off-by: agustin18 --- .../websearch_interception/test_websearch_short_circuit.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py b/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py index 928178801bc..e24e248d963 100644 --- a/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py +++ b/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py @@ -486,9 +486,8 @@ class TestShortCircuitEntryPoint: assert result is not None mock_search.assert_called_once_with(expected_query) - tool_use_block = next((b for b in result["content"] if b["type"] == "server_tool_use"), None) - if tool_use_block is not None: - assert tool_use_block["input"]["query"] == expected_query + tool_use_block = next(b for b in result["content"] if b["type"] == "server_tool_use") + assert tool_use_block["input"]["query"] == expected_query class TestShortCircuitSafeguardResults: