Skip to content

feat(anthropic-messages): per-deployment deferred_tools handling on the /v1/messages bridge (lts/1.108.x) - #54213

Merged
mateo-berri merged 19 commits into
BerriAI:lts/1.108.xfrom
martenj4:litellm_deferred_tools_per_deployment_lts
Nov 25, 2026
Merged

mateo-berri merged 19 commits into
BerriAI:lts/1.108.xfrom
martenj4:litellm_deferred_tools_per_deployment_lts

Conversation

@martenj4

@martenj4 martenj4 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

LTS twin of #54183 for lts/1.108.x. When Claude Code loads a tool through tool search, every non-Anthropic model behind /v1/messages lost its prompt cache on that turn. This adds the same per-deployment deferred_tools setting on 1.108, so native tool search or emulation keeps the cache and no backend gets blocks it rejects

Details

TLDR

Problem this solves:

  • A Claude Code tool load drops the prompt cache on non-Anthropic models
  • Deferred tools reach every backend as plain tools, and defer_loading leaks into the chat bridge's tool schema

How it solves it:

  • New model_info.deferred_tools: passthrough, native, emulate, or drop (default)
  • native maps ToolSearch onto Responses API tool search
  • emulate keeps one fixed tool list on chat-only backends through a CallLoadedTool dispatcher
  • A value a deployment's route cannot apply answers 400, or uses drop under drop_params

User Flow

Before: a developer running Claude Code through a 1.108 proxy on an Azure deployment pays full input price on every request right after a tool load

  1. They start Claude Code with ANTHROPIC_BASE_URL=https://litellm-domain, ENABLE_TOOL_SEARCH=true and an MCP server connected
  2. They ask something that needs an MCP tool, so Claude Code searches for it and loads it
  3. The next POST https://litellm-domain/v1/messages comes back with cache_read_input_tokens: 0, and every later tool load repeats it

After: the same session keeps its cache across tool loads

  1. The proxy admin sets deferred_tools: native under the Azure deployment's model_info and restarts the proxy
  2. They start Claude Code the same way and ask the same question
  3. The request right after the load comes back with most of its input in cache_read_input_tokens, like Anthropic direct
model_list:
  - model_name: azure-sol
    litellm_params:
      model: azure/gpt-6.1-sol
      api_base: os.environ/AZURE_API_BASE
      api_key: os.environ/AZURE_API_KEY
    model_info:
      deferred_tools: native

Design decisions

Every mode, default, and error matches #54183, whose Design decisions section explains each choice. This PR only moves that behavior onto the 1.108 code layout

Picks

