Repository navigation
fix(guardrails): show the /v1/messages web search tool to guardrails - #53376
Conversation
[Medium impact] The PR appears safe to merge, with no new actionable issues found.
|
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d3be73d. Configure here.
PR overviewNo security issues were found in this pull request. Reviews
|
There was a problem hiding this comment.
Devin Review found 1 potential issue.
3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
…erriAI#53376) * fix(guardrails): show the /v1/messages web search tool to guardrails * fix(guardrails): send a returned web search tool on as the guardrail returned it (cherry picked from commit 4c62c9a)

Handwritten 1-3 sentence description
[insert handwritten description here]
Details
TLDR
Problem this solves:
/v1/messagesnever see Anthropic'sweb_searchtoolHow it solves it:
web_searchto guardrails as sent, in its request positionweb_fetch,bashand other hosted tools already areIntentional product change: guardrails that return tools now decide whether
web_searchreaches the provider. A guardrail that allow-lists tools by name must listweb_searchto keep it.User Flow
Before: a team that guards tools with a guardrail cannot control web search
[Read, web_search_20250305]behind a guardrail that returns toolsReadRead, whatever the guardrail answered, and the model says it cannot searchAfter: the guardrail sees web search and its answer decides
Readandweb_search_20250305web_searchout, the provider receives onlyReadLinear ticket
Relates to LIT-10590
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreScreenshots / Proof of Fix
Two live proxies on one VM, 2 workers each, own Postgres and Redis, real provider calls. A forwarding recorder in front of each provider captured what the proxy sent. Every request is
POST /v1/messageswith tools[Read, web_search_20250305]unless the cell says otherwise.Setup to rerun: config.yaml, start command, request
config.yaml(the opt-in runs swap theguardrailsblock for custom-code guardrails that allow all, mask theReaddescription, or return tools withoutRead):Env:
OPENAI_API_KEY,AWS_BEARER_TOKEN_BEDROCK,DATABASE_URL. Start:litellm --config config.yaml --port 4000 --num_workers 2The same request with
"model": "claude-bedrock-invoke"is the Bedrock cell. In the runs below eachapi_basepointed at a local recorder that logged the request and forwarded it to the real provider.Before (1fa7e4a)
gpt: 200, text3.13.0, an answer from memory. OpenAI received tools[Read]claude-bedrock-invoke: 200, "I don't have access to a web search tool". Bedrock received tools[Read]After (7973ad5)
gpt: 200, text3.15.2, a searched answer. OpenAI received tools[Read, web_search_preview]claude-bedrock-invoke: 400 "Bedrock does not support Anthropic's server-side web search tool (tool type 'web_search_20250305' ...). To use web search with this model, enable LiteLLM's web search interception". No provider callAll cells
Readdescription, or dropRead; a guardrail that returnstools: []/v1/messages,/v1/chat/completions,/v1/responses, streaming and not, Bedrock Invoke, Bedrock Converse, OpenAI, direct Anthropic[Read][Read, web_search][Read][Read, web_search_preview][Read][Read][Read, web_search][Read][Read, web_search_preview][Read][Read][Read, web_search_preview][Read][Read, web_search_preview][][web_search_preview]tools: []: the provider got no tools on both legs, for OpenAI and for Bedrock (200 both)/v1/messagesto an OpenAI model behind the content filter: web search forwarded on 0 of 8 before, 8 of 8 after; 40 x 200 with exactly one provider call each on both legsTests
tests/unit/llms/anthropic/chat/guardrail_translation/test_anthropic_guardrail_handler.py, including the legacy{"name": "web_search"}shape. Five fail at the merge base and all pass at the tiptests/unit/llms/anthropic,base_llm,bedrockandproxy/guardrails, 16930 passed; three/v1/messagesguardrail integration files, 80 passedType
🐛 Bug Fix
Caveats (if any)
Medium
web_searchbehind a tools-returning guardrail: 200 without search becomes 400web_fetchandbashalready arrive inLow
typeof a hosted toolweb_fetchandbash; the request itself is unaffectedFinal Attestation
REVIEWER MUST KNOW BEFORE APPROVING
/v1/messagesrequest carryingweb_search_20250305behind any guardrail that receives tools. Before: the guardrail'stoolsinput did not contain it. After: it does, as the Anthropic dict the caller sentweb_searchand the model answered without search. After: the provider receives it. On a Bedrock Claude deployment that turns a 200 into 400 "Bedrock does not support Anthropic's server-side web search tool", the answer the request gets with no guardrail. Approved by yucheng-berri on 2026-11-21web_search_optionsfor, when the request also carries a function tool anddrop_paramsis not set: 400UnsupportedParamsError: <provider> does not support parameters: ['web_search_options'], raised before any provider call. Run live on mistral, groq and deepinfra (proxy at 1fa7e4a and 7973ad5, content filter guardrail, stub upstream): before 200 with the provider receiving[Read]and no search, after 400. With no guardrail both commits answer that same 400, withdrop_params: trueboth answer 200, and a request whose only tool is web search answers 400 on both. Approved by yucheng-berri on 2026-11-21web_search(for example an allow-list by name). Before and after: the provider does not receive it. After, that is the guardrail's decision and not a side effect