Repository navigation
fix(rust): add the dangerous-tool-use beta when an anthropic /v1/messages request carries safeguards - #46102
Conversation
…ages request carries safeguards
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
@litereview code-review |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Azure AI is never Rust-routed through the proxy: litellm/rust_bridge/catalog.py:73 lists anthropic, deepseek, vertex_ai only. Body scope corrected accordingly |
|
@litereview code-review |
|
DeepSeek leg stays unverified: the only DeepSeek key answers 402 Insufficient Balance and the console blocks this box. Tracked as a Medium caveat |
|
@litereview code-review |
…eta map column DeepSeek and the other hosts without a column in anthropic_beta_headers_config.json keep forwarding safeguards and client betas as sent. Adds the wire-level audit tests.
|
@litereview code-review |
…c_safeguards_beta
|
@litereview code-review |
Azure AI and Claude Platform Messages transforms now add the dangerous-tool-use beta for a non-null safeguards field, through the Azure AI and Anthropic beta-map columns. The safeguards wire and chaos tests get unique file names so they do not collide with the Python fix's tests, the Python-route test asserts the fixed behavior behind a BUG skip, and the DeepSeek test checks that no beta is added
|
@litereview code-review |
[Medium impact] The PR appears safe to merge, with no new actionable issues found SummaryRust adds the safeguards beta for supported Anthropic-compatible hosts. The latest changes also remove null
Reviews (5) · Last reviewed commit: "test: cover Bedrock Mantle in the null s..." · Reviewed by Greptile |
…ute can prove it Claude Platform has no beta-map column and no QA account, so it goes back to sending safeguards with no derived beta, like DeepSeek. Also release held chaos-test requests before the thread pool waits on them, and mark the no-column test as rstest.
|
@litereview code-review |
1 similar comment
|
@litereview code-review |
1 similar comment
…e null-cell test off Databricks Claude Platform on AWS answers 400 to safeguards without dangerous-tool-use-2026-09-03 and 200 with it, so its Messages transform derives the beta through the Anthropic column again. The null-cell case now uses only Bedrock Converse, since Databricks support for the beta is changing in a sibling PR.
|
@litereview code-review |
…ts beta Anthropic rejects any safeguards key, null included, when the dangerous-tool-use beta is missing, so an explicit "safeguards": null on the Rust gateway still answered 400. The shared Messages transform now drops a null safeguards key on every host, as the proxy already drops None params before calling Rust, so it answers 200 with no beta. The scripted peer in the integration wire tests now rejects the key on presence, matching the real API.
|
@litereview code-review |
…vendor's non-list wording The Rust null-safeguards regression test now also runs for bedrock_mantle, whose beta is keyed on the field being present. The scripted Anthropic peer answers a non-list safeguards value with the real API's "valid array" wording.
|
@litereview code-review |
|
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 78e110d. Configure here.
…ages request carries safeguards (BerriAI#46102) Backport of BerriAI#46102 to stable/1.106.x. Cherry-picked from 5b042c0 (main). Adapted to the line: only the anthropic Messages config is ported (a non-null safeguards field adds dangerous-tool-use-2026-09-03), with its unit cases. The azure_ai, claude_platform, deepseek and vertex_ai Messages files, the beta-map provider plumbing, and the Rust integration tests are not part of this backport.
…ages request carries safeguards (BerriAI#46102) Backport of BerriAI#46102 to stable/1.105.x. Cherry-picked from 5b042c0 (main). Adapted to the line: only the anthropic Messages transform is ported (shared by azure_ai, whose beta-map cell supports the beta here), as a minimal change since the line has no BetaProvider mapping; the claude_platform, deepseek and vertex Rust transforms and the Rust integration tests are not on the line and are dropped. Not compiled locally.
…ages request carries safeguards (BerriAI#46102) * fix(rust): add the dangerous-tool-use beta when an anthropic /v1/messages request carries safeguards * test(rust): check the dangerous-tool-use beta reaches the wire with safeguards * fix(rust): derive the dangerous-tool-use beta only for hosts with a beta map column DeepSeek and the other hosts without a column in anthropic_beta_headers_config.json keep forwarding safeguards and client betas as sent. Adds the wire-level audit tests. * fix(rust): add the safeguards beta on Azure AI and Claude Platform hosts Azure AI and Claude Platform Messages transforms now add the dangerous-tool-use beta for a non-null safeguards field, through the Azure AI and Anthropic beta-map columns. The safeguards wire and chaos tests get unique file names so they do not collide with the Python fix's tests, the Python-route test asserts the fixed behavior behind a BUG skip, and the DeepSeek test checks that no beta is added * fix(rust): keep Claude Platform out of the safeguards beta until a route can prove it Claude Platform has no beta-map column and no QA account, so it goes back to sending safeguards with no derived beta, like DeepSeek. Also release held chaos-test requests before the thread pool waits on them, and mark the no-column test as rstest. * fix(rust): derive the safeguards beta for Claude Platform and keep the null-cell test off Databricks Claude Platform on AWS answers 400 to safeguards without dangerous-tool-use-2026-09-03 and 200 with it, so its Messages transform derives the beta through the Anthropic column again. The null-cell case now uses only Bedrock Converse, since Databricks support for the beta is changing in a sibling PR. * fix(rust): drop a null safeguards key instead of sending it without its beta Anthropic rejects any safeguards key, null included, when the dangerous-tool-use beta is missing, so an explicit "safeguards": null on the Rust gateway still answered 400. The shared Messages transform now drops a null safeguards key on every host, as the proxy already drops None params before calling Rust, so it answers 200 with no beta. The scripted peer in the integration wire tests now rejects the key on presence, matching the real API. * test: cover Bedrock Mantle in the null safeguards case and match the vendor's non-list wording The Rust null-safeguards regression test now also runs for bedrock_mantle, whose beta is keyed on the field being present. The scripted Anthropic peer answers a non-list safeguards value with the real API's "valid array" wording. --------- Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com> (cherry picked from commit 5b042c0)
TLDR
Problem this solves:
/v1/messagesrequests withsafeguardsand noanthropic-betaheader get 400safeguards: Extra inputs are not permittedextra_bodyand curl callers, while Claude Code sends the beta itselfHow it solves it:
dangerous-tool-use-2026-09-03whensafeguardsis set, filtered through the beta map'santhropic,vertex_aiandazure_aicolumns, with Claude Platform readinganthropicanthropicandvertex_ai, and the Rust gateway also forazure_aiandbedrock/claude_platform. Vertex drops its own copyRust now drops an explicit
"safeguards": nullon every host, Mantle included, as the proxy drops None params, so it gets 200 with no beta. Adding the beta would send it for a feature the caller turned off. A malformed value gets Anthropic's own 400. Rust Bedrock Invoke is untouchedUser Flow
Before: a developer sending
safeguardsthrough a Rust-routed Anthropic deployment gets a 400 every timeLITELLM_RUST=trueand ananthropic/claude-sonnet-5-5deployment"safeguards": [{"type": "dangerous_tool_use", ...}]and noanthropic-betaheadersafeguards: Extra inputs are not permitted, while the request withoutsafeguardsgets 200After: the same request gets 200 with the classifier's verdict
safeguard_resultson the message or the streamingmessage_delta/statusatAuto mode server: EnabledPre-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
Last updated: 78e110d. QA and /live-pr-risk ran on 0906914, the last commit with a product diff
Each proxy leg ran with
LITELLM_RUST=true,--num_workers 2and no database, against real Anthropic and Vertex AI. The proxy does not sendazure_aiorbedrock/claude_platformto Rust, so those rows ran the Rust gateway against real Azure AI Foundry and Claude Platform on AWSextra_body"safeguards": null"safeguards": nullAnthropic, safeguards (headline)
LITELLM_RUST=true litellm --config config.yaml --num_workers 2 --port <port>payload_safeguards.json(safeguardsplus a Bash tool) withcurland noanthropic-betaheaderconfig.yaml and payload_safeguards.json
payload_safeguards_stream.jsonadds"stream": true,payload_control.jsondropssafeguards, and the Vertex payloads swap the model tovertex-claude-sonnet-5-5{ "model": "claude-sonnet-5-5", "max_tokens": 64, "messages": [ { "role": "user", "content": "Reply with the single word ok" } ], "tools": [ { "name": "Bash", "description": "Run a shell command", "input_schema": { "type": "object", "properties": { "command": { "type": "string" } }, "required": [ "command" ] } } ], "safeguards": [ { "type": "dangerous_tool_use", "classifier_context": { "v": 1, "permission_mode": "auto" } } ] }x-litellm-rust: truemarks a Rust answer, and the control case shows Rust serves both legsBefore (aa32e4c):
After (0906914):
Other cases
Anthropic, safeguards, streaming
Before (aa32e4c):
After (0906914):
Anthropic, no safeguards (control)
Before (aa32e4c):
After (0906914):
Anthropic SDK 1.15.0, safeguards in extra_body
Before (aa32e4c):
After (0906914):
SDK 1.15.0's streamed final message omits
safeguard_results, which is not this PRsdk_case.py
Vertex AI, safeguards
Before (aa32e4c):
After (0906914):
Vertex AI, safeguards, streaming
Before (aa32e4c):
After (0906914):
Azure AI through the Rust gateway
Each leg built the gateway with
cargo build --locked --manifest-path litellm-rust/Cargo.toml -p litellm-gatewayin its worktree and started it withLITELLM_CONFIG=gateway.yaml HOST=127.0.0.1 PORT=<port> litellm-gateway, withLITELLM_MASTER_KEY,AZURE_API_BASE(the Foundry resource) andAZURE_API_KEYin its env. The payloads are the Anthropic ones with the model set toazure-claude-sonnet-5-5. The gateway sets nox-litellm-rustheader, since all of it is RustBefore (aa32e4c):
After (0906914):
Before (aa32e4c):
After (0906914):
Before (aa32e4c):
After (0906914):
Before (aa32e4c):
After (0906914):
Claude Platform on AWS through the Rust gateway
Each leg built the gateway with
cargo build --locked --manifest-path litellm-rust/Cargo.toml -p litellm-gatewayin its worktree and started it withLITELLM_CONFIG=gateway.yaml HOST=127.0.0.1 PORT=<port> litellm-gateway, withLITELLM_MASTER_KEY,AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_DEFAULT_REGION=us-west-2andANTHROPIC_AWS_WORKSPACE_IDin its env. The payloads are the Anthropic ones with the model set tocp-claude-sonnet-5-5Before (aa32e4c):
After (0906914):
Before (aa32e4c):
After (0906914):
Before (aa32e4c):
After (0906914):
Before (aa32e4c):
After (0906914):
Claude Code 2.1.299 auto mode
Claude Code ran in tmux with
ANTHROPIC_BASE_URLset to each leg's proxy, modelclaude-sonnet-5-5, and auto mode on. It was asked to readnotes.txtand then runecho hello from the gatewaywith Bash. Both legs finished the turn with no permission prompt, and/statusshowsAuto mode server: Enabledon both, since Claude Code sends the beta header itself. The screenshots show the turn, notsafeguard_results, which curl and the SDK showBefore (aa32e4c):
After (0906914):
Audit round 1 of 3
PASS at 0906914 against merge base aa32e4c. Of the 23 selected integration cells, 13 were red and 10 green on the base, all 23 were green in two head runs with the same seeds, and the 3 Rust messages controls stayed green
Live cells used claude-sonnet-5-5 against the real vendors through both proxies (Anthropic, and Vertex at the global location) and both standalone Rust gateways (Azure AI Foundry and Claude Platform). Every base 400 was
safeguards: Extra inputs are not permittedThe real API answers a non-list value with
safeguards: Input should be a valid array, so the scripted peer now uses that wording. The Rust null-drop crate case now also covers bedrock_mantle, whose beta is keyed on the field being present. The Rust unit and crate tests for every changed host pass at the head/live-pr-risk at 0906914
Verdict: PASS. Every base vs head difference is one the PR names. Safeguards requests that Anthropic rejected now answer 200 on the Rust path, and the standalone gateway now drops a null
safeguardskey that the base forwardedThe rig ran base aa32e4c and head 0906914 with
LITELLM_RUST=true, two workers, and one Postgres per side. Recorders sat in front of every upstream. The proxy reached Anthropic, Vertex (global) and DeepSeek. The standalone gateway reached those three plus Mantle, MiniMax and Tencent. Upstream attempt counts and credential headers match on both sides. A merged tree (current main plus the PR, clean merge) matched the head on 9 top cells. The 15 related integration files passed at the tip (322 passed, 6 skipped, each skip a known bug marker)Breaking
None found
Backward incompatible
All six are what the PR intends. Spend rows follow the status, so Sonnet successes went from 4 to 11 of 16 on the proxy
Regression risk
/v1/messages, safeguardsanthropic-betaDependency graph
No proxy path reaches azure_ai or claude_platform through Rust, because
catalog.pysends only anthropic, deepseek and vertex_ai there. The PR changes no Python code, so the Python Messages path is unchangedNot verified
The driver ran the Rust unit tests at the tip before the commit, 2101 passed and 0 failed
Type
🐛 Bug Fix
Caveats (if any)
Low
safeguardsuntil fix(anthropic): add the dangerous-tool-use beta when a /v1/messages request carries safeguards #43955 merges. Left as is because fix(anthropic): add the dangerous-tool-use beta when a /v1/messages request carries safeguards #43955 is that fixsafeguards, while Rust drops the key. Left as is because both get 200 and that path is out of scopeFinal Attestation
Bugbot summary