Skip to content

fix(anthropic): map /v1/messages fields onto OpenAI Responses equivalents or reject them (lts/1.108.x) - #54367

Merged
mateo-berri merged 28 commits into
BerriAI:lts/1.108.xfrom
chaznm:litellm_backport_messages_openai_field_mapping_lts_1_108_x
Nov 26, 2026
Merged

mateo-berri merged 28 commits into
BerriAI:lts/1.108.xfrom
chaznm:litellm_backport_messages_openai_field_mapping_lts_1_108_x

Conversation

@chaznm

@chaznm chaznm commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

Backport of #54173 to the 1.108 LTS line. Anthropic apps calling an OpenAI model through /v1/messages silently lost settings like turning off parallel tool calls, fast mode and web search filters, and MCP servers were refused. Each now turns into the matching OpenAI setting, and one OpenAI has nothing for gets a clear 400 unless the admin turned on dropping unsupported params

Details

TLDR

Problem this solves:

  • On /v1/messages to OpenAI models, disable_parallel_tool_use, speed and web search filters did nothing
  • mcp_servers answered 400, while container and allowed_callers answered 200 as if they ran

How it solves it:

Intentional product change: container, top_k, inference_geo and allowed_callers other than ["direct"] now answer 400 instead of being ignored. A key allowlist, tool policy or content guardrail now acts on mcp_servers entries and MCP blocks on any model

Picks

Main commit LTS commit How it applied
0ba6bad 72000a8 files moved, plus a test
2d05686 14c7f2a files moved
07299c5 1b13afd clean
b94ad06 3390a69 files moved
06f4f7c 8a9a381 files moved, plus #51337's helper
938d13a 6446719 files moved
3308019 188f1e6 Rust file moved
6079beb 26ba7c8 files moved
c7b29fe ad83790 one helper adapted
f5f1806 17ccc3f one helper adapted
9194d39 e814f47 applied clean
49bd187 743a957 files moved, plus a helper
1761d9a 454e948 files moved, default TTL in the test
b021dfa ce62add Rust file moved
92f11f3 a0342b7 files moved
6134a53 4ad5e05 files moved
How the picks applied, and the commits that are not picks

"Files moved" means the change applied as is after following this line's older paths, where litellm/llms/anthropic/messages/ is still litellm/llms/anthropic/pass_through/. The first pick also adds a token counter test this line has and main does not. The 06f4f7c pick also copies #51337's strict-schema helper, which this line lacks, into pass_through/utils.py. The Rust redaction change goes in litellm-rust/crates/tracing/src/redaction.rs, and main's Rust logging test has no file to go in here. The c7b29fe pick checks a mcp_servers entry with a pydantic adapter, since this line has no _dict_or_none helper. The f5f1806 pick takes main's typed get_standard_logging_model_parameters and its pydantic import, which this line lacked. The 49bd187 pick adds the tool_result_text_part helper main already had, which its guardrail change reads

Three commits are not picks of #54173. 43b2b48 keeps a 1h cache mark at OpenAI's default cache TTL, because this line has neither the 12h cache TTL type nor the 12h cache write price, so a 12h write would be billed at the 30m price. 0ef163b picks #53740's authorization_token redaction, which the MCP authorization redaction in 188f1e6 extends. dd87c56 kept an mcp_toolset out of the guardrail round trip, and the merge 2fe9f5c replaced it with #54323's fix, which main has too

The merge 8df6262 brings in lts/1.108.x at 5da336d. Its one conflict, in convertible_blocks.py, kept the new helpers from both sides. The merge 6b1a0fe brings in lts/1.108.x at f57b2c5, and its one conflict, the import lines of the guardrail handler test, kept both sides' imports. The 1761d9a pick was ported by hand to this line's paths, and its prefill test expects OpenAI's default TTL, as Decision 5 says. The b021dfa pick puts its Rust change in the same redaction.rs as 3308019. The merge b4cad6b brings in lts/1.108.x at 1b6d623, and its conflicts in the Responses bridge transformation and the guardrail handler kept both sides. It also drops a cast in the messages handler that the type gate flagged once tool_choice was typed

The merge 2fe9f5c brings in lts/1.108.x at 9b6796a, which has #54323. Its conflicts in the guardrail handler and its test took the base's tool write-back, which sends an unchanged mcp_toolset on as it came the way main does, and kept the picks' MCP block scanning and both sides' tests. It also adds a cast in the guardrail handler that the type gate flagged

User Flow

Before: an Anthropic SDK app on an OpenAI model loses some settings silently, and its MCP servers are refused

  1. The app sends POST https://litellm-domain/v1/messages with "model": "gpt-6.2-sol", a get_weather tool and tool_choice: {"type": "auto", "disable_parallel_tool_use": true}, asking for the weather in four cities
  2. The reply has four tool_use blocks, as if the flag was never sent
  3. It sends mcp_servers with the DeepWiki MCP server and gets a 400

After: the same requests take effect

  1. The app sends the same request
  2. The reply is a 200 with one tool_use block
  3. The mcp_servers request returns 200 with an answer from the DeepWiki MCP server

Decisions

The decisions are #54173's, except that a cache_control mark of any TTL stays at OpenAI's default cache TTL here, since this line has no 12h TTL

