Skip to content

fix(guardrails): keep /v1/messages tools the guardrail left unchanged exactly as sent - #53290

Merged
yucheng-berri merged 6 commits into
mainfrom
litellm_lit10590_messages_guardrail_tools
Nov 24, 2026
Merged

yucheng-berri merged 6 commits into
mainfrom
litellm_lit10590_messages_guardrail_tools

Conversation

@yucheng-berri

@yucheng-berri yucheng-berri commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

On /v1/messages, tools a guardrail leaves unchanged now reach the provider exactly as the caller sent them, instead of being rebuilt and losing Anthropic-only fields.

Details

TLDR

Problem this solves:

  • Any tools-returning guardrail rewrote every /v1/messages tool
  • web_search was dropped, mcp_toolset became litellm_unnamed_tool_0
  • defer_loading, strict, input_examples, allowed_callers, cache_control were stripped

How it solves it:

  • Tools the guardrail hands back unchanged stay exactly as sent
  • Only a tool the guardrail changed or added is converted
  • A tool the guardrail removed stays removed

Intentional product change: a Bedrock Claude deployment behind such a guardrail used to answer 200 after silently dropping a web_search_20250305 tool. It now answers the same 400 it already gives without a guardrail, which tells the operator to enable web search interception.

User Flow

Before: a developer running a coding agent through the gateway behind a default-on content filter gets deferred tools loaded up front and loses web search

  1. The admin sets a default-on pre_call litellm_content_filter that only masks emails
  2. The developer sends POST https://litellm-domain/v1/messages with a tool_search_tool_regex tool and two tools marked "defer_loading": true
  3. The provider receives both tools without defer_loading and with "type": "custom" added, so they are no longer deferred
  4. With a web_search_20250305 tool next to a custom tool on an OpenAI model, the provider receives no web search tool at all

After: the same request reaches the provider with the tools the developer sent

  1. The admin sets a default-on pre_call litellm_content_filter that only masks emails
  2. The developer sends POST https://litellm-domain/v1/messages with a tool_search_tool_regex tool and two tools marked "defer_loading": true
  3. The provider receives both tools byte for byte as sent, still deferred, and the email in the prompt is still masked
  4. With a web_search_20250305 tool next to a custom tool on an OpenAI model, the provider receives the web search tool

Admin UI Logs page, same request on both proxies: POST /v1/messages to an OpenAI model with [Read, web_search_20250305] behind the email-masking content filter, asking the model to list its tools.

Before (f30ea8b): the provider was given 1 tool and the model says it cannot search the web

before

After (834fd4a73f2): the provider was given both tools

after

Relevant issues

Fixes #50055
Fixes #49253

Covers the cases in the open PRs #40077 and #49721.

Linear ticket