Pick table
main commit lts commit
5121db0 d6d1365
fe80829 d6d1365
e2dec1c d6d1365
c05f900 52a9352
2cc7863 2d5c1a8
112c9ac 78a205d
837ad2c 874d45f
4ac1e85 0dd87fc
52171f9 968ccd9
263951a c65b7d8
74d8355 d8561fb
852f13e ba603a4
4e66f7e 7ce2004
ffb864e b0254a8
bcb7c2e 6c7d110
624a6c8 f62deb6
0be65b3 78e77c5
0cae7c3 bbf3181
f3d34a8 2030ddd
Differences on this line
  • The first three main commits went in by hand as one commit, and c05f900, 2cc7863, 112c9ac, 837ad2c and 4ac1e85 as one commit each, since 1.108 keeps the bridge under litellm/llms/anthropic/pass_through/ where main has litellm/llms/anthropic/messages/, and messages/handler.py here is main's native/handler.py
  • loads_json_object is copied into litellm_core_utils/core_helpers.py, since 1.108 lacks it
  • The 1.108 streaming_iterator.py makes sse_frame_event public and gains sse_frames, which the emulation stream restorer reads
  • _translate_tool_to_responses_api is pulled out of the Responses adapter so native can keep deferred tools deferred
  • Main's applied-edits, polyfill and context-management plumbing in the same files stays out, since it is unrelated to this change
  • The emulation import in the handler stays lazy, as on main, so import litellm still never loads litellm.proxy._types
  • 1.108's _should_route_to_responses_api takes no stop_sequences, so the call site passes native_deferred_tools and not stop_sequences. OpenAI requests with stop_sequences already went to the Responses API on 1.108 and keep tool search there, so only requests that leave it, like Azure's, get main's stop_sequences 400 when they carry ToolSearch and a deferred tool
  • 1.108 has no thread or diagnostics checks, so the unknown-value refusal sits right after the native config lookup
  • 1.108's Rust route serves only LITELLM_RUST traffic and has one Python hook, settings(kwargs), so the refusals go there, with Rust route tests main does not need. It finds the provider with get_llm_provider and checks for a provider messages API through the handler's messages_request_bridges, since 1.108 lacks main's _messages_config
  • Main's count_tokens routing fix in 2cc7863, and 112c9ac's count_tokens test change, have no twin here, since 1.108's count_tokens picks a token counter by provider only
  • In the Rust route, refusal_unless_dropped wraps the messages_request_bridges check that stands in for main's config is None
  • The Responses adapter handler imports optional_str from litellm.rust_bridge.public_call, since 1.108 lacks litellm.llms.base_llm.base_utils.optional_str
  • The guardrail write-back keeps defer_loading on each tool the request deferred, since 1.108 rebuilds the tools from OpenAI format after a guardrail runs. Main already sends a tool the guardrail left unchanged exactly as it came. On both lines, a guardrail that removed ToolSearch sends the kept tools without defer_loading
  • The chat adapter reads a request-level base_model for the passthrough check, since 1.108 passes it apart from model_info. Main merges it into model_info before the adapter runs
  • The count_tokens part of bcb7c2e has no LTS change, since 1.108 never counted defer_loading

Linear ticket

Resolves LIT-11175

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

After ran on 6c7d110 and Before on ba603a4 (topology, config, gist)

Last updated: 2030ddd. QA ran on 6c7d110, after merging lts/1.108.x at f57b2c5. Changes since: fixes to native with stop_sequences, the tool_config cache point, guardrail write-back, native replays, and the emulate restore, which now skips strict tools. Proof remains valid because live-pr-risk re-ran each changed path on real providers at bbf3181 and 2030ddd, and only the two Low caveats below moved (report). Verification: CI passed at 2030ddd

Percentages are cache reads right after a tool load

Case Before After
1. br-kimi emulate turn CallLoadedTool error, 0% Forecast, 95%
2. azure-sol native turns Nothing deferred, 0% As control, 97%
3. claude-direct curl defer_loading dropped defer_loading kept
R6 1. br-kimi-pass turn After only One warning per request
R6 1, 2, 3, 5. passthrough curls After only 400, drop_params 200
R6 4. fw-kimi-pass, br-kimi turns After only Forecast, no error
R2 7. azure-sol native long After only 97-98%

Case 1, Claude Code on br-kimi (headline)

br-kimi is bedrock/us.moonshotai.kimi-k3.1 with deferred_tools: emulate, behind the pre_call content filter

  1. Start Claude Code on each leg with run_session.sh
  2. Send What is the weather forecast for Paris? Use the weather MCP tool.
  3. Read the session's /spend/logs with spend_brief.sh

After, the forecast shows with no error, and row 3, right after the load, reads 95% from cache (full run)

$ SHOT=$S/tip-br-kimi-short.png $S/run_session.sh tip br-kimi http://127.0.0.1:32637 $S/master.key short
$ python3 spend_rows.py http://127.0.0.1:$P master.key $m "$S" "$E" spend-tip-br-kimi-short-raw.json | awk 'BEGIN{print "# input cached tools(defer) upstream"} NR>1 && NF>8 {print $1, $4, $6, $8, $NF}'
# input cached tools(defer) upstream
1 1561 0% 0(0) text
2 12401 0% 13(1) ToolSearch
3 13087 95% 18(6) CallLoadedTool
4 13270 99% 18(6) text

pr54213-6c7d110941-r7-case1-tip-br-kimi.png