Every decision, as this line ships them
  1. speed: "fast" maps to service_tier: "priority", the faster and pricier tier, per OpenAI's fast mode docs. "standard" sends nothing and any other value answers 400. A forwarded service_tier such as "flex" wins over fast, but "auto" does not
  2. Each MCP server becomes one Responses mcp tool with require_approval: "never", since Anthropic's connector runs tools without asking. An mcp_toolset allowlist becomes allowed_tools. A toolset that turns off only some tools, sets defer_loading or names no server answers 400, and so does a malformed mcp_servers entry unless drop_params is on. An mcp_call returns as mcp_tool_use and mcp_tool_result blocks and replays as the same call, each result found by its call's id. The access match has no default branch, as on main, since basedpyright fails a variant it misses
  3. Web search with domain filters moves to web_search, the tool that takes filters. max_uses becomes max_tool_calls, a cap on every built-in tool, only when web search is the only one, and answers 400 otherwise. A model that refuses domain filters, such as gpt-4o-mini, answers OpenAI's 400, and with drop_params the turn goes again once without them, as on main
  4. Strict json_schema output uses a copy of fix(anthropic): close strict JSON schemas on the Messages to Responses bridge #51337's helper, so $ref and default keep working, and objects with properties close as on main, even ones allowing extra keys, since Anthropic accepts only additionalProperties: false. A schema using anything OpenAI's strict mode rejects, such as a map, a free-form object, allOf, a const with no type, a $ref beside other keywords or a uri format, goes up as is with strict: false, as every schema did here Before (code). OpenAI then does not enforce that schema. The other choices were a 400, or rewriting the schema into OpenAI's subset the way Anthropic's SDK does, which drops constraints the caller set. Like OpenAI's SDK, strict mode lists every property as required, so the model fills optional fields too, and strict: false keeps them optional
  5. A cache_control mark of any TTL stays an explicit cache breakpoint at OpenAI's default TTL on this line, as it was before. A top-level cache_control now marks the last block, or the last block before an assistant prefill since OpenAI takes no mark on assistant text, unless the deployment lists cache_control in additional_drop_params. A tool's cache mark now reaches OpenAI too, at the same default TTL
  6. The key tool allowlist and the tool policy guardrail count each mcp_servers entry by its name, the way /v1/responses counts server_label, so native Anthropic models get this too. Matching a server by its URL stays a separate feature request
  7. Guardrails read mcp_tool_use input and mcp_tool_result text the way they read tool_use and tool_result, on any model, and a mask goes back into the block it came from. A streamed reply's MCP blocks still skip guardrails, as they did Before on native Anthropic, and a follow-up tracks it. A post-call guardrail's rewrite of any tool call's input is dropped here as Before, since fix(guardrails): write rewritten tool_calls from the Generic Guardrail API back to the client #50413 is main only. Every returned mcp_tool_result block is a dict, built here or parsed from Anthropic's JSON, so the write-back reads dicts only, as main does

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

Last updated: 2fe9f5c. All 70 request cases ran again there against 9b6796a, and make check, 3282 unit tests and 564 of 566 integration tests pass there, and the 2 others fail the same on the base

What carries from earlier runs

2fe9f5c merges lts/1.108.x at 9b6796a, which has #54323 and the base's guardrail changes. All 70 cases ran again at 2fe9f5c against 9b6796a, and each After answers as it did at 4ad5e05, apart from one extra redacted_thinking block in one MCP reply. The guardrail, allowlist, tool policy, generic guardrail API and canary cases ran again at 2fe9f5c206d and After answers the same. Before at 9b6796a has #54323, so its claude-haiku guardrail and toolset cases answer 200 instead of the Anthropic 400 below. The merge changes no cache, cost, logging or redaction code, so the cache and debug log cases carry. 4ad5e05 picks main's filters retry, and the 3 drop_params filter tests fail without it

437c970 only adds type annotations to four tests, so the 2fe9f5c runs carry to it, and make check and those tests pass there

a0342b7 changes only how the Responses bridge picks strict for an output schema, and every schema case on an OpenAI Responses model ran again there. The Gemini schema cases take the chat adapter, which it leaves alone. The cache cases ran at ad83790 and the tool cache and web search cases at 743a957, both against ff47f81, and they carry to ce62add. Neither base merge touches the shared cache code, which matches f57b2c5 at ce62add. 454e948 changes only where a top-level mark goes before an assistant prefill, and the prefill case ran that at ce62add. dd87c56 changes only the guardrail handler and ce62add only the log redaction pattern, and those cases run no guardrail and log nothing they check

Setup, the same on both legs

Each leg booted its own tree on one box with its own Postgres database and 2 workers, on a free port. Env var names are OPENAI_API_KEY, GEMINI_API_KEY, ANTHROPIC_API_KEY, LITELLM_MASTER_KEY, DATABASE_URL, OPENAI_BASE_URL, LITELLM_LOCAL_MODEL_COST_MAP=True and PYTHON_DOTENV_DISABLED=1. OPENAI_BASE_URL points at a small recorder that logs each request and forwards it unchanged to https://api.openai.com/v1, which is where the "OpenAI got" lines come from

cd <tree at the leg's commit>
python litellm/proxy/proxy_cli.py --config config.yaml --host 127.0.0.1 --port <port> --num_workers 2 --timeout_worker_healthcheck 60 --telemetry False --use_prisma_db_push

config.yaml, also in the gist

model_list:
  - model_name: gpt-6.2-sol
    litellm_params:
      model: openai/gpt-6.1-sol
      api_key: os.environ/OPENAI_API_KEY
  - model_name: gpt-6.2-sol-drop
    litellm_params:
      model: openai/gpt-6.1-sol
      api_key: os.environ/OPENAI_API_KEY
      drop_params: true
  - model_name: gpt-6.2-sol-nocache
    litellm_params:
      model: openai/gpt-6.1-sol
      api_key: os.environ/OPENAI_API_KEY
      additional_drop_params: ["cache_control"]
  - model_name: gpt-4.1
    litellm_params:
      model: openai/gpt-4.1
      api_key: os.environ/OPENAI_API_KEY
  - model_name: gemini-flash
    litellm_params:
      model: gemini/gemini-3.8-flash
      api_key: os.environ/GEMINI_API_KEY
  - model_name: claude-haiku
    litellm_params:
      model: anthropic/claude-haiku-5-5
      api_key: os.environ/ANTHROPIC_API_KEY

Client code, anthropic 0.84.0. A case that sets mcp_servers, container or speed goes through client.beta.messages with the matching beta header, as its step says. The full script is sdk_leg.py, and the allowlist cases are sdk_allowlist.py

import anthropic

client = anthropic.Anthropic(base_url="http://127.0.0.1:<port>", api_key=LITELLM_MASTER_KEY, max_retries=0)
message = client.messages.create(**case)
with client.messages.stream(**case) as s:
    message = s.get_final_message()

The cache cases ran on a second set of proxies with no recorder and no database, since LiteLLM sends a cache breakpoint only to OpenAI's own host and the recorder's URL looks like another host. Their config.yaml has only the gpt-6.2-sol and gpt-6.2-sol-nocache entries above, started with litellm --config config.yaml --port <port> --num_workers 2. Besides Before and After, a third proxy ran the tip with 43b2b48 reverted, which is what the picks alone would ship on this line. Each call sends a prompt of about 6,000 tokens marked cache_control: {"type": "ephemeral", "ttl": "1h"}, salted per leg so the legs never share a cache entry, and repeats it 40 s later. The script is sdk_cache.py, and its output is cache-progress.txt with each call's full reply beside it

28 requests through the Anthropic SDK, Before and After