Resolves LIT-10590

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Two live proxies ran side by side, one at the merge base and one at the tip, each with 2 workers, its own Postgres and its own Redis. Every provider call is real. A logging reverse proxy sat between each gateway and the provider (it is the deployment's api_base), so the "provider received" lines below are the bytes the gateway sent.

Provider routes covered: Bedrock InvokeModel Claude through /v1/messages (json and stream), the Bedrock pass-through route /bedrock/model/<model>/invoke, Bedrock Converse through /v1/messages, and an OpenAI model through /v1/messages. In this matrix the direct Anthropic API key had no credits, so Anthropic answered 400 "credit balance is too low" on both legs; the Anthropic API and Azure AI Foundry Claude were proven later with a funded key, see the reviewer notes at the bottom. The Gemini deployment in the rig pointed at a retired model name and answered 404 on both legs.

Shared setup: config.yaml, start command, env var names, client
model_list:
  - model_name: claude-anthropic
    litellm_params:
      model: anthropic/claude-haiku-4-5
      api_key: os.environ/ANTHROPIC_API_KEY
      api_base: http://127.0.0.1:<anthropic recorder port>
  - model_name: claude-bedrock-invoke
    litellm_params:
      model: bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0
      aws_region_name: us-west-2
      aws_bedrock_runtime_endpoint: http://127.0.0.1:<bedrock recorder port>
  - model_name: claude-bedrock-converse
    litellm_params:
      model: bedrock/converse/us.anthropic.claude-haiku-4-5-20251001-v1:0
      aws_region_name: us-west-2
      aws_bedrock_runtime_endpoint: http://127.0.0.1:<bedrock recorder port>
  - model_name: gpt
    litellm_params:
      model: openai/gpt-5.4-mini
      api_key: os.environ/OPENAI_API_KEY
      api_base: http://127.0.0.1:<openai recorder port>/v1
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  coordination_redis: {host: 127.0.0.1, port: <redis port>}
router_settings:
  redis_host: 127.0.0.1
  redis_port: <redis port>
guardrails:
  - guardrail_name: content-filter
    litellm_params:
      guardrail: litellm_content_filter
      mode: pre_call
      default_on: true
      patterns:
        - {pattern_type: prebuilt, pattern_name: email, action: MASK}
      blocked_words:
        - {keyword: FORBIDDENWORD, action: BLOCK}

For the cases where a guardrail edits or removes a tool, the guardrails block is replaced by two opt-in custom guardrails selected per request with "guardrails": ["mask-read-tool"] or ["drop-read-tool"]:

from litellm.integrations.custom_guardrail import CustomGuardrail

def _name(tool):
    return (tool.get("function") or {}).get("name")

class MaskReadToolDescription(CustomGuardrail):
    async def apply_guardrail(self, inputs, request_data, input_type, logging_obj=None):
        for tool in inputs.get("tools") or []:
            if _name(tool) == "Read":
                tool["function"]["description"] = "[MASKED BY GUARDRAIL]"
        return inputs

class DropReadTool(CustomGuardrail):
    async def apply_guardrail(self, inputs, request_data, input_type, logging_obj=None):
        if "tools" in inputs:
            inputs["tools"] = [tool for tool in inputs["tools"] if _name(tool) != "Read"]
        return inputs

Start command, run from each checkout: python litellm/proxy/proxy_cli.py --config config.yaml --port <port> --num_workers 2 --use_prisma_db_push

Env var names: DATABASE_URL, LITELLM_MASTER_KEY, ANTHROPIC_API_KEY, OPENAI_API_KEY, AWS_BEARER_TOKEN_BEDROCK, LITELLM_LICENSE

Client, the same for every case, with the tools and prompt of that case:

curl -s http://127.0.0.1:<port>/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "anthropic-version: 2023-06-01" -H "content-type: application/json" -d '{
  "model": "claude-bedrock-invoke", "max_tokens": 1024, "stream": false,
  "messages": [{"role": "user", "content": "Use tool search to find the tool that adds a Confluence footer comment, then call it for page 42 with the text hi."}],
  "tools": [
    {"type": "tool_search_tool_regex_20251119", "name": "tool_search_tool_regex"},
    {"name": "Read", "description": "Reads a file from disk", "input_schema": {"type": "object", "properties": {"path": {"type": "string"}}, "required": ["path"]}},
    {"name": "mcp__atlassian__create_confluence_footer_comment_with_a_very_long_name_x", "description": "Adds a footer comment to a Confluence page", "input_schema": {"type": "object", "properties": {"page_id": {"type": "string"}, "text": {"type": "string"}}, "required": ["page_id", "text"]}, "defer_loading": true},
    {"name": "mcp__jira__create_issue", "description": "Creates a Jira issue", "input_schema": {"type": "object", "properties": {"page_id": {"type": "string"}, "text": {"type": "string"}}, "required": ["page_id", "text"]}, "defer_loading": true}
  ]}'

The web search cases send "tools": [<Read as above>, {"type": "web_search_20250305", "name": "web_search", "max_uses": 1}] with the prompt "Use web search to find the latest stable CPython release, then answer with the version number only."

input_schema is shortened to {...} in the output below. It was identical to what the client sent in every line.

Before (f30ea8b)