Before, Claude Code shows Error: No such tool available: CallLoadedTool, and row 3 reads 0% (full run)

$ SHOT=$S/base-br-kimi-short.png $S/run_session.sh base br-kimi http://127.0.0.1:24247 $S/master.key short
$ python3 spend_rows.py http://127.0.0.1:$P master.key $m "$S" "$E" spend-base-br-kimi-short-raw.json | awk 'BEGIN{print "# input cached tools(defer) upstream"} NR>1 && NF>8 {print $1, $4, $6, $8, $NF}'
# input cached tools(defer) upstream
1 1561 0% 0(0) text
2 12441 0% 13(0) ToolSearch
3 13120 0% 18(0) CallLoadedTool
4 13298 99% 18(0) mcp__weather__get_forecast
5 13637 97% 18(0) text

pr54213-7ce200493b-r7-case1-base-br-kimi.png

Case 2, azure-sol native, 3 Claude Code turns, both legs and a control without the guardrail

azure-sol is azure/gpt-6.1-sol with deferred_tools: native. Each session sends In one sentence, what does a three-day weather forecast usually include?, then case 1's prompt, which loads the forecast tool, then Is Wednesday a good day for a picnic in Paris? Answer in one sentence. The control runs the same session on the After proxy with a key minted with metadata.disable_global_guardrails: true (mint). All three sessions showed the same forecast and picnic answer (After, control, Before)

After defers the same tools as the control, and row 4, right after the load, read 97% from cache, like the control. Before deferred no tool, so row 4 read 0% and cost $0.0305 instead of $0.0023

$ SHOT=$S/tip-azure-sol-multi.png $S/run_session.sh tip azure-sol http://127.0.0.1:32637 $S/master.key multi
$ python3 spend_rows.py http://127.0.0.1:$P master.key $m "$S" "$E" spend-tip-azure-sol-multi-raw.json
 # startTime (UTC) status   input output cached  spend ($)  tools(defer) msgs  last user turn                           upstream answered
 1 13:12:31.900 success   1410     79     0%   0.004313  0(0)            1  (title request, no tools)                text
 2 13:12:31.986 success  11545    113     0%   0.028786  13(1)           2  prompt: In one sentence, what does a     text
 3 13:12:43.697 success  11809     33    77%   0.007866  13(1)           5  prompt: What is the weather forecast     tool_search_call
 4 13:12:49.600 success  12021     24    97%   0.002263  14(2)           8  ToolSearch result (1 tool_reference)     mcp__weather__get_forecast
 5 13:12:54.682 success  12102     80    99%   0.002243  14(2)          11  tool_result                              text
 6 13:13:05.379 success  12221     29    99%   0.001836  14(2)          14  prompt: Is Wednesday a good day for      text
6 rows, total spend $0.047307

Control

$ SHOT=$S/tip-azure-sol-multictl.png $S/run_session.sh tip azure-sol http://127.0.0.1:32637 $S/nogr.key multictl
$ python3 spend_rows.py http://127.0.0.1:$P master.key $m "$S" "$E" spend-tip-azure-sol-multictl-raw.json
 # startTime (UTC) status   input output cached  spend ($)  tools(defer) msgs  last user turn                           upstream answered
 1 13:14:31.267 success    754    121     0%   0.002718  0(0)            1  (title request, no tools)                text
 2 13:14:31.357 success  10184    151     0%   0.025764  13(1)           2  prompt: In one sentence, what does a     text
 3 13:14:39.995 success  10486     33    74%   0.007825  13(1)           5  prompt: What is the weather forecast     tool_search_call
 4 13:14:42.003 success  10704     24    97%   0.002145  14(2)           8  ToolSearch result (1 tool_reference)     mcp__weather__get_forecast
 5 13:14:44.189 success  10785     98    99%   0.002291  14(2)          11  tool_result                              text
 6 13:14:51.468 success  10922     27    99%   0.001729  14(2)          14  prompt: Is Wednesday a good day for      text