Both legs sent the same 28 requests through the Anthropic Python SDK, plain and streaming. The OpenAI cases went to real OpenAI gpt-6.1-sol, served as gpt-6.2-sol since 6.1 is the newest Sol in this line's cost map, one schema case went to gpt-4.1, and two schema cases went to Gemini gemini-3.8-flash. Each OpenAI case quotes what OpenAI received, read from a recorder that forwards to api.openai.com. The table says what each request answered and, in brackets, what the OpenAI request carried

Case Before After
disable_parallel_tool_use, 4 cities 200 4 tool calls 200 1 tool calls (parallel_tool_calls False)
No parallel flag, 4 cities 200 4 tool calls 200 4 tool calls
stop_sequences 200 text 200 text
Strict schema on gpt-4.1 200 text 200 text (strict)
Strict tool 200 redacted_thinking+text 200 redacted_thinking+text (strict)
Strict tool, every field required 200 redacted_thinking+text 200 redacted_thinking+text (strict)
speed fast 200 text 200 text (service_tier priority)
No speed 200 text 200 text
speed fast, service_tier auto 200 text (service_tier auto) 200 text (service_tier priority)
mcp_servers 400 unsupported param 200 mcp_tool_use+mcp_tool_result+text (mcp tool)
mcp_toolset 400 unsupported param 200 mcp_tool_use+mcp_tool_result+text (mcp tool)
mcp_toolset with a disabled tool 400 unsupported param 200 text (mcp tool)
mcp_toolset naming no server 400 unsupported param 400 unsupported param
mcp_servers, drop_params model 200 redacted_thinking+text 200 mcp_tool_use+mcp_tool_result+text (mcp tool)
web_search allowed_domains 200 text 200 text
web_search user_location 200 redacted_thinking+text 200 text
container skills 200 text 400 unsupported param
container skills, drop_params model 200 text 200 text
container id 200 text 400 unsupported param
container id, drop_params model 200 text 200 text
top_k 200 redacted_thinking+text 400 unsupported param
top_k, drop_params model 200 redacted_thinking+text 200 redacted_thinking+text
inference_geo 200 redacted_thinking+text 400 unsupported param
inference_geo, drop_params model 200 redacted_thinking+text 200 redacted_thinking+text
Schema with a root $ref 200 text 200 text (strict)
Root $ref on Gemini 200 text (nothing sent) 200 text (nothing sent)
Map fields on Gemini 200 text (nothing sent) 200 text (nothing sent)
Malformed mcp_servers entry 400 unsupported param 400 unsupported param
A key's tool allowlist counts each mcp_servers entry, on any model

The tool allowlist now counts each mcp_servers entry by its name, on OpenAI and native Anthropic models alike. Two virtual keys were made with /key/generate, one with metadata.allowed_tools: ["lookup"] and one with ["lookup", "deepwiki"], and each sent DeepWiki through mcp_servers plus its mcp_toolset. The script is sdk_allowlist.py, and its output is Before and After

Request Before After
deepwiki on gpt-6.2-sol, key allows lookup 400 invalid_request_error 403 tool_access_denied
deepwiki on gpt-6.2-sol, key allows lookup and deepwiki 400 invalid_request_error 200, called deepwiki
deepwiki on claude-haiku, key allows lookup 200, called deepwiki 403 tool_access_denied
deepwiki on claude-haiku, key allows lookup and deepwiki 200, called deepwiki 200, called deepwiki
tools lookup on claude-haiku, key allows lookup 200 200
A 1h cache mark keeps the 30m TTL and its logged price on this line

43b2b48 keeps a 1h mark at OpenAI's default 30m cache TTL. With the picks alone, OpenAI writes that cache for 12h, which main's cost map prices at about twice the 30m write, while this line logs it at the 30m price because its cost map has no 12h write price. After writes for 30m as Before did, so the logged cost matches the write. Each cost covers the call's whole prompt at the same rate per token on every leg

Case Before (ff47f81) Picks alone After (ad83790)
/v1/responses 1h mark, write TTL 30m, 6876 tokens 12h, 7047 tokens 30m, 6876 tokens
/v1/responses first call cost $0.0172 for 6876 tokens $0.0177 for 7057 tokens $0.0172 for 6876 tokens
/v1/messages 1h mark, first call cost $0.0173 for 6876 tokens $0.0177 for 7057 tokens $0.0172 for 6876 tokens
/v1/messages top-level mark, first call cost $0.0172 for 6872 tokens $0.0177 for 7053 tokens $0.0172 for 6872 tokens
Callbacks get the MCP token as REDACTED

A logging callback reads model_parameters from the standard logging payload. Each leg sent a canary MCP token as authorization_token on two OpenAI calls and one native Anthropic call. Before answered 400 to the OpenAI calls and gave the callback the Anthropic call's token in plain text at model_parameters.mcp_servers[0].authorization_token. After answered 200 to all three and shows the token 0 times in the callback payload, the proxy log and spend logs (script, Before, After)

With debug logs on, an MCP token that starts with null- was logged 2 times in plain and 2 times in JSON debug logs at 454e948 and 0 times at ce62add, which keeps the null and boolean exception to whole values (script, output)

A split MCP replay and an assistant prefill

When the first turn called two MCP tools and the replay sends both uses before either result, or puts text between a use and its result, After answers 200 and OpenAI gets both mcp_call items with their outputs. Before answers 400, since it refuses mcp_servers on OpenAI models. count_tokens answers 400 on these blocks on both legs before any OpenAI call, as on main (script, output)

A top-level 1h cache_control now puts the mark on the last user turn at OpenAI's default TTL, before an assistant prefill too, where Before sent no mark. All six calls answered 200, plain and streaming. These ran against api.openai.com with no recorder, reading each proxy's own outbound body (script, output)

A json_schema within OpenAI's strict mode goes to OpenAI with strict: true and any other with strict: false, all 200 (wire summary)

Schema cases
Schema Before After
closed object 200, strict: false 200, strict: true
map and free-form fields 200, strict: false 200, strict: false
free-form field 200, strict: false 200, strict: false
allOf with a $ref 200, strict: false 200, strict: false
const with no type 200, strict: false 200, strict: false
$ref with a description 200, strict: false 200, strict: false
uri format 200, strict: false 200, strict: false
SDK messages.parse with HttpUrl 200, strict: false 200, strict: false
enum and date-time 200, strict: false 200, strict: true
root $ref 200, strict: false 200, strict: true

