Repository navigation
fix(responses): backport Claude tool search replay to lts/1.108.x - #53007
mateo-berri merged 19 commits into
Conversation
Claude tool search on /v1/responses now returns a tool_search_output after each tool_search_call, streamed and not, listing the tools the search loaded as the caller sent them A stateless follow-up sends the search back to Anthropic as the server_tool_use and tool_search_tool_result Claude produced, and the Anthropic request drops a replayed search whose loaded tools are no longer sent, so a changed tool list no longer answers 400 The guardrail write-back for SDK output items reads part text through a typed helper, so the new output item type adds no attribute errors (cherry picked from commit beedaab)
The streamed tool_search_output item was announced at the end of the stream with an output index reserved earlier, so output_item.added events arrived as 0, 2, 1 and the OpenAI SDK's stream helper raised IndexError. The item is now emitted when Claude's search result arrives. (cherry picked from commit e610512)
A tool name Anthropic cannot take gets rewritten on the request, so Claude's tool_search_tool_result named the rewritten tool. The response now maps those tool references back to the caller's names, streamed and not, and a replayed search result maps them forward again on the next turn. (cherry picked from commit 5d56e18)
Regenerates the lazy OpenAPI snapshot and the dashboard API types for the tool_search_output item the picks add to the Responses API output union
A follow-up sent to a route that cannot run tool search, a Claude model without it included, now leaves out the replayed search the way it did before, instead of sending Claude search blocks that model cannot take. The stateless gate and the stored-turn filter now use the same check that already decides whether the tool_search tool itself is kept A streamed tool_search_call now gets its output_item.done when Claude's search result arrives, so it finishes before its tool_search_output. Clients that build history from done events, like Codex, kept the output ahead of its call (cherry picked from commit 3e61760)
…'s own search tool A Claude model the cost map does not flag for tool search still runs it when the request carries Anthropic's own tool_search_tool_regex or bm25 tool, which is how turn 1 already decides to keep it. Both replay gates now follow that rule, so a stored follow-up on such a model keeps Claude's search as it did before, and a stateless one replays it (cherry picked from commit 24bc04e)
…rriAI#50280's merge left on lts/1.108.x Ruff answers F811 and F601 on the line's tip, so make lint fails for every PR onto it. The kept class is the wider one that also takes bytes replies, and no test outcome in either file changes. (cherry picked from commit 27c77ef)
(cherry picked from commit 0274d84)
… prune only missing tools A replayed Claude tool search now reaches pre-call guardrails and the Purview DLP scan with its search arguments, a stale search drops only the tool references the follow-up no longer sends, and the stored previous_response_id path keeps the base gate for routes the cost map does not flag
…when it still sends a search tool A store false follow-up that sent no search tool still got the search replayed, and Claude then said it called a tool it no longer had. Same change as fe560fc on the main branch
… still sends a search tool A previous_response_id follow-up that sent no search tool still got the stored search, the same gap a store false follow-up had. The stale search pruning now logs the tools it leaves out at debug level. Same change as 0a748dd on the main branch.
…all id The guardrail test reused toolu_01Weather, an id that streaming and bridge tests already put in the process-wide TOOL_CALLS_CACHE. When one of those ran first in the same worker, the guardrail write-back took its rebuild path and the test failed for a reason unrelated to the replayed search. (cherry picked from commit 6d49b25)
…nd stored follow-ups A search-only assistant turn now gets its search result renamed to the sanitized tool names too, so the stale-tool trim no longer drops it. Stored follow-ups on Claude routes replay the search as base did, trimmed to the tools still sent, and Bedrock invoke sends the tool search beta whenever the history holds a search (cherry picked from commit 0a27b5b)
… a follow-up without a search tool (cherry picked from commit afa708b)
A chat history whose search result used the request's tool names (weather.get) got Anthropic's 400 when replayed on a proxy still on the old code, during a rolling deploy or a rollback. Chat completions now returns Claude's search result as main does, and the Responses bridge maps a rewritten name back to the request's tool when it builds tool_search_output. That also fills tool_search_output on Bedrock invoke streams, which carry no name map (cherry picked from commit 4249121)
The line keeps Claude's search in tool_calls, so the picked fixtures store it there, and the chat test file drops the duplicate and unrelated tests the conflict resolution brought in from main
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…rt_claude_tool_search_replay_lts_1_108_x # Conflicts: # litellm/llms/anthropic/chat/transformation.py
…rt_claude_tool_search_replay_lts_1_108_x
PR overviewThis PR backports Claude tool search replay support to lts/1.108.x, including handling replayed search calls in the Responses guardrail translation path. One issue remains open: replayed search arguments are absent from the flat-text inputs inspected by text-based guardrails, allowing PII in a search pattern to reach Claude unchanged. Exploitation requires tool search to be enabled and the referenced tool to remain available. No issues have been addressed yet. Open issues (1)
Fixed/addressed: 0 · PR risk: 5/10 Reviews
|
| messages: Final = LiteLLMCompletionResponsesConfig.transform_responses_api_input_to_messages( | ||
| input=input_data, | ||
| responses_api_request=data, | ||
| replay_tool_search=True, |
There was a problem hiding this comment.
Medium: Replayed search arguments bypass text-based guardrails
Enabling replay here exposes search arguments only in structured_messages: _extract_input_text_and_images() extracts content alone, while built-in guardrails such as Presidio inspect only inputs["texts"]. With tool search enabled and the referenced tool still available, a caller can submit a completed srvtoolu_* search call/output pair containing PII in arguments.pattern and have it forwarded unchanged to Claude; include replayed arguments in the flat-text scan and write masked values back before replay.
There was a problem hiding this comment.
Input function_call arguments skip the flat-text scan on this line too. Search calls follow the same rule, and structured-message guardrails still see both
[Medium impact] The PR appears safe to merge with the explicitly accepted limits
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
1 similar comment
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 0aac632. Configure here.
On the 1.108 LTS line, Claude's tool search through
/v1/responsesis lost on the next turn, and a follow-up without a tool the search loaded fails with Anthropic's 400This brings the same fix as #50821 to the line
Original
TLDR
Problem this solves:
tool_search_outputfor Claude's searchstore: falsefollow-ups drop Claude's searchHow it solves it:
tool_search_outputfrom the request's tools and their names, streamed and notstore: falseturns that still send a search tooltool_search_call's arguments to guardrails and Purview DLPIntentional product change: a replayed search keeps only the loaded tools a follow-up still sends, where Anthropic answered 400, and is left out when none remain, on
/v1/chat/completionstooBackport checklist
tool_callstool_search_output. Two picks conflicted intransformation.pyand keep the line's names, since it has no native compaction. 0a27b5b conflicted in the Responsestransformation.pyand keeps the line's stored-message check. 4249121 conflicted inhandler.py, which goes back to its base version, as main's change does. 6e11cc5 stores Claude's search intool_callsin the picked tests, as the line does, and drops tests the conflict brought in from main. 0aac632 keeps both sides of an import conflict incommon_utils.pyenterprise/orlitellm-proxy-extras/change, so no package bumpbeedaabb87313a02a507e610512b05ea4e2f2cd05d56e180cad431a5b9ac3e617601982f165e690a24bc04e65b0bd6d58fde0274d8496bdb4dd174b2192a6eed2b16d1f96345fe560fc86f228b7c246f0a748dd66009973046e06d49b2509f0c8fe27e580a27b5b8031b4d8ed81eafa708bb43402cad739b4249121c2f427d4eb383Relevant issues
Part of #50104, the search record lost on later turns
User Flow
Before: a developer using OpenAI tool search on Claude through
/v1/responsesloses the search on later turns, and a changed tool list failstoolsholding{"type": "tool_search"}plus deferredget_weatherandget_local_time, asking for the weather in Paristool_search_callthenfunction_call get_weather, but notool_search_outputnaming the loaded tools, streamed or not"store": false, replaying every turn 1 item plus afunction_call_output, and Claude says it ran no tool searchprevious_response_idand without a tool the search loaded, and get HTTP 400 "Tool reference '' not found in available tools"After: turn 1 returns the search result, Claude remembers its search on turn 2, and a changed tool list still answers 200
tool_search_outputlisting the loaded tools, streamed or not"store": falseturn 2, and Claude lists the tool search it ran and what it foundprevious_response_idturn 2 and get HTTP 200, and Claude's search keeps every loaded tool still sentPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays 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
Each leg ran the curl scripts on Anthropic
claude-sonnet-5-5and Vertex AI, and the reporter's Agents SDK client on Bedrock Sonnet 5.5 and Opus 5, against one proxy with Postgres and one worker, since--reloadignores--num_workerson this lineProxy command, config.yaml, and env var names
The proxy reads
ANTHROPIC_API_KEY,GOOGLE_APPLICATION_CREDENTIALS(a service account key file),VERTEXAI_PROJECT,LITELLM_MASTER_KEY,DATABASE_URL(a fresh Postgres database per leg),LITELLM_LOCAL_MODEL_COST_MAP=True, andLITELLM_PRISMA_COMMAND_TIMEOUT=600. Bedrock calls use the default AWS profile, an SSO role with Bedrock inference, and no AWS env vars. The scripts readINTEGRATION_PROXY_URLandINTEGRATION_MASTER_KEY.agents_qa.pyruns onopenai-agents==0.24.0qa.sh (cases 1 to 5), qa-bm25.sh (cases 6 to 8), qa-nosearch.sh (cases 9 and 10), and agents_qa.py
The Vertex AI runs use
qa.shandqa-nosearch.shwithvertex-claude-sonnet-5-5in place ofclaude-sonnet-5-5tool_search_outputtool_search_outputat index 1, in orderstore: falseturn 2get_weatheror every tool goneget_weathergonetool_search_outputstore: falseturn 2tool_search_tool_bm25get_local_timegoneget_weatherweather_getweather.getstore: falseturn 2tool_namespacetoolsBefore (831a14c)
Raw, unedited output of each script above, agents_qa.py once per model
qa.sh
qa-bm25.sh
qa-nosearch.sh
agents_qa.py
agents_qa.py on Opus 5
qa.sh on Vertex AI
qa-nosearch.sh on Vertex AI
After (0997304)
Raw, unedited output of each script above, agents_qa.py once per model
qa.sh
qa-bm25.sh
qa-nosearch.sh
agents_qa.py
agents_qa.py on Opus 5
qa.sh on Vertex AI
qa-nosearch.sh on Vertex AI
Last updated: 0aac632. QA ran on 0997304. Changes since QA: three picks from main, a test fit, and three merges of lts/1.108.x. The newest merge changed this PR's files, so the smoke ran again. Verification: the smoke below ran on 0aac632
Smoke, 2c6736f and 0aac632
Before and after table, commands, and where the raw output is
Before is the branch's new merge base with lts/1.108.x. qa.sh and agents_qa.py ran unchanged on Anthropic
claude-sonnet-5-5, each proxy with 2 workers and its own Postgres. The raw output of both legs is in this gist as5-before-2c6736fdfc.mdand6-after-0aac632864.md, beside cases 10 and 13 from 831a14c and 6e11cc5tool_search_outputstore: falseturn 2get_weatheror every tool goneget_weathergonetool_namespacetoolsEach leg ran these two commands from its tree, with
Qpointing at the gist checkoutCase 4 with
get_weathergone from turn 2 is the headline. Before, on 2c6736fAfter, on 0aac632
Type
🐛 Bug Fix
Caveats (if any)
Medium
tool_namespacetools workLow
store: falsefollow-ups still drop Claude's search and stored ones replay it, as on base, since replaying made Claude claim a tool it lacked and dropping breaks stored follow-ups that workweather_get, notweather.get, as on basetool_referenceto a dropped tool still gets Anthropic's 400, as on baseFinal Attestation
Bugbot summary