6 rows, total spend $0.042472

Before

$ SHOT=$S/base-azure-sol-multi.png $S/run_session.sh base azure-sol http://127.0.0.1:24247 $S/master.key multi
$ python3 spend_rows.py http://127.0.0.1:$P master.key $m "$S" "$E" spend-base-azure-sol-multi-raw.json
 # startTime (UTC) status   input output cached  spend ($)  tools(defer) msgs  last user turn                           upstream answered
 1 11:17:56.124 success   1410    101     0%   0.004534  0(0)            1  (title request, no tools)                text
 2 11:17:56.201 success  11568    144     0%   0.029154  13(0)           2  prompt: In one sentence, what does a     text
 3 11:18:04.199 success  11863     33    77%   0.007946  13(0)           5  prompt: What is the weather forecast     tool_search_call
 4 11:18:06.518 success  12108     24     0%   0.030500  14(0)           8  ToolSearch result (1 tool_reference)     mcp__weather__get_forecast
 5 11:18:11.462 success  12189     57    99%   0.002021  14(0)          11  tool_result                              text
 6 11:18:20.387 success  12285     29    99%   0.001787  14(0)          14  prompt: Is Wednesday a good day for      text
6 rows, total spend $0.075942

After still reads about 1,300 to 1,360 more input tokens than the control on rows 2 to 6, and Before carries the same extra. On both legs the guardrail repeats the last system block when Claude Code's billing header block comes first. A 3-block curl reads 2303 input tokens through the guardrail and 1163 without it, and 1163 both ways once the header block is gone, at the tip as at 7ce2004 (tip, 7ce200493b and Before)

Case 3, claude-direct curl with a tool_reference, both legs and Anthropic direct

claude-direct is anthropic/claude-sonnet-5-5. c3-claude.json has ToolSearch up front, mcp__weather__get_forecast with defer_loading: true, and a ToolSearch result that references it (After, Before and direct)

$ curl -s -w "\nHTTP %{http_code}\n" http://127.0.0.1:$P/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "content-type: application/json" -d @c3-claude.json -o out-c3-claude-$L.json; jq -c "$J" out-c3-claude-$L.json

After