Each ran plain and streaming at a0342b7 with the same result, and strict is what OpenAI received (first three, the rest). Before replies are r8-base-<case>-plain.txt in the r8 gist for the first three and l-base-<case>-plain.txt in the schema gist for the rest, and After replies are l-head-<case>-plain.txt there, for example uri Before and uri After

Content guardrails now block and mask words inside MCP blocks (guardrail wire diff, mask wire summary)

Guardrail cases

These guardrails were added to the same config.yaml, and each request turns one on with "guardrails": ["<name>"] in its body

guardrails:
  - guardrail_name: mcp_word_in
    litellm_params:
      guardrail: litellm_content_filter
      mode: pre_call
      blocked_words:
        - keyword: POISONWORD
          action: BLOCK
  - guardrail_name: mcp_word_out
    litellm_params:
      guardrail: litellm_content_filter
      mode: post_call
      blocked_words:
        - keyword: Cookbook
          action: BLOCK
  - guardrail_name: mcp_mask_in
    litellm_params:
      guardrail: litellm_content_filter
      mode: pre_call
      blocked_words:
        - keyword: POISONWORD
          action: MASK
  - guardrail_name: mcp_mask_out
    litellm_params:
      guardrail: litellm_content_filter
      mode: post_call
      blocked_words:
        - keyword: Cookbook
          action: MASK

claude-haiku goes straight to Anthropic and gpt-6.2-sol goes to OpenAI through the recorder. "blocked" is the guardrail's 400 Content blocked: keyword ... detected, and on gpt-6.2-sol Before answered 400 on every row, blocked on the user text row and mcp_servers unsupported on the rest. "Anthropic 400" is Anthropic refusing a request whose mcp_toolset a pre_call guardrail dropped, which #54323 fixed in the base at 9b6796a. This table's Before ran on an older base, and Before at 9b6796a is in the 2fe9f5c206d run

Request Guardrail haiku Before haiku After gpt After
POISONWORD in a replayed mcp_tool_result block Anthropic 400 blocked blocked
POISONWORD in a replayed mcp_tool_use block Anthropic 400 blocked blocked
same replay, streamed block Anthropic 400 blocked blocked
POISONWORD in user text block blocked blocked blocked
Cookbook in the reply's mcp_tool_result block 200 blocked blocked
same reply, streamed block 200 200, not scanned 200, not scanned
clean replay block Anthropic 400 200 200
clean replay none 200 200 200
POISONWORD in a replayed mcp_tool_result mask Anthropic 400 200 200, OpenAI got [KEYWORD_REDACTED]
Cookbook in the reply's mcp_tool_result mask 200, Cookbook shown [KEYWORD_REDACTED] [KEYWORD_REDACTED]
mcp_toolset that turns on one tool block Anthropic 400 200 200, OpenAI got allowed_tools
same toolset none 200 200 200, OpenAI got allowed_tools

A blocked request never reached OpenAI, and a blocked reply came after one OpenAI call. Each request is r8-cell-<case>.json in the gist and its replies are r8-base-<case>.txt and r8-head-<case>.txt, for example request, Before and After for the toolset row on claude-haiku

Tool policy cases

The tool policy guardrail reads mcp_servers names on native Anthropic models too, and a toolset it lets through reaches Anthropic (script, Before, After)

Both legs restarted with a tool_policy guardrail, mode: pre_call and default_on: true, and store_model_in_db: true. Each policy was set with POST /v1/tool/policy and given 25 s to sync. Each call is claude-haiku with DeepWiki in mcp_servers and its mcp_toolset

deepwiki policy Before After
blocked Anthropic 400 400 Violated tool policy
untrusted Anthropic 400 200, called deepwiki

Tool cache marks and web search filters were checked on the real OpenAI host too (outbound bodies)

Tool cache marks and web search filters

A cache_control mark on a tool now reaches OpenAI as that tool's prompt_cache_breakpoint, plain and streaming, where Before sent the tool with no mark, and a 1h TTL on it stays at OpenAI's default TTL, like a message mark on this line. Web search with blocked_domains and max_uses goes out as web_search with filters.blocked_domains and max_tool_calls, where Before sent a bare web_search_preview. All eight calls answered 200. These ran at 743a957 and ff47f81 against api.openai.com with no recorder, reading each proxy's own outbound body, since LiteLLM sends cache marks only to OpenAI's own host. The requests are tool mark, 1h tool mark, streamed and web search

/live-pr-risk on 43b2b48, no breaking change

43b2b48 removes the 12h mapping the picks added, so the shared cache code (common_utils.py, the OpenAI Responses and Chat Completions transformations, the Anthropic cache control hook and the OpenAI-like config) matches f57b2c5 at ce62add, and git diff --stat f57b2c584f3 ce62add3900 on those files prints nothing. The Messages bridge itself does change, since the picks add a tool's cache mark, so that path ran live at 743a957 in the tool cache cases above, where OpenAI got the tool's mark at the default TTL. The cache legs above ran at ad83790 and show the same write TTL and cost as ff47f81 on /v1/responses and /v1/messages. Later commits change no shared cache code, so the pass carries to ce62add

/live-pr-risk on dd87c56, no breaking change

dd87c56 changes what a /v1/messages guardrail scans and writes back, on any model. Its dependents are the content filter, which ran in the guardrail cases above on both models, the tool policy guardrail, which ran in the tool policy cases, and any guardrail that reads the scanned tools, which no longer gets the toolset as a function with no name. Function tools and provider tools such as web search take the same path as Before. 8df6262 merged the base in, so this tip is what lands on lts/1.108.x

Backward incompatible

  • On OpenAI models container, top_k, inference_geo, a code execution allowed_callers and a malformed mcp_servers entry answer 400 where they answered 200 and did nothing. Under drop_params an mcp_servers entry now goes upstream instead of being dropped. This follows litellm's drop_params convention, and the drop_params legs show the 200. Kept in Caveats for Mateo's review
  • speed: "fast" now asks for OpenAI's priority tier, billed about 2x. It is the mapping this PR was asked for, kept in Caveats
  • A key whose allowed_tools leaves out an mcp_servers entry, a tool policy that blocks one, or a content guardrail whose word shows up in an MCP block now refuses the request on any model, native Anthropic included, where Before let it through. This closes gaps in the allowlist and the guardrails, kept in Caveats for Mateo's review

Regression risk

  • A pre-existing gap went to security engineering
  • A streamed reply's MCP blocks skip guardrails on both models, as they did Before on native Anthropic. A follow-up tracks it
/live-pr-risk on ce62add, no breaking change

The merge 6b1a0fe brings base changes to the Anthropic guardrail translation handler and to the /v1/messages stream assembly and streaming iterators, which the picks' MCP guardrail and stream code sit beside. The guardrail, mask, tool policy and streamed cases above ran at ce62add and answer as they did at dd87c56. 454e948 adds two helpers with one caller each in the Messages adapter, one pairing a replayed MCP result with its call by id and one placing the top-level cache mark, and the split replay and prefill cases ran both. ce62add applies the null and boolean exception in log redaction to whole values only, so it only redacts more, and every redact_string caller gets it, which the debug log case covers. Since then lts/1.108.x moved to 1e96f26 with #53768, a previous_response_id fix that shares no file with this PR. On ce62add merged with 1e96f26, the SDK, allowlist, prefill and split replay cases answer as they did at ce62add, apart from one extra redacted_thinking block in a schema reply (output)

/live-pr-risk on 2fe9f5c, no breaking change

The merge 2fe9f5c brings in #54323's tool write-back, #54327's Bedrock guardrail scan of /v1/messages, and the generic guardrail API's tool_calls, tools and structured_messages fields. Each reads what the picks' guardrail handler hands it, so the dependents are the content filter, the tool policy, the generic guardrail API and the Bedrock guardrail on /v1/messages. The 2fe9f5c206d run drove the first three on both legs, with a recorder in front of the generic guardrail API, and every After answers as it did at 4ad5e05. The tool allowlist and the canary cases also answer the same

Backward incompatible

  • A generic guardrail API vendor now also gets a replayed mcp_tool_result's text in texts and its mcp_tool_use in tool_calls, which it did not get at 9b6796a. This is Decision 7 reaching a guardrail the base added, and no auth header reaches the vendor on either leg. Kept in Caveats for Mateo's review

Regression risk

  • A Bedrock guardrail against real AWS did not run live, and its 2 /v1/responses wire tests fail the same on the base

Every Before request, with what OpenAI got, is in cases-before-f57b2c584f3.md

After (ce62add), every request and what OpenAI got

disable_parallel_tool_use, 4 cities

  1. Send m1_parallel.json the same way as Before
  2. 200 with {"stop_reason": "tool_use", "tool_use": 1, "cost": "0.000468"}, and streaming gave the same status. OpenAI got {"parallel_tool_calls": false, "tool_choice": "auto", "tools": [{"type": "function", "name": "get_weather", "strict": false}]}. Raw output is in the gist, the stream run beside it

No parallel flag, 4 cities

  1. Send m1_no_flag.json the same way as Before
  2. 200 with {"stop_reason": "tool_use", "tool_use": 4, "cost": "0.000912"}, and streaming gave the same status. OpenAI got {"tool_choice": "auto", "tools": [{"type": "function", "name": "get_weather", "strict": false}]}. Raw output is in the gist, the stream run beside it

stop_sequences

  1. Send m0_stop_sequences.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.00016600000000000002"}, text 1 2 3 4 5, and streaming gave the same status. OpenAI got none of the case's fields. Raw output is in the gist, the stream run beside it

Strict schema on gpt-4.1

  1. Send h1_chat_bridge_strict.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.000194"}, text {"city": "Paris", "country": "France"}, and streaming gave the same status. OpenAI got {"text.format.strict": true}. Raw output is in the gist, the stream run beside it

Strict tool

  1. Send m2_strict.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["redacted_thinking", "text"], "cost": "0.0007320000000000001"}, text {"color":"red","note":"The color must be either red or blue...., and streaming gave the same status. OpenAI got {"text.format.strict": true}. Raw output is in the gist, the stream run beside it

Strict tool, every field required

  1. Send m2b_strict_required.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["redacted_thinking", "text"], "cost": "0.0007"}, text {"answer": "yes", "confidence": 1}, and streaming gave the same status. OpenAI got {"text.format.strict": true}. Raw output is in the gist, the stream run beside it

speed fast

  1. Send m3_speed_fast.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.00014800000000000002"}, text Hi, and streaming gave the same status. OpenAI got {"service_tier": "priority"}. Raw output is in the gist, the stream run beside it

No speed

  1. Send m3_speed_none.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "8.400000000000001e-05"}, text Hi!, and streaming gave the same status. OpenAI got none of the case's fields. Raw output is in the gist, the stream run beside it

speed fast, service_tier auto

  1. Send m3c_speed_fast_auto.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.00016800000000000002"}, text Hi!, and streaming gave the same status. OpenAI got {"service_tier": "priority"}. Raw output is in the gist, the stream run beside it

mcp_servers

  1. Send m4_mcp_servers.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["mcp_tool_use", "mcp_tool_result", "text"], "cost": "0.00333"}, text The first 3 top-level topics for **BerriAI/litellm** are: 1..., and streaming gave the same status. OpenAI got {"tools": [{"type": "mcp", "server_label": "deepwiki", "server_url": "https://mcp.deepwiki.com/mcp", "require_approval": "never"}]}. Raw output is in the gist, the stream run beside it

mcp_toolset

  1. Send m5_mcp_toolset.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["mcp_tool_use", "mcp_tool_result", "text"], "cost": "0.003094"}, text The first 3 top-level topics for BerriAI/litellm are: 1. ..., and streaming gave the same status. OpenAI got {"tools": [{"type": "mcp", "server_label": "deepwiki", "server_url": "https://mcp.deepwiki.com/mcp", "allowed_tools": ["read_wiki_structure"], "require_approval": "never"}]}. Raw output is in the gist, the stream run beside it

mcp_toolset with a disabled tool

  1. Send m5b_mcp_toolset_blocked_tool.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.000484"}, text ASK_QUESTION_UNAVAILABLE, and streaming gave the same status. OpenAI got {"tools": [{"type": "mcp", "server_label": "deepwiki", "server_url": "https://mcp.deepwiki.com/mcp", "allowed_tools": ["read_wiki_structure"], "require_approval": "never"}]}. Raw output is in the gist, the stream run beside it

mcp_toolset naming no server

  1. Send m5c_orphan_toolset.json the same way as Before
  2. 400 with openai/gpt-6.1-sol is served through the OpenAI Responses API, which has no equivalent for mcp_toolset 'github' without a matching mcp_servers entry. To drop it, set 'litellm.drop_params=Tru..., and streaming gave the same status. Raw output is in the gist, the stream run beside it

mcp_servers, drop_params model

  1. Send m5d_orphan_toolset_drop.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["mcp_tool_use", "mcp_tool_result", "text"], "cost": "0.00333"}, text The first 3 top-level topics for **BerriAI/litellm** are: 1..., and streaming gave the same status. OpenAI got {"tools": [{"type": "mcp", "server_label": "deepwiki", "server_url": "https://mcp.deepwiki.com/mcp", "require_approval": "never"}]}. Raw output is in the gist, the stream run beside it

web_search allowed_domains

  1. Send m6_websearch_domains.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.030021"}, text LiteLLM is an open-source Python SDK and AI gateway that pro..., and streaming gave the same status. OpenAI got {"tools": [{"type": "web_search", "filters": {"allowed_domains": ["docs.litellm.ai"]}}]}. Raw output is in the gist, the stream run beside it

web_search user_location

  1. Send m6b_websearch_location.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.031876"}, text San Francisco — Today, Wednesday, November 25, expect **morn..., and streaming gave the same status. OpenAI got {"tools": [{"type": "web_search_preview", "user_location": {"type": "approximate", "city": "San Francisco", "region": "California", "country": "US", "timezone": "America/Los_Angeles"}}]}. Raw output is in the gist, the stream run beside it

container skills

  1. Send m7_container_callers.json the same way as Before
  2. 400 with openai/gpt-6.1-sol is served through the OpenAI Responses API, which has no equivalent for allowed_callers on tool 'get_weather'; container. To drop them, set 'litellm.drop_params=True', or ..., and streaming gave the same status. Raw output is in the gist, the stream run beside it

container skills, drop_params model

  1. Send m7b_container_callers_drop.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.000156"}, text Hi!, and streaming gave the same status. OpenAI got {"tools": [{"type": "function", "name": "get_weather", "strict": false}]}. Raw output is in the gist, the stream run beside it

container id

  1. Send r2_container_id.json the same way as Before
  2. 400 with openai/gpt-6.1-sol is served through the OpenAI Responses API, which has no equivalent for container. To drop it, set 'litellm.drop_params=True', or 'drop_params: true' in the model's 'litel..., and streaming gave the same status. Raw output is in the gist, the stream run beside it

container id, drop_params model

  1. Send r2b_container_id_drop.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "8.400000000000001e-05"}, text Hi!, and streaming gave the same status. OpenAI got none of the case's fields. Raw output is in the gist, the stream run beside it

top_k

  1. Send m8_top_k.json the same way as Before
  2. 400 with openai/gpt-6.1-sol is served through the OpenAI Responses API, which has no equivalent for top_k. To drop it, set 'litellm.drop_params=True', or 'drop_params: true' in the model's 'litellm_p..., and streaming gave the same status. Raw output is in the gist, the stream run beside it

top_k, drop_params model

  1. Send m8b_top_k_drop.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["redacted_thinking", "text"], "cost": "0.00018800000000000002"}, text Red, and streaming gave the same status. OpenAI got none of the case's fields. Raw output is in the gist, the stream run beside it

inference_geo

  1. Send m9_inference_geo.json the same way as Before
  2. 400 with openai/gpt-6.1-sol is served through the OpenAI Responses API, which has no equivalent for inference_geo. To drop it, set 'litellm.drop_params=True', or 'drop_params: true' in the model's 'l..., and streaming gave the same status. Raw output is in the gist, the stream run beside it

inference_geo, drop_params model

  1. Send m9b_inference_geo_drop.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["redacted_thinking", "text"], "cost": "0.00022800000000000004"}, text Red, and streaming gave the same status. OpenAI got none of the case's fields. Raw output is in the gist, the stream run beside it

Schema with a root $ref

  1. Send r1_root_ref.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.000288"}, text {"name":"Ada","age":36}, and streaming gave the same status. OpenAI got {"text.format.strict": true}. Raw output is in the gist, the stream run beside it

Root $ref on Gemini

  1. Send r1g_root_ref_gemini.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.00114825"}, text {"name": "Ada", "age": 36}, and streaming gave the same status. Nothing went through the OpenAI recorder. Raw output is in the gist, the stream run beside it

Map fields on Gemini

  1. Send r3_maps_gemini.json the same way as Before
  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.0012202500000000002"}, text {"name":"Ada","metadata":{ } ,"tags":{"color":"blue"}}, and streaming gave the same status. Nothing went through the OpenAI recorder. Raw output is in the gist, the stream run beside it

Malformed mcp_servers entry

  1. Send r4_mcp_malformed.json the same way as Before
  2. 400 with openai/gpt-6.1-sol is served through the OpenAI Responses API, which has no equivalent for a malformed mcp_servers entry. To drop it, set 'litellm.drop_params=True', or 'drop_params: true' i..., and streaming gave the same status. Raw output is in the gist, the stream run beside it

Type

🐛 Bug Fix

Caveats (if any)

Copied from #54173 without main-only items, plus this line's own

Medium

  • speed: "fast" asks for OpenAI's priority tier, billed about 2x, unless additional_drop_params lists speed
  • container, top_k, inference_geo and refused domain filters answer 400 unless dropped, and drop_params now keeps mcp_servers, which a custom openai/ host may reject
  • allowed_callers with a code execution caller answers 400, and a follow-up tracks it
  • Key allowlists, tool policies and content guardrails now act on MCP server names only, on any model, so native Anthropic requests can get 403 or 400, and generic guardrail API vendors get MCP blocks
  • The tool permission guardrail still skips MCP and hosted tools on every route, as Before, and a follow-up tracks it
  • Streamed MCP blocks skip guardrails, as on native Anthropic Before, and a follow-up tracks it
  • Strict mode requires optional schema fields, and a schema it rejects goes unenforced (Decision 4)
  • Shadow eval now replays a logged tool's headers as REDACTED
  • A pre-existing gap went to security engineering

Low

  • defer_loading on an mcp_toolset answers 400, with no tool search round trip
  • Under drop_params, a partial mcp_toolset denylist drops the whole MCP server
  • Azure models take the Chat Completions path as Before and skip the new mappings
  • This line still drops stop_sequences to OpenAI, as Before, and a follow-up tracks it
  • count_tokens on OpenAI models answers 400 on MCP blocks, as Before, and a follow-up tracks it
  • router_code_coverage fails on the base too, naming the same four router functions
  • A post-call rewrite of a tool call's input, MCP included, is still dropped, and a follow-up tracks it

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
Bugbot summary

[!NOTE]
Medium Risk
Broad request/response translation and new 400 behavior on formerly accepted params can surprise callers; credential redaction and stricter allowlist/guardrail coverage are security-relevant but aligned with the intended fixes.

Overview
Anthropic /v1/messages → OpenAI Responses now translates fields that were previously ignored or blocked: disable_parallel_tool_use → parallel_tool_calls, speed: "fast" → service_tier: priority, web search domain filters and max_uses, MCP mcp_servers / mcp_toolset → Responses mcp tools (with allowlists and replay as mcp_tool_use / mcp_tool_result), structured output via strict OpenAI JSON schema when compatible, and prompt-cache marks (including top-level cache_control). Params with no OpenAI equivalent (container, top_k, inference_geo, partial MCP toolsets, etc.) raise UnsupportedParamsError unless drop_params / additional_drop_params; refused web search filters and reasoning summary are retried via a generalized _RefusedField path.

Logging and redaction strip authorization, authorization_token, and headers from logged tools / mcp_servers, with matching Python/Rust patterns for MCP-style authorization values (including Bearer/Basic), while keeping masked or literal null/true/false values.

Guardrails, allowlists, and streaming treat MCP blocks like ordinary tool use/results (input and nested result text), include MCP server names in tool-name extraction, and emit MCP call SSE chunks on the Responses stream bridge.

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

mateo-berri and others added 17 commits November 14, 2026 08:22
…ents or reject them

The Responses bridge for /v1/messages dropped several Anthropic fields and still answered 200. disable_parallel_tool_use now sets parallel_tool_calls false, speed fast asks for the priority service tier, mcp_servers become Responses mcp tools with their toolset allowlist, web_search keeps its domain filters, user_location, and max_uses, a json_schema output format goes up strict, and a 1h cache_control mark asks OpenAI for its 12h breakpoint TTL

A field with no Responses equivalent (container, allowed_callers, an unknown speed, a toolset denylist, defer_loading, max_uses next to another built-in tool) answers 400 UnsupportedParamsError naming every such field, and drop_params drops them instead

strict_json_schema moves to base_utils so the Codex harness, the chat-completions bridge, and the Responses bridge share one walker, which now leaves property names and enum, const, and examples values alone

(cherry picked from commit 0ba6bad)
…ompletions rejects a breakpoint ttl

(cherry picked from commit 2d05686)
… on the Responses wire

(cherry picked from commit 07299c5)
… the 1.108 line

The 1h to 12h breakpoint ttl the picks carry needs the 12h prompt cache ttl type and the 12h cache write rate, and this line has neither, so a 12h write would be billed at the 30m write rate. A 1h mark keeps the default explicit breakpoint here, as it did before the picks, until the 12h billing reaches the line
…r 400 for a container id

Picks the main fix onto lts/1.108.x. The line lacks BerriAI#51337, so this copies its strict-schema helper into the
pass-through utils for the Responses bridge, and the chat bridge keeps its own closing logic. A container id string
and a malformed mcp_servers entry now answer 400, or are dropped under drop_params, instead of a 500
…rt_messages_openai_field_mapping_lts_1_108_x

# Conflicts:
#	litellm/llms/anthropic/pass_through/responses_adapters/handler.py
#	litellm/llms/anthropic/pass_through/responses_adapters/transformation.py
#	tests/unit/llms/anthropic/pass_through/responses_adapters/test_responses_adapters_transformation.py
…rt_messages_openai_field_mapping_lts_1_108_x
…rt_messages_openai_field_mapping_lts_1_108_x

# Conflicts:
#	litellm/llms/anthropic/pass_through/responses_adapters/handler.py
#	litellm/llms/anthropic/pass_through/responses_adapters/transformation.py
#	litellm/llms/anthropic/pass_through/utils.py
#	tests/unit/llms/anthropic/pass_through/responses_adapters/test_responses_adapters_handler.py
…erriAI#53740)

An MCP server entry in a /v1/messages request carries its credential as authorization_token. The key name
list both redactors share had auth_token, access_token and refresh_token but not this one, so an opaque token
under it stayed in debug logs. It is added to the Python list and to the Rust list, which must agree.

A value under one of these key names may start with an auth scheme, as in Bearer abc. The key name pattern
took the value up to the first space, so it hid the scheme and left the credential. It now takes a Bearer or
Basic scheme together with the value.
(cherry picked from commit f409bfd)
…e OpenAI bridge and redact the MCP authorization

top_k and inference_geo have no Responses equivalent, so they now answer 400 like container unless drop_params
or additional_drop_params drops them, instead of a silent 200. An mcp_toolset that names no mcp_servers entry
answers 400 the same way. The error says to set drop_params: true in the model's litellm_params or under
litellm_settings.

A forwarded service_tier of auto no longer beats speed fast, since auto asks for nothing specific. A top-level
cache_control marks the last block of the conversation the way Anthropic caches it, and an mcp_call output comes
back as mcp_tool_use and mcp_tool_result blocks that replay on the next turn.

The server token goes out as the Responses mcp tool's authorization field, so both redactors now scrub a value
under a quoted authorization key in JSON or a Python repr. A value litellm already masked, like the Authorization
header in the JSON debug log, keeps its hint, and an Authorization header name is left alone.

On the 1.108 line a 1h cache mark keeps the default breakpoint TTL, so the automatic top-level mark maps to
the default breakpoint too, and the Rust redaction pattern lives in litellm-rust/crates/tracing.

(cherry picked from commit 3308019)
…rt_messages_openai_field_mapping_lts_1_108_x
…t drops cache_control

(cherry picked from commit 6079beb)
The standard logging payload copied tools and mcp_servers into
model_parameters as sent, so an MCP server's authorization or
authorization_token reached every logging callback in plain text.

(cherry picked from commit f5f1806)
Mark AnthropicMessagesRequestOptionalParams.container ReadOnly and pass it when the Responses adapter builds its request instead of setting it afterwards

(cherry picked from commit 9194d39)
@chaznm
chaznm requested a review from a team November 25, 2026 07:02
@veria-ai

veria-ai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

The PR updates Anthropic /v1/messages handling to map fields to OpenAI Responses equivalents or reject them, including web-search parameters and MCP tool-call processing.

Three issues have been addressed, but two remain open. With drop_params enabled, a retry can remove web-search domain restrictions and permit retrieval outside an application's intended sources. Separately, masking guardrails can redact MCP arguments without those changes reaching the client, leaving the original content exposed.

Open issues (2)

Fixed/addressed: 3 · PR risk: 6/10

Reviews

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge, with the remaining numbered finding fixed and no new blocking issues foundRetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge, with the remaining numbered finding fixed and no new blocking issues found

Summary

This PR backports Anthropic Messages mappings for OpenAI Responses, adds MCP support, extends guardrail checks, and redacts MCP credentials

The latest commit only adds type annotations to four tests. It fixes the remaining numbered finding without changing runtime behavior. No new issues or confirmed repository-rule violations were found

chaznm documents streamed MCP guardrail coverage and post-call tool-input rewrites as deferred limitations. Neither is a new finding in this review

No tests were run during this review

  • Anthropic message settings now reach OpenAI or get rejected.
  • Anthropic message requests can use OpenAI MCP servers.
  • Guardrails and tool allowlists now include MCP blocks and servers.
  • MCP credentials are hidden in model logs and redacted text.

Reviews (7) · Last reviewed commit: "test(anthropic): type the MCP tool resul..." · Reviewed by Greptile

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

…arrow the authorization log pattern

OpenAI strict structured outputs reject a map or a free-form object, so a
Messages output schema that leaves an object open now goes to the Responses
API with strict false instead of answering 400.

Guardrails on /v1/messages now read mcp_tool_use input and mcp_tool_result
text in requests and replies, and write a masked result back, the way they
already handle tool_use and tool_result. That covers replayed history too.

The quoted authorization log pattern now needs a word boundary and skips
null, None and booleans, so keys like requires_authorization log as sent.

(cherry picked from commit 49bd187)
…rt_messages_openai_field_mapping_lts_1_108_x

# Conflicts:
#	litellm/llms/anthropic/pass_through/convertible_blocks.py
…rt_messages_openai_field_mapping_lts_1_108_x

# Conflicts:
#	tests/unit/llms/anthropic/chat/guardrail_translation/test_anthropic_guardrail_handler.py
…p a top-level cache mark before a prefill (lts/1.108.x)
…th null or a boolean (lts/1.108.x)

The exception for a literal null, None, true or false authorization value now needs the whole value to be that literal, so a token such as null-<rest> is redacted in Python and Rust
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

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.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

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.


def _unfiltered(tool: object) -> object:
search: Final = _filtered_web_search(tool)
return tool if search is None else {key: value for key, value in search.items() if key != "filters"}

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.

Medium: Preserve domain restrictions on retry

With global or deployment-level drop_params=True, an upstream filters refusal resends web_search without its allowed_domains/blocked_domains, allowing unrestricted retrieval for applications that use these fields to constrain trusted sources. Fail closed or drop the entire search tool unless removing domain restrictions has a separate explicit opt-in.

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.

This matches main's filters retry, which runs only under drop_params, litellm's opt-in to drop what a model refuses, else 400

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

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.

…rt_messages_openai_field_mapping_lts_1_108_x

# Conflicts:
#	litellm/llms/anthropic/chat/guardrail_translation/handler.py
#	tests/unit/llms/anthropic/chat/guardrail_translation/test_anthropic_guardrail_handler.py

# Extract tool calls
elif content_type == "tool_use" and isinstance(content_block, dict):
elif content_type in _TOOL_CALL_BLOCK_TYPES and isinstance(content_block, dict):

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.

Medium: Persist MCP tool-call redactions

convert_tool_use_to_openai_format() serializes input into a separate arguments string, but process_output_response() only writes back returned texts, so a masking guardrail can return redacted MCP arguments while the client still receives the originals. This applies to both in-place and replacement-list returns. Track the original call-block positions and apply returned tool_calls back to those blocks, rejecting rewrites that cannot be applied safely.

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.

On lts/1.108.x a post-call rewrite of any tool call's input is dropped, function tools too, since #50413 is main only. A follow-up tracks it

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings could not be posted inline.

  • P1 Security MCP argument masks disappear litellm/llms/anthropic/chat/guardrail_translation/handler.py:2150 ▶

    Post-call masks never reach mcp_tool_use.input. The guardrail changes a separate copy of the arguments, but the response path only writes back texts. Sensitive values therefore reach the client unchanged. Write the changed tool_calls back before returning the response

    How this was verified: MCP arguments become a separate JSON string for the guardrail, but the response path only writes back texts

@mateo-berri

Copy link
Copy Markdown
Contributor

Post-call tool call rewrites are dropped for every tool_use on lts/1.108.x, as #50413 is main only, so MCP blocks match function tools here

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

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.

if block.get("type") == "text":
block["text"] = guardrail_response
elif block.get("type") == "mcp_tool_result":
_write_back_mcp_tool_result_text(block, mapping[1], guardrail_response)

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.

Output guardrail MCP result write-back skips Pydantic objects

Low Severity

The new mcp_tool_result write-back in _apply_guardrail_responses_to_output only handles dict content blocks, while the existing text block write-back also handles Pydantic objects via the elif hasattr(content_block, "type") branch. When a native Anthropic model returns mcp_tool_result blocks as Pydantic model instances (as the Anthropic SDK may do), a post-call guardrail mask for that block's text is scanned and matched but silently not written back, leaving the original unmasked text in the response.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 437c970. Configure here.

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.

Every mcp_tool_result block litellm returns is a dict, built here or parsed from Anthropic's JSON, and main's write-back is the same

tools=({**_mcp_tool(server), "allowed_tools": list(names)},), unsupported=unsupported
)
case _NoEquivalent(field=field):
return _ResponsesTools(unsupported=(*unsupported, field))

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.

Match statement in _mcp_server_tools lacks default return

Low Severity

_mcp_server_tools uses a match statement on access: _McpAccess without a default branch. While all current variants (_AllTools, _OnlyTools, _NoEquivalent) are covered, if a new variant is added to _McpAccess without updating this function, it implicitly returns None where _ResponsesTools is expected, causing an AttributeError when the caller accesses .tools or .unsupported.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 437c970. Configure here.

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.

The declared _ResponsesTools return makes basedpyright fail any new _McpAccess variant this match misses, and main's same function has no default either

@mateo-berri

Copy link
Copy Markdown
Contributor

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!

2 issues from previous reviews remain unresolved.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit 437c970. Configure here.

@mateo-berri mateo-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

@mateo-berri
mateo-berri merged commit 9ebac9b into BerriAI:lts/1.108.x Nov 26, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants