diff --git a/litellm/integrations/websearch_interception/handler.py b/litellm/integrations/websearch_interception/handler.py index 6a4929a6b22..cf46f5827f0 100644 --- a/litellm/integrations/websearch_interception/handler.py +++ b/litellm/integrations/websearch_interception/handler.py @@ -303,8 +303,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 2616a81ce96..81d3aa0b26f 100644 --- a/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py +++ b/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py @@ -417,6 +417,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(