Deferred tools behind the default-on content filter, Bedrock InvokeModel, json and stream

  1. Send the client request above with "stream": false, then again with "stream": true. Both answer 200 with stop_reason: tool_use
  2. Provider received, both times:
{"type": "tool_search_tool_regex_20251119", "name": "tool_search_tool_regex"}
{"name": "Read", "input_schema": {...}, "type": "custom", "description": "Reads a file from disk"}
{"name": "mcp__atlassian__create_confluence_footer_comment_with_a_very_long_name_x", "input_schema": {...}, "type": "custom", "description": "Adds a footer comment to a Confluence page"}
{"name": "mcp__jira__create_issue", "input_schema": {...}, "type": "custom", "description": "Creates a Jira issue"}

Same tools through the Bedrock pass-through route

  1. POST the same body without model and stream, with "anthropic_version": "bedrock-2023-05-31", to /bedrock/model/claude-bedrock-invoke/invoke. It answers 200
  2. Provider received the same four rewritten tools as above, with no defer_loading

Prompt with an email, so the guardrail edits the request

  1. Send the client request with the prompt "Repeat this back exactly: contact bob@example.com". It answers 200 with the text contact [EMAIL_REDACTED]
  2. Provider received the same four rewritten tools as above, with no defer_loading

Web search tool next to a custom tool, OpenAI model through /v1/messages

  1. Send the web search request with "model": "gpt". It answers 200 with the text ``, an answer from memory
  2. Provider received on /v1/responses:
{"type": "function", "name": "Read", "strict": false, "description": "Reads a file from disk", "parameters": {...}}

Web search tool next to a custom tool, Bedrock InvokeModel

  1. Send the web search request with "model": "claude-bedrock-invoke". It answers 200 with the text "I don't have access to a web search tool. The tools available to me only allow me to read files from disk."
  2. Provider received only the Read tool

A guardrail that edits one tool, and one that removes it

  1. Send the client request with "guardrails": ["mask-read-tool"]. It answers 200. Provider received Read with "description": "[MASKED BY GUARDRAIL]", and the two deferred tools without defer_loading
  2. Send it with "guardrails": ["drop-read-tool"]. It answers 200. Provider received no Read tool, and the two deferred tools without defer_loading

Blocked word

  1. Send the client request with the prompt "say FORBIDDENWORD". It answers 400 Content blocked: keyword 'forbiddenword' detected and the provider receives nothing

After (834fd4a73f2)

Deferred tools behind the default-on content filter, Bedrock InvokeModel, json and stream

  1. Send the client request above with "stream": false, then again with "stream": true. Both answer 200 with stop_reason: tool_use
  2. Provider received, both times, the tools exactly as sent:
{"type": "tool_search_tool_regex_20251119", "name": "tool_search_tool_regex"}
{"name": "Read", "description": "Reads a file from disk", "input_schema": {...}}
{"name": "mcp__atlassian__create_confluence_footer_comment_with_a_very_long_name_x", "description": "Adds a footer comment to a Confluence page", "input_schema": {...}, "defer_loading": true}
{"name": "mcp__jira__create_issue", "description": "Creates a Jira issue", "input_schema": {...}, "defer_loading": true}

Same tools through the Bedrock pass-through route

  1. POST the same body without model and stream, with "anthropic_version": "bedrock-2023-05-31", to /bedrock/model/claude-bedrock-invoke/invoke. It answers 200
  2. Provider received the four tools exactly as sent, with "defer_loading": true on both deferred tools

Prompt with an email, so the guardrail edits the request

  1. Send the client request with the prompt "Repeat this back exactly: contact bob@example.com". It answers 200 with the text contact [EMAIL_REDACTED]
  2. Provider received the four tools exactly as sent, with "defer_loading": true on both deferred tools

Web search tool next to a custom tool, OpenAI model through /v1/messages

  1. Send the web search request with "model": "gpt". It answers 200 with the text 3.15.2
  2. Provider received on /v1/responses:
{"type": "function", "name": "Read", "strict": false, "description": "Reads a file from disk", "parameters": {...}}
{"type": "web_search_preview"}