HTTP 200
{"type":"message","stop_reason":"tool_use","content":[{"type":"tool_use","name":"mcp__weather__get_forecast","input":{"city":"Paris"},"text":null}],"usage":{"input_tokens":660,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":58,"output_tokens_details":{"thinking_tokens":0},"service_tier":"standard","inference_geo":"global","speed":"standard"},"error":null}

Before

HTTP 200
{"type":"message","stop_reason":"tool_use","content":[{"type":"tool_use","name":"mcp__weather__get_forecast","input":{"city":"Paris"},"text":null}],"usage":{"input_tokens":652,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":58,"output_tokens_details":{"thinking_tokens":0},"service_tier":"standard","inference_geo":"global","speed":"standard"},"error":null}

The same body sent straight to Anthropic counts 660 input tokens with defer_loading and 652 without it (with, without). So After matches Anthropic getting the deferred tool, and Before matches the flag dropped

Round 6 cases and rounds 2 and 4 case 7, After only at the tip, control key so no guardrail runs, as in those rounds

Round 6 case 1. br-kimi-pass is bedrock/chat_completions/us.moonshotai.kimi-k3.1 with deferred_tools: passthrough, and the proxy turns on drop_params for Claude Code requests. What the admin sees in the terminal running the proxy is one warning per request, and both requests answer 200 (full run, round 6 Before)

$ SHOT=$S/tip-br-kimi-pass-short.png $S/run_session.sh tip br-kimi-pass http://127.0.0.1:32637 $S/nogr.key short
13:16:14 - LiteLLM:WARNING: deferred_tools.py:59 - drop_params is on, so LiteLLM falls back instead of answering 400: model_info.deferred_tools passthrough keeps defer_loading on each tool, but the bedrock route LiteLLM uses for chat_completions/us.moonshotai.kimi-k3.1 does not support it. Pick emulate or drop for this deployment, or set drop_params to send deferred tools the drop way
13:16:14 - LiteLLM:WARNING: deferred_tools.py:59 - drop_params is on, so LiteLLM falls back instead of answering 400: model_info.deferred_tools passthrough keeps defer_loading on each tool, but the bedrock route LiteLLM uses for chat_completions/us.moonshotai.kimi-k3.1 does not support it. Pick emulate or drop for this deployment, or set drop_params to send deferred tools the drop way
INFO:     127.0.0.1:54584 - "POST /v1/messages?beta=true HTTP/1.1" 200 OK
INFO:     127.0.0.1:54578 - "POST /v1/messages?beta=true HTTP/1.1" 200 OK

pr54213-6c7d110941-r7-r6case1-tip-br-kimi-pass.png

The same request as a curl answered 400 naming the setting, as in round 6, and 200 with one warning once it sets "drop_params": true

Round 6 cases 2, 3 and 5. Round 6's bodies on nova-pass (Bedrock Converse), gemini-pass and grok-pass (Bedrock) each answered 400 naming the setting, then 200 with a tool_use and one warning with "drop_params": true (curls and console)

Round 6 case 4. One forced ToolSearch turn each on fw-kimi-pass and br-kimi showed the forecast with no error, and br-kimi read 97% right after the load (fw-kimi-pass, br-kimi)

Rounds 2 and 4 case 7, a 5-turn session on azure-sol that loads 3 tools. Rows 4, 7 and 10 follow a load and read 97%, 98% and 98%, where Before read 0% in round 4 (full run)

$ SHOT=$S/tip-azure-sol-long.png $S/run_session.sh tip azure-sol http://127.0.0.1:32637 $S/nogr.key long
$ python3 spend_rows.py http://127.0.0.1:$P master.key $m "$S" "$E" spend-tip-azure-sol-long-raw.json
 # startTime (UTC) status   input output cached  spend ($)  tools(defer) msgs  last user turn                           upstream answered
 1 13:16:46.993 success    747    153     0%   0.003024  0(0)            1  (title request, no tools)                text
 2 13:16:47.075 success  10174      5     0%   0.024279  13(1)           2  prompt: Reply with just the word rea     text
 3 13:16:52.588 success  10330     33    75%   0.007459  13(1)           5  prompt: What is the weather forecast     tool_search_call
 4 13:16:55.524 success  10548     24    97%   0.002130  14(2)           8  ToolSearch result (1 tool_reference)     mcp__weather__get_forecast
 5 13:16:58.557 success  10629     66    99%   0.001955  14(2)          11  tool_result                              text
 6 13:17:06.645 success  10732     33    99%   0.001688  14(2)          14  prompt: What is the air quality in P     tool_search_call
 7 13:17:09.495 success  10950     24    98%   0.001896  15(3)          17  ToolSearch result (1 tool_reference)     mcp__weather__get_air_quality
 8 13:17:12.369 success  11021     25    99%   0.001561  15(3)          20  tool_result                              text
 9 13:17:20.770 success  11083     34    99%   0.001635  15(3)          23  prompt: What time is sunrise in Pari     tool_search_call
10 13:17:24.085 success  11304     25    98%   0.001949  16(4)          26  ToolSearch result (1 tool_reference)     mcp__weather__get_sunrise
11 13:17:26.446 success  11381     23    99%   0.001591  16(4)          29  tool_result                              text
12 13:17:31.881 success  11437     53    99%   0.001846  16(4)          32  prompt: Summarize the three answers      text
12 rows, total spend $0.051013
Earlier runs, kept for history and not carried to this tip

Round 7 at 7ce2004. Case 1, case 2 with its control, case 3, and focused suites at 7ce200493b and b0254a835a

Rounds 2 to 6, before the merge, in the round 6, round 5, round 4, round 3 and round 2 gists. Round 5's gist also holds round 4's cases in files 28 to 37

Surprises
  • Guardrail repeats Claude Code's last system block, both legs. Pre-existing
  • Kimi recovered from Before's error and answered. Gone on After
  • Spend logs show the guardrail's rewritten tools. Pre-existing

Round 6 surprises, seen again at the tip

  • 1.108's Bedrock chat_completions/ Kimi route rejects tools. Pre-existing
  • So the br-kimi-pass turn never calls the weather tool. Pre-existing
  • The warning prints on the tool-free title request too. Caused here
  • Spend logs record CallLoadedTool, not the restored name. Caused here

Type

🆕 New Feature

Caveats (if any)

Medium

  • emulate never ran on a vLLM server serving Kimi, which LIT-11175's "Done when" names
    • QA covers Bedrock and Fireworks Kimi
  • emulate skips the provider's schema check on a loaded tool's input, so a bad call reaches the client as is

Low

  • Azure native puts a pinned chat-era api_version on Responses URLs
  • count_tokens ignores deferred_tools, so emulate over-counts
  • native turns into drop without a warning on compaction requests, which go to chat completions
  • Under drop_params the fallback warning logs on every request
  • The passthrough 400 names Claude Code to every caller
  • Logs, spend and guardrails see CallLoadedTool under emulate
  • Under emulate, a dispatcher call to a non-deferred strict tool comes back as CallLoadedTool, and the model retries. Claude Code sends no strict
  • Azure native spend rows say anthropic_messages, not responses, and streams lack x-litellm-model-api-base
  • A bad value fails per request, not at config load
  • The docs are in litellm-docs#3279, which merges after this PR
Decisions

passthrough is refused by provider, so an openai/ deployment pointed at a self-hosted OpenAI-compatible server gets the same 400 as OpenAI, while hosted_vllm/ goes through. LiteLLM picks per-provider rules such as the supported-params list by the provider prefix, not by api_base, so a server that takes deferral belongs under its own provider. Under drop_params, which Claude Code gets by default, the request falls back to drop instead

Under emulate the proxy does not check a loaded tool's input against its schema. Checking it was the alternative, but a call that fails could only go back as an unknown tool or fail the turn, while passing it through lets the client's tool reject it, as it does a bad call from any model. A dispatcher call to a strict tool the client did not defer is not restored, since the dispatcher's free-form input skips its schema, so the model has to call that tool directly. Checking the input against the schema in the proxy was the alternative, but it would evaluate a client-supplied schema, regex patterns included, inside the proxy

A live-pr-risk run at 0dd87fc found three things. A unified guardrail dropped defer_loading when it wrote the tools back, which broke emulate and turned native off, and 7ce2004 keeps it. A tool name or tool_use_id that is not a string answered 500 instead of the provider's 400, and 7ce2004 fixes that too. native on Azure sends requests to the Responses API, so spend rows and headers differ, but only a deployment that opts into native sees that

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
Large cross-cutting changes to request routing, tool translation, and streaming across the Anthropic messages bridge; misconfiguration is caught early but behavior varies heavily by provider and mode.

Overview
Adds model_info.deferred_tools (passthrough, native, emulate, drop; default drop) so Claude Code ToolSearch and defer_loading survive the /v1/messages bridge without breaking prompt cache or upstream validation.

The messages handler rejects incompatible settings (or falls back when drop_params is on), routes native to Responses with client tool search, and emulate rewrites deferred calls through a CallLoadedTool dispatcher with response/stream restoration. Chat and Responses adapters preserve or strip defer_loading by mode; ToolSearch history is replayed as tool_search_call / tool_search_output on the Responses path. Guardrails round-trip deferral and strip defer_loading when ToolSearch is removed; cache_control marking skips deferred tools. The Rust messages route applies the same refusals before I/O.

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

@martenj4
martenj4 requested a review from a team November 24, 2026 18:44
@veria-ai

veria-ai Bot commented Nov 24, 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: 4 · PR risk: 0/10

Reviews

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

…ol search replay

native now needs a provider with client tool search (azure, fireworks_ai, openai) and wins over the
global chat completions flag. ToolSearch results keep their text and is_error state, a forced
ToolSearch tool_choice answers 400 or drops, emulate forces a deferred tool through the dispatcher,
sync emulate streams work, and an unknown deferred_tools value is refused on every route, the opt-in
Rust messages route included
…apply and quote tool search text

A provider served through its own /v1/messages API now answers 400 for any
deferred_tools value but passthrough, on the Python handler and on the opt-in
Rust messages route, and passthrough on OpenAI answers 400 since OpenAI
rejects defer_loading without its own tool search. Both fall back under
drop_params. A ToolSearch result's text replays as a quoted string labeled as
tool output
… on Azure, and name loaded tools under passthrough

Fireworks' Responses tool search still bills deferred tools as prompt
input, so native now answers 400 there like any provider without client
tool search. passthrough answers 400 on Azure as it does on OpenAI,
since both reject defer_loading outside their own tool search.

Every deferred_tools fallback under drop_params now logs one warning
naming the setting, because Claude Code requests get drop_params on by
default and never see the 400.

Under passthrough a ToolSearch result's tool_reference blocks reach a
chat backend as text naming each loaded tool, instead of an empty tool
result. drop keeps the earlier handling.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect deferred-tool behavior across the `/v1/messages` bridge and several backend routes.

The code fixes the previous strict-tool issue, but the required live QA must cover the latest product commit before merging

Findings

  1. P2 Latest live QA is missing ▶

Summary

Adds per-deployment deferred_tools modes for the /v1/messages bridge

  • Native mode sends tool searches through the Responses API.
  • Chat routes use one dispatcher for tools loaded through search.
  • Each deployment can choose how its route handles deferred tools.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["/v1/messages"] --> B{"Deployment mode"}
    B -->|native| C["Responses tool search"]
    B -->|emulate| D["Fixed tools and CallLoadedTool"]
    B -->|passthrough| E["Keep defer_loading where supported"]
    B -->|drop| F["Send plain tools"]
    D --> G{"Tool allowed for restoration?"}
    G -->|yes| H["Return original tool name"]
    G -->|no| I["Leave dispatcher call unchanged"]
Loading

Reviews (10) · Last reviewed commit: "fix(anthropic): keep strict tools out of..." · Reviewed by Greptile

…ool, close sync streams, and refuse passthrough on Mistral

Port of main commit 837ad2c onto lts/1.108.x, in the pass_through module paths

Under emulate, a CallLoadedTool call now comes back to the client only when it names a deferred tool that a ToolSearch result in the request loaded, or the tool that tool_choice forced. A forced deferred tool also limits the dispatcher's name to that tool. Any other call stays a CallLoadedTool call, so the client never runs a tool it did not load or force

The dispatcher takes the first CallLoadedTool name the caller's tools do not use, and closing a restored sync stream closes the provider stream too, before or during iteration

passthrough on mistral answers 400 naming the setting, or falls back to drop under drop_params, since Mistral's chat API answers 422 on deferred tools
…mulate

Port of main commit 4ac1e85 onto lts/1.108.x, in the pass_through module paths

Under emulate a loaded tool's arguments reach the model as the dispatcher's free-form input, so the provider cannot enforce strict input for it. A deferred tool with strict set now answers 400 naming the setting, or goes without strict under drop_params with the fallback warning, the way an unsupported strict already drops elsewhere. Claude Code sends no strict, so its sessions are unaffected
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

Comment on lines +681 to +683
_refuse_deferred_tools(
None if emulation is None else emulation.strict_input_refusal(), drops_deferred_tools_setting
)

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.

P2 Latest live QA is missing

This changes strict deferred-tool refusals, but completed live QA stops at 78a205df5d. The repository requires proxy-to-provider proof at the latest product commit, 0dd87fcbeb5dd9e272dec965e41aeeca85ea2db8. Finish and attach those runs, covering the changed tool and stream paths, before merging

Rule Used: Apply this rule only to PRs that fix LLM translation bugs or add LLM translation features. LLM translation means converting requests, responses, streaming events, tool calls, and errors between the API a caller uses on LiteLLM (any endpoint or SDK fu... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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.

Live QA round 4 at 0dd87fc is now in the PR body, covering strict, emulate restore, dispatcher rename and sync stream close

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.

Live QA round 5 at 968ccd9, the current tip, is now in the PR body, covering emulate drop billing and the Rust route

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 proof section now covers tip 2030ddd, since live-pr-risk re-ran every changed tool and stream path on real providers at bbf3181 and 2030ddd

Port of 52171f9 from main. The emulate stream wrapper forwarded attributes
through __getattr__, which the proxy's runtime-checkable disconnect billing
protocol does not see, so a client that dropped a streamed /v1/messages request
on an openai/ deployment set to emulate logged no spend. The wrapper now passes
on the inner stream's partial_response_on_disconnect
@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.

…ols passthrough and fall back to drop there

Under drop_params, passthrough on Bedrock Converse, Bedrock native chat, Gemini and Vertex Gemini (vertex_ai_beta included) now sends the same request drop sends
@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.

case "bedrock":
return BedrockModelInfo.get_bedrock_route(model) in ("converse", "converse_like", "chat_completions")
case _:
return False

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.

bedrock_converse skips passthrough refusal

Medium Severity

builds_tools_without_deferral only inspects provider bedrock, so a bedrock_converse/ deployment never matches. passthrough on that provider is not refused and defer_loading is still dropped by Converse's tool builder, so the new per-route 400 never fires.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d8561fb. 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.

bedrock_converse is not a provider prefix here, get_llm_provider rejects bedrock_converse/ models, and Converse models resolve to provider bedrock, which this check covers

…ols passthrough on Vertex

A Vertex deployment routes to Gemini when its base_model names Gemini or when it is a numeric
PSC endpoint with an api_base. The passthrough refusal now reads both, so such a deployment
gets the same 400, or the drop fallback under drop_params, as a Vertex Gemini model name
…and keep non-string tool names out of set lookups
@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.

…ed_tools_per_deployment_lts

# Conflicts:
#	litellm/litellm_core_utils/core_helpers.py
…through check and ignore a non-object tool_choice on deferred tool routes
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…nces instead of silently dropping tool search

The Responses API has no stop_sequences, so a native request carrying them went to chat completions with deferred tools sent the drop way. It now answers 400 naming the way out, and under drop_params falls back with a warning. The guardrail test double now types request_data and logging_obj
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…ponses API

1.108 still sends OpenAI requests with stop_sequences to the Responses API, where native tool search works, so the stop_sequences refusal now applies only to requests that leave it, such as Azure's
…rries ToolSearch

Without ToolSearch, native sends deferred tools the same way drop does, so a stop_sequences request that leaves the Responses API keeps going to chat completions with stop instead of answering 400
…uardrails, native replays and emulate

The tool_config cache point now skips tools with defer_loading, since Anthropic refuses a deferred tool
that carries cache_control. When a guardrail removes the tool search tool, the tools it kept go up without
defer_loading, so they stay callable. A native replay sends a tool's schema only in the first
tool_search_output that loads it. Emulate restores a CallLoadedTool call to any tool the client declared
without deferring it. native with stop_sequences refuses only when the request has tool search and at
least one deferred tool
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

A CallLoadedTool call carries free-form input, so restoring it to a strict tool would skip that tool's
schema. Such a call now goes back unchanged, like a call naming an unknown tool, and the model retries
with the tool itself. The tool_config cache point test now records the request at the wire instead of
replacing the handler
@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

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!

1 issue from previous review remains unresolved.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit 2030ddd. Configure here.

@mateo-berri
mateo-berri merged commit 9378d01 into BerriAI:lts/1.108.x Nov 25, 2026
64 checks passed
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.
yucheng-berri added a commit that referenced this pull request Nov 25, 2026
…s it

lts/1.108.x restores defer_loading by name on tools a guardrail returns (#54213).
The merge took main's write-back, which converts an edited tool without it.
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.

2 participants