Web search tool next to a custom tool, Bedrock InvokeModel

  1. Send the web search request with "model": "claude-bedrock-invoke". It answers 400 "Bedrock does not support Anthropic's server-side web search tool (tool type 'web_search_20250305', model 'us.anthropic.claude-haiku-4-5-20251001-v1:0'). To use web search with this model, enable LiteLLM's web search interception so the proxy executes the search instead"
  2. Provider received nothing. This is the answer the same request already gets on the merge base when no guardrail is attached

A guardrail that edits one tool, and one that removes it

  1. Send the client request with "guardrails": ["mask-read-tool"]. It answers 200. Provider received Read with "description": "[MASKED BY GUARDRAIL]" in its original second position, and the other three tools exactly as sent with "defer_loading": true
  2. Send it with "guardrails": ["drop-read-tool"]. It answers 200. Provider received no Read tool, and the two deferred tools exactly as sent with "defer_loading": true

Blocked word

  1. Send the client request with the prompt "say FORBIDDENWORD". It answers 400 Content blocked: keyword 'forbiddenword' detected and the provider receives nothing

Unchanged on both legs

Bedrock Converse through /v1/messages, /v1/chat/completions and /v1/responses with the same guardrails, a logging_only and a during_call guardrail that edits tools, a request with no guardrail, and a request with no tools sent the same bytes before and after.

Audit at 834fd4a73f2

63 live cells per leg across three guardrail configs: 50 pass, 5 show the behavior changes listed at the bottom, 8 are blocked by a provider (no Anthropic credits, Gemini 404). The guardrails used are on the Admin UI page below.

guardrails

Chaos step Before After
40 concurrent requests on /v1/messages, /v1/chat/completions, /v1/responses, mixed streaming, one worker killed mid-burst 40 x 200, one provider call each 40 x 200, one provider call each
Tools on the 16 Bedrock /v1/messages calls of that burst 16 rewritten 16 as sent
30 concurrent requests with Postgres paused for 6 s 30 x 200 30 x 200
Anthropic SDK sync, sync stream, async, async stream 0 of 4 as sent 4 of 4 as sent

Sad and edge cells with the same answer on both legs: tools as a string, an int, a list of strings (500 on both), unknown model (400), no auth (401), unknown guardrail name, empty tools, duplicate tool names (provider 400 on both), tool_choice naming a tool the guardrail removed (provider 400 on both), a 5 KB description, an OpenAI-format tool.

Third-party guardrails, live at 77f56dc

Thirteen pre_call guardrails against their real services (Presidio as real analyzer and anonymizer containers), /v1/messages to the Anthropic API, main 7f08cd7 against this tip. Each got a benign prompt, the same prompt streamed, and a prompt with a card number and an email. The tools were tool_search_tool_regex, a plain tool, a defer_loading tool and a strict tool with cache_control. A recorder in front of Anthropic and each vendor logged what was sent.

Guardrail Status, both legs Tools sent to Anthropic, before After
Akto 200, 200, 403 (blocks the card number) defer_loading and strict dropped as sent
Noma 200 x 3, card number masked on both dropped as sent
Alice 200 x 3 dropped as sent
Straiker 200, 200, denied dropped as sent
Zscaler AI Guard 200 x 3 dropped as sent
OpenAI Moderation 200 x 3 dropped as sent
Presidio 200 x 3, card number and email masked on both dropped as sent
TypeSafe 200 x 3 (no vendor call, it only judges tool calls) dropped as sent
Azure Prompt Shield, Azure Text Moderation 200 x 3 each as sent as sent
Airia, Ovalix, Gray Swan 400 x 3 each: the vendor refused the call (503, 401, no policy id) not sent not sent

All 42 cells per leg have the same status, the same x-litellm-applied-guardrails, the same stream event count, the same vendor call count and the same message text on the wire. The only difference is the tools. Not run: Bedrock Guardrails and Model Armor.

Tests

tests/integration/messages_endpoint/test_anthropic_messages_caller_tools_wire.py gains four cases on a real two-worker proxy with a scripted provider. They failed at f30ea8b (4 failed, 18 passed) and pass at the tip (22 passed). The unit tests cover a tool returned unchanged, edited, renamed, removed, added, returned twice, two tools the guardrail cannot tell apart, and deferred tools left alone by a removal.

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • Bedrock Claude with web_search_20250305 behind a guardrail: 200 without search becomes 400
    • Same 400 the request gets today without a guardrail
    • Fix for operators: enable web search interception
  • A tool a guardrail edits is still converted from OpenAI format
    • That one tool loses Anthropic-only fields, as before
    • Tools reach the provider in the order the guardrail returned them, as on main

Low

  • A guardrail that removes every non-deferred tool: kept tools lose defer_loading
    • Anthropic rejects a request whose tools are all deferred
  • A malformed tool the guardrail left unchanged is no longer repaired into a valid one
    • Bedrock answers 400, as it does with no guardrail
  • Comparing tools costs two JSON passes over them per guardrail
    • About 1 ms for 100 tools of 2 KB each, linear in size
  • tests/integration runs on main after merge, or with the run-ci label

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

REVIEWER MUST KNOW BEFORE APPROVING

  • Built on fix(guardrails): show the /v1/messages web search tool to guardrails #53376 (merged as 4c62c9a), which shows web_search to guardrails. Now on main, tip 77f56dc (a8287e0 minus one timing unit test, no product change)
  • 67c80d0 makes the tools follow the guardrail's returned order, as main does. Before that commit this branch rebuilt them in the request's order, so a guardrail's reorder was ignored and a renamed tool landed after the cache_control breakpoint, and matching cost grew with the square of the tool count. Live on OpenAI through a forwarding recorder, main 7f08cd7 and 030c2ba both send [fmt, lint] for a reversing guardrail and [lint_v2, fmt] for a renaming one. At 030c2ba: 17675 unit tests and 84 /v1/messages integration tests pass. Live on Bedrock Claude Haiku 4.5 at 030c2ba against main 7f08cd7, same recorder: both send [fmt, lint] and [lint_v2, fmt] with the cache_control breakpoint still on the last tool, and the second call with the renamed tool reads the whole tool prefix from the prompt cache (11,507 tokens on main, 11,508 here). Proxy overhead with a guardrail that renames every tool, median of 3: 2000 tools 820 ms on main and 911 ms here (about 3.0 s before 67c80d0), 1000 tools 427 ms and 436 ms, 500 tools 265 ms and 222 ms
  • a8287e0 reads the tools a guardrail returns once. Before it, a custom guardrail that returned tools as a generator, map or reversed had every tool dropped with a 200, or the request answered 500, where main sends them. Live on OpenAI at a8287e0 against main 7f08cd7: a generator, a reversed and a map that edits one tool all send the same three tools on both legs. 17678 unit tests and 84 /v1/messages integration tests pass
  • Full live matrix rerun at 0239ff0 against main 7f08cd7: 63 cells per leg, 36 send identical bytes, 26 send the caller's unchanged tools as sent, 1 is the nameless-tool 400 below. Chaos bursts 40 of 40 and 30 of 30
  • Live on the Anthropic API and on Azure AI Foundry Claude Haiku 4.5 at a8287e0 against main 7f08cd7, through forwarding recorders, 24 cells per leg, each with no guardrail and behind an email-masking litellm_content_filter: deferred tools (json and stream), a cache_control tool, a valid strict tool and web_search_20250305 all answer 200 on both legs. Behind the guardrail main sends rebuilt tools (defer_loading and strict gone, "type": "custom" added) and this branch sends the caller's tools byte for byte, the same bytes both legs send with no guardrail. The email is masked on both legs
  • Approved by yucheng-berri on 2026-11-23 for every route and provider: the "malformed tool is no longer repaired" change below also applies on the paths listed here, because they share this write-back. Each one answers the same 400 main gives with no guardrail. Reproduced live:
    • Bedrock pass-through /bedrock/model/<model>/invoke and /invoke-with-response-stream with an Anthropic body: a tool with an unknown key, no name, name: "", no input_schema, an input_schema with no type, strict on a schema without additionalProperties: false, or every tool deferred goes 200 to 400. A valid unchanged tool now goes out as sent, without the added "type": "custom", and still answers 200
    • /v1/messages to an OpenAI model: strict: true on a schema that is not valid for OpenAI strict mode goes 200 to 400 (main dropped strict), and name: "" goes 200 to 400 on the Responses route
    • /v1/messages to Vertex AI Claude: the same malformed shapes, allowed_callers, and computer_20250124 sent without its beta header go 200 to 400
    • /v1/messages to the Anthropic API and to Azure AI Foundry Claude: a named tool with no input_schema goes 200 to 400
  • Live rerun at 86b69c6, the same diff before the rebase, against fix(guardrails): show the /v1/messages web search tool to guardrails #53376's head 7973ad5 (main 1fa7e4a merged in): 63 live cells per leg, same rig as above. 36 sent identical bytes, 26 now send the caller's tools as sent or with fewer fields rewritten, and 1 changed status (the nameless tool below). Unit sweep 16944 passed, three integration files 84 passed, chaos bursts 40 of 40 and 30 of 30 with 16 of 16 Bedrock tool lists as sent. The detailed proof above is from 834fd4a73f2 on the old base; the cells it shows gave the same result in the rerun, except that a tools: [] reply now removes web_search
  • With fix(guardrails): show the /v1/messages web search tool to guardrails #53376 underneath, a guardrail that returns an empty tool list removes web_search again, because it now sees that tool and left it out. The earlier "empty tools reply keeps web search" change is gone
  • Bedrock Claude deployment, /v1/messages request carrying a web_search_20250305 tool, behind a guardrail that returns tools. Before: 200, the web search tool was silently dropped and the model answered without search. After: 400 "Bedrock does not support Anthropic's server-side web search tool", the same answer the request gets with no guardrail. This change now comes from fix(guardrails): show the /v1/messages web search tool to guardrails #53376. Approved by yucheng-berri on 2026-11-21
  • A malformed /v1/messages tool that a guardrail returns unchanged, on a Bedrock Claude deployment. Before: the tool was rebuilt from OpenAI format, which repaired it, and Bedrock answered 200. After: it is sent as the caller sent it and Bedrock answers 400, as it does on main with no guardrail. Shapes reproduced: no name and no input_schema (was rewritten into litellm_unnamed_tool_0), a named tool with no input_schema, name: "", an input_schema with a top-level anyOf, an input_schema with no type, an unknown key on the tool, input_examples, strict, and a list where every tool has defer_loading. A tool the guardrail edits is still rebuilt and repaired. Approved by yucheng-berri on 2026-11-23 for every route and provider (the nameless case on 2026-11-21)

Note

Medium Risk
Changes pre-call request shaping on /v1/messages for all tools-returning guardrails; malformed unchanged tools and Bedrock web_search now surface provider 400s instead of silent rewrites.

Overview
On /v1/messages, guardrail write-back no longer rebuilds every tool from OpenAI format. New logic (_tools_after_guardrail, fingerprint matching, and _loaded_up_front) keeps tools the guardrail left alone exactly as the client sent them—including defer_loading, web_search, native tool types, and other Anthropic-only fields. Only tools the guardrail edited, added, or reordered are converted back; removed tools stay removed. When every surviving tool would be deferred-only, defer_loading is stripped so Anthropic still accepts the request.

Integration tests add vendor guardrails that redact one description or drop one tool; unit tests cover pass-through, edits, removals, duplicates, and deferred-tool edge cases.

Reviewed by Cursor Bugbot for commit a8287e0. Bugbot is set up for automated code reviews on this repo. Configure here.

@veria-ai

veria-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Fixed/addressed: 2 · PR risk: 0/10

Reviews

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

5 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no outstanding actionable findings.

Summary

The PR keeps unchanged /v1/messages tools as the caller sent them. Changed or added tools are still converted, and removed tools stay removed.

The latest commit only removes a timing-sensitive test and its unused import. No new actionable issues were found.

yucheng-berri explicitly approved unchanged malformed tools returning provider errors across affected routes and providers. They also approved Bedrock web search returning its existing unsupported-tool error instead of silently losing search.

  • Unchanged tools keep their original Anthropic fields after a guardrail.

Reviews (15) · Last reviewed commit: "test(guardrails): drop the write-back ti..." · Reviewed by Greptile

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

4 similar comments
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri
yucheng-berri force-pushed the litellm_lit10590_messages_guardrail_tools branch from b0a6081 to 0b0f7ad Compare November 21, 2026 20:16
@yucheng-berri
yucheng-berri changed the base branch from main to litellm_messages_guardrail_sees_web_search November 21, 2026 20:16
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri
yucheng-berri force-pushed the litellm_lit10590_messages_guardrail_tools branch from 0b0f7ad to 72acdef Compare November 21, 2026 21:30
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri
yucheng-berri force-pushed the litellm_lit10590_messages_guardrail_tools branch from 72acdef to 86b69c6 Compare November 21, 2026 21:53
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

Base automatically changed from litellm_messages_guardrail_sees_web_search to main November 22, 2026 01:02
@yucheng-berri
yucheng-berri force-pushed the litellm_lit10590_messages_guardrail_tools branch from 86b69c6 to 8bb758a Compare November 22, 2026 01:03
…eturned them

A guardrail that reordered or renamed tools had its order ignored: tools were
rebuilt in the request's order and a renamed tool was appended last, after the
tool carrying the cache_control breakpoint. Matching a rewritten tool back to a
request position also rescanned the open positions once per tool.

The tools now follow the guardrail's list. A tool it left alone is sent as the
caller sent it, any other is converted in place, with one lookup per tool.
Tools the guardrail is never shown go first, as before this branch.
…ages_guardrail_tools

# Conflicts:
#	litellm/llms/anthropic/chat/guardrail_translation/handler.py
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 77f56dc. Configure here.

@ryan-crabbe-berri ryan-crabbe-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@yucheng-berri
yucheng-berri merged commit ce63fa7 into main Nov 24, 2026
52 checks passed
@yucheng-berri
yucheng-berri deleted the litellm_lit10590_messages_guardrail_tools branch November 24, 2026 21:03
yucheng-berri added a commit that referenced this pull request Nov 25, 2026
…rt_53290_lts_1_108_x

Conflicts with #54213 in the /v1/messages guardrail tool write-back, resolved to
main's text, where #54183 sits on top of #53290: tools the guardrail returned
unchanged stay as sent, and a kept tool loads up front when the guardrail removed
the tool search tool. The by-name defer_loading restore from #54213 is left out,
as on main.
mateo-berri pushed a commit to chaznm/litellm that referenced this pull request Nov 25, 2026
… exactly as sent (BerriAI#53290)

* fix(guardrails): send /v1/messages tools a guardrail left alone as the caller sent them

* fix(guardrails): send /v1/messages tools in the order the guardrail returned them

A guardrail that reordered or renamed tools had its order ignored: tools were
rebuilt in the request's order and a renamed tool was appended last, after the
tool carrying the cache_control breakpoint. Matching a rewritten tool back to a
request position also rescanned the open positions once per tool.

The tools now follow the guardrail's list. A tool it left alone is sent as the
caller sent it, any other is converted in place, with one lookup per tool.
Tools the guardrail is never shown go first, as before this branch.

* test(guardrails): measure write-back time growth instead of counting field reads

* fix(guardrails): read the tools a guardrail returns once so a one-shot iterable is not lost

* test(guardrails): drop the write-back timing test, unit tests must not depend on execution speed

(cherry picked from commit ce63fa7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants