Skip to content

fix(anthropic): add the dangerous-tool-use beta when a /v1/messages request carries safeguards - #43955

Merged
mateo-berri merged 13 commits into
mainfrom
litellm_azure_ai_safeguards_dangerous_tool_use_beta
Oct 17, 2026
Merged

mateo-berri merged 13 commits into
mainfrom
litellm_azure_ai_safeguards_dangerous_tool_use_beta

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Claude Code auto mode through an Azure AI Foundry Claude deployment fails at a default proxy config
  • The client's anthropic-beta: dangerous-tool-use-2026-09-03 never reaches Foundry (azure_ai is not a header-forwarding provider)
  • Foundry answers 400 to the safeguards body field, so Claude Code silently falls back to its client-side classifier
  • fix(anthropic): forward the dangerous-tool-use beta to Azure AI Foundry #43934 only mapped the beta for the forward_client_headers_to_llm_api: true case

How it solves it:

  • The proxy derives the beta from the request body: safeguards present adds dangerous-tool-use-2026-09-03
  • Only providers whose column in the bundled anthropic_beta_headers_config.json supports the beta get it (anthropic, which the Claude Platform on AWS also reads, and azure_ai), so this check never fetches anything
  • A safeguards request to azure_ai, which filters betas, loads the remote beta map once per worker on its own thread, so a cold burst never holds the threads chat completions use. No other request fetches the map because of this PR
  • Providers with no column for it (github_copilot, Eden AI, OpenAI-compatible JSON providers) keep today's wire
  • additional_drop_params now applies before the headers are built, so a dropped param such as safeguards or context_management sends neither the field nor its beta
  • Regression tests cover the derived beta, the beta map gate, the drop on every native Claude provider, and which requests fetch the map
Alternatives considered and the github_copilot decision

Adding azure_ai to the proxy's list of providers whose client anthropic-* headers are forwarded would push every client anthropic header to every azure_ai deployment, Claude or not, and would still leave the fix dependent on the client sending the header. An azure_ai-only header merge (the shape stable took in #43662) duplicates the merge the shared beta derivation already does and, on main, needs two mutable-collection suppressions, so the check went into the shared derivation instead. The check keys on safeguards being present and not null, the same test the derivation applies to context_management and output_format, so a non-array value now gets the provider's own validation error (safeguards: Input should be a valid array) instead of the unknown-field 400, and an empty array is left to the provider (200 on Foundry). Deriving only for a non-empty array was the alternative and was not taken, since it would hide a client's malformed value behind the pre-fix error

The derivation is gated on the beta map through is_beta_header_supported_by_bundled_config, which reads the copy of the map shipped with the release, so a provider gets the derived beta only where the map already says it accepts it. The OpenAI-compatible JSON providers inherit the anthropic provider name in this code path, so they look up the openai_like column, which has no entry for the beta. The alternative was a deny list of providers that skip the derivation, which an earlier commit had for github_copilot alone. It was not taken because every provider with no filter (Sail, Meta, Prism, Eden AI, and any JSON provider added later) would start receiving a beta nobody verified they accept. A provider that supports it later gets it by adding its column

The gate reads the bundled map and not the remote copy the provider filter loads. With the remote copy, anthropic and the Claude Platform on AWS fetched it on their first safeguards request, which the merge base never did, and a slow or blocked GitHub held that request for up to 5 seconds. The cost is that a provider column added only to the remote map reaches the derivation at the next release, while the filter still applies the remote copy, so a beta the remote map removes is still dropped. The alternatives were the remote copy with a fetch for every provider, or switching the filter to the bundled copy too. The first brings the fetch back, and the second changes how every beta is filtered, which this PR does not need

The remote map load for filtering providers runs on a dedicated one-thread executor and not on asyncio.to_thread. With the shared default executor, each cold request waiting on the load held one of its threads, and litellm.acompletion runs on those same threads, so 40 cold requests delayed an unrelated chat completion by about 3 seconds. The alternative was a per-worker async lock around the load, which still blocks the event loop when a sync caller holds the lock

additional_drop_params used to run after the headers were built, so a deployment that drops safeguards would still have sent the derived beta with no field to go with it. Dropping the params first means every derived beta, and every header built from a body param, follows the body that is actually sent. The alternative was to strip the beta again after the drop, which would need a second list of which beta belongs to which param and would miss the next derived beta

github_copilot has no column in the beta map, so a Copilot request with safeguards goes out exactly as it does today: safeguards in the body and no derived beta header. Nothing on hand can show whether Copilot accepts that beta on its Claude models, since the only Copilot login available is a Copilot Free account that Copilot serves no Claude model to. The alternatives were deriving it for Copilot too and verifying with a teammate's Copilot Pro or Business token, or adding a Copilot column unverified. Neither was taken, because a wrong guess turns a Copilot turn that works today into a 400, while leaving Copilot alone keeps today's behavior and can be widened later by adding its column once a Copilot account with Claude access can verify it

safeguards sent to an anthropic/ model over /v1/chat/completions or /v1/responses still goes out without the beta and gets Anthropic's 400, exactly as on the merge base. Deriving the beta there alone would turn that 400 into a 200 that silently loses the verdict, since neither response shape carries safeguard_results yet. The alternatives were deriving the beta on those paths now, or deriving it and mapping safeguard_results into both response shapes. Neither was taken here, because the reported flow is Claude Code on /v1/messages and the mapping is its own change, so a follow-up ticket tracks both together

User Flow

Before: a developer running Claude Code in auto mode against the proxy's Azure AI Foundry Claude deployment gets the client-side classifier instead of the server one

  1. They start claude --permission-mode auto --model claude-sonnet-5-5 with ANTHROPIC_BASE_URL=https://litellm-domain and ask it to read notes.txt and then run echo hello from the gateway with the Bash tool
  2. Claude Code sends POST https://litellm-domain/v1/messages?beta=true with safeguards in the body and anthropic-beta: ...,dangerous-tool-use-2026-09-03
  3. Foundry answers 400 safeguards: Extra inputs are not permitted, so Claude Code silently retries the same request without safeguards
  4. The Bash tool runs on Claude Code's own classifier with no Allowed by auto mode classifier line, and /status shows Auto mode server: Disabled

After: the same session gets the server-side classifier with no proxy config change

  1. They start claude --permission-mode auto --model claude-sonnet-5-5 with ANTHROPIC_BASE_URL=https://litellm-domain and ask it to read notes.txt and then run echo hello from the gateway with the Bash tool
  2. Claude Code sends POST https://litellm-domain/v1/messages?beta=true with safeguards in the body and anthropic-beta: ...,dangerous-tool-use-2026-09-03
  3. Foundry answers 200 with safeguard_results in the response
  4. The Bash tool output shows Allowed by auto mode classifier and /status shows Auto mode server: Enabled

Linear ticket

Part of LIT-8284

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

Both legs drive Claude Code in a terminal against the same two-worker proxy config with Foundry Claude deployments, booted from different commits

Rig and commands

Both legs ran on 2026-10-17 the same way: a proxy with --num_workers 2 and no database (127.0.0.1:23901 from the merge base aa32e4c, 127.0.0.1:48897 from 39fc45d), a config with three azure_ai deployments on one Azure AI Foundry resource (claude-sonnet-5-5, claude-opus-5-5, claude-opus-5) and no general_settings (so no client header forwarding), and Claude Code v2.1.299 started in a terminal as claude --permission-mode auto --model <model> with ANTHROPIC_BASE_URL=http://127.0.0.1:<port>, the proxy key as ANTHROPIC_AUTH_TOKEN, and ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-sonnet-5-5. The prompt is Read notes.txt, then use the Bash tool to run: echo hello from the gateway, followed by /status. The curl sends the request shape Claude Code sends, with safeguards in the body and the client's anthropic-beta header carrying dangerous-tool-use-2026-09-03

curl -sS -w '%{http_code}\n' http://127.0.0.1:<port>/v1/messages \
  -H "x-api-key: $LITELLM_KEY" -H 'content-type: application/json' -H 'anthropic-version: 2023-06-01' \
  -H 'anthropic-beta: claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14,context-management-2025-06-27,dangerous-tool-use-2026-09-03' \
  -d '{"model":"<model>","max_tokens":256,"stream":false,"safeguards":[{"type":"dangerous_tool_use","classifier_context":{"v":1,"permission_mode":"auto"}}],"tools":[{"name":"Bash","description":"Runs a shell command","input_schema":{"type":"object","properties":{"command":{"type":"string"}},"required":["command"]}}],"messages":[{"role":"user","content":"Use the Bash tool to run: echo hello"}]}'
Case Before (aa32e4c) After (39fc45d)
Claude Code, Sonnet 5.5 client-side classifier Allowed by auto mode classifier
Claude Code, Opus 5.5 client-side classifier Allowed by auto mode classifier
/status, both models Auto mode server: Disabled Auto mode server: Enabled
curl, Sonnet 5.5 400 200 with safeguard_results
curl, Opus 5 400 200 with safeguard_results

Before (aa32e4c, the merge base)

  1. Boot the proxy from aa32e4c, start Claude Code against it as above, and send the prompt

  2. The Bash tool runs on Claude Code's own classifier with no Allowed by auto mode classifier line (Sonnet 5.5, then Opus 5.5)

    pr43955-ddabcb2dd4-before_sonnet_bash.png
    pr43955-ddabcb2dd4-before_opus_bash.png

  3. /status shows Auto mode server: Disabled

    pr43955-ddabcb2dd4-before_sonnet_status.png
    pr43955-ddabcb2dd4-before_opus_status.png

The curl: 400 on both models, the error Claude Code swallows before it retries without safeguards

Raw output, the response body followed by the status code from -w

claude-sonnet-5-5

{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: Azure_aiException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"safeguards: Extra inputs are not permitted\"},\"request_id\":\"req_011Cg77wEd7jcJ3WFCqPkQPH\"}\n\nLiteLLM: model group 'claude-sonnet-5-5' failed with the error above. No fallback was attempted."}}400

claude-opus-5

{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: Azure_aiException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"safeguards: Extra inputs are not permitted\"},\"request_id\":\"req_011Cg75e65hvQMrFDsACRKLC\"}\n\nLiteLLM: model group 'claude-opus-5' failed with the error above. No fallback was attempted."}}400

After (39fc45d)

  1. Boot the proxy from 39fc45d with the same config, start Claude Code the same way, and send the prompt

  2. The Bash tool output shows Allowed by auto mode classifier (Sonnet 5.5, then Opus 5.5)

    pr43955-39fc45d7ef-after_sonnet_bash.png
    pr43955-39fc45d7ef-after_opus_bash.png

  3. /status shows Auto mode server: Enabled

    pr43955-39fc45d7ef-after_sonnet_status.png
    pr43955-39fc45d7ef-after_opus_status.png

The curl: 200 with safeguard_results on both models

Raw output, the response body followed by the status code from -w

claude-sonnet-5-5

{"model":"claude-sonnet-5-5","id":"msg_011Cg7KNPG1a82q1YmanWVAX","type":"message","role":"assistant","content":[{"type":"tool_use","id":"toolu_017xqU5NWLw9VeBtn8fupQma","name":"Bash","input":{"command":"echo hello"},"caller":{"type":"direct"}}],"container":null,"stop_reason":"tool_use","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":377,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":50,"output_tokens_details":{"thinking_tokens":0},"service_tier":"standard","inference_geo":"global","speed":"standard"},"diagnostics":null,"safeguard_results":[{"type":"dangerous_tool_use","status":{"type":"available","tool_uses":{"toolu_017xqU5NWLw9VeBtn8fupQma":{"type":"evaluated","outcome":"not_flagged"}}}}]}200

claude-opus-5

{"model":"claude-opus-5","id":"msg_011Cg7KNWU5y1Mmvy71Cb3zG","type":"message","role":"assistant","content":[{"type":"text","text":"I'll run that command for you."},{"type":"tool_use","id":"toolu_017ESS4iEgftPT8JZxJdVe66","name":"Bash","input":{"command":"echo hello"},"caller":{"type":"direct"}}],"container":null,"stop_reason":"tool_use","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":375,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":60,"output_tokens_details":{"thinking_tokens":0},"service_tier":"standard","inference_geo":"global","speed":"standard"},"diagnostics":null,"safeguard_results":[{"type":"dangerous_tool_use","status":{"type":"available","tool_uses":{"toolu_017ESS4iEgftPT8JZxJdVe66":{"type":"evaluated","outcome":"not_flagged"}}}}]}200

Observations:

  • On the before leg Claude Code shows no error for the swallowed 400
/live-pr-risk at 39fc45d: no breaking change, every base 200 stays 200

/live-pr-risk (39fc45d vs its merge base aa32e4c)

Verdict: no dependent path that worked on the base fails on the head. The only outbound difference is the derived anthropic-beta value on anthropic, azure_ai, and the Claude Platform on AWS, plus no context-management beta from a deployment that drops context_management, every case sent exactly one upstream request on both sides, and every other vendor's wire is the same as the base's

Rig: one proxy per side on a random port with --num_workers 2, its own Postgres database, PYTHONPATH pinned to its worktree, no general_settings, num_retries: 0, and thirteen deployments, each behind a forwarding recorder in front of the real vendor (mitmproxy for the SigV4 Claude Platform on AWS leg), so every request's headers, body keys, and count were diffed base vs head. Azure AI Foundry and Anthropic direct (both claude-sonnet-5-5) ran 12 cases each (with and without safeguards, with and without the Claude Code anthropic-beta, streaming, null, [], an int, an empty string, a 5 KB string, and a repeat), and every other deployment ran 2 (Claude Code header with safeguards, and safeguards alone), including one Foundry and one Anthropic deployment with additional_drop_params: [safeguards], plus one Anthropic deployment with additional_drop_params: [context_management] sent a context_management edit

Vendor (route) Case Base Head
Foundry (azure_ai) Claude Code header 400 200
Foundry safeguards alone 400 200
Foundry streaming 400 200
Foundry, Anthropic safeguards: [] 400 200
Foundry, Anthropic int, "", 5 KB string 400 400
Foundry, Anthropic no safeguards, null 200 200
Anthropic (anthropic) Claude Code header 200 200
Anthropic no client beta 400 200
Claude Platform on AWS safeguards alone 400 200
Claude Platform on AWS Claude Code header 200 200
Foundry, Anthropic dropping safeguards both cases 200 200
Anthropic dropping context_management edit sent 200 200
Eden AI, DeepSeek, Tencent both cases 200 200
MiniMax, Sail both cases 402 402
Meta, Prism both cases 400 400
Response ids, vendor messages, and the merge-ref check

Head 200 ids: Foundry msg_011Cg7LCEFrUtortjAFk2rGs (Claude Code header) and msg_011Cg7LCW3tFadSZK1XwrJSf (safeguards alone), Anthropic msg_011Cg7LDjBgWmgbuKcokiUyd (safeguards alone) and msg_011Cg7LDdtwa9aRKMyrkR4Qk (no client beta), Claude Platform on AWS msg_011Cg7LG4WqGMTiE2jnkKwRt. Base 400s on Foundry, Anthropic, and Claude Platform on AWS all carry safeguards: Extra inputs are not permitted

For a non-array value the vendor's message changes from Extra inputs are not permitted to Input should be a valid array, still a 400 after one attempt. Eden AI, Sail, Meta, Prism, DeepSeek, Tencent, and MiniMax recorded the same headers and body on both sides with no anthropic-beta, so their answers are the base's. The two deployments with additional_drop_params: [safeguards] sent no safeguards field and no derived beta on either side (the Anthropic one forwards the client's own beta header on both sides, as the base does). The deployment dropping context_management sent the field on neither side, and the base still sent anthropic-beta: context-management-2025-06-27 while the head sent no beta (head msg_011Cg7LGVtKekrLgBwcZowQ4, 200 on both)

Merge-ref check: 39fc45d merged clean into current main (d346d76) as a06737d25f, booted the same way against the same recorders, and all 45 cases answered the status the head did with the same recorded headers and body keys. Merge-ref 200 ids: Foundry msg_011Cg7LkHWhnZEjGjiu6PtPQ, Anthropic msg_011Cg7Lmj9qd6gUGnWBwW2yN, Claude Platform on AWS msg_011Cg7LpiMJj58VQY1ySdixU, each with safeguard_results

Breaking: none. Every base 200 stays 200 with the same response shape

Backward incompatible: a request carrying safeguards with no client beta, or with safeguards: [], now succeeds on anthropic, azure_ai, and the Claude Platform on AWS where it used to answer 400, and a non-array value now gets the vendor's array validation error instead of the unknown-field one, both the PR's intended change. additional_drop_params now applies before the proxy builds the provider headers on /v1/messages, so a dropped param no longer drives its derived beta. The drop cases above show it for safeguards and context_management (the base sent the context-management beta with no field, the head sends neither, both answer 200). A dropped output_format follows the same code path and was not driven live. A client workspace_id on the Claude Platform on AWS is not affected, since the proxy answers 401 to it unless the deployment allows it as a client credential, and then additional_drop_params never touches it on either side

Regression risk: none found. Providers with no column for the beta in the beta map (github_copilot, Eden AI, the OpenAI-compatible JSON providers) get no derived beta, matching the base wire

Dependency graph: callers of the shared beta derivation are anthropic, azure_ai, bedrock claude_platform, deepseek, tencent, minimax, the openai_like JSON providers, Eden AI, and github_copilot, all verified live except github_copilot. Callers of the moved additional_drop_params step are every /v1/messages deployment that sets it, verified live on Foundry and Anthropic. Vertex and bedrock invoke derive the beta in their own transformations, so the shared derivation does not reach them, but the moved additional_drop_params step does, which the X4 and X5 cells cover. The integration suites that mention safeguards ran on the head and are listed under the audit below

Not verified: github_copilot live, since no Copilot account with Claude access exists here (its unchanged wire is pinned by the audit's D20 cell); MiniMax and Sail vendor verdicts behind their 402s

Audit round 6 of 3 at 39fc45d: PASS

Audit round 6 of 3 (39fc45d vs merge base aa32e4c, past the cap for the High caveats on the beta map fetch)

Verdict: PASS. Every selected deterministic cell matched the inventory on the base and on both head runs, and every live row ran through the real vendor on both legs

Contract Cells Base Head A Head B
anthropic derives the beta once, merged with client betas D1 to D6 red where derived pass pass
SDK clients keep it, spend row written D7, D8, D10 red pass pass
azure_ai derives it from the body D9, D11 to D13 red where derived pass pass
filtered providers send no beta D14 to D16 pass pass pass
providers with no map column send no beta D17 to D19 pass pass pass
Claude Platform on AWS derives it D21 red pass pass
github_copilot unchanged D20 pass pass pass
bedrock and other endpoint families unchanged D22 to D27 pass pass pass
a dropped safeguards sends no beta X1, X2, X5 pass pass pass
a dropped safeguards on vertex_ai sends no beta X4 red pass pass
a dropped context_management sends no beta X3 red pass pass
Claude Code's betas and result reach the caller W1, W2 red pass pass
non-array value reaches the caller once S1 to S3 red pass pass
duplicate key, repeated request S4, S5 S4 pass, S5 red pass pass
upstream errors sent once with the beta S6, S7 red pass pass
cache hit makes no upstream call E1 red pass pass
burst, slow streams, worker SIGKILL C1 to C3 red pass pass
only filtered safeguards requests fetch the beta map, off the shared threads C4 red pass pass
Runs, node ids, and live rows

Rig: the box lane on this driver node, one leg per rig with its own Postgres and Redis, the owned upstream from tests/integration/_support/upstream.py, and a two-worker proxy per leg on tests/integration/proxy_config.yaml with no general_settings. Each lane ran tests/integration/run.py providers on the 46 node ids below with 4 pytest workers, --seed 4106601 --order-seed 0, INTEGRATION_PROXY_READY_SECONDS=240, one lane after another

Runs: base (aa32e4c) 46 collected, 22 passed, 24 failed, every failure an anthropic-beta assertion except C4, which never sees the map fetch the cold Foundry burst needs (State did not converge: 0); head A (39fc45d) 46 collected, 46 passed; head B (39fc45d) 46 collected, 46 passed, the same collected set and verdicts as head A, no retries. Lane scratch databases are dropped at lane end, so the deterministic rows carry their node ids rather than response ids

Node ids, all in tests/integration/messages_endpoint/providers/anthropic/: test_anthropic_safeguards_beta_wire.py (test_anthropic_messages_derive_the_dangerous_tool_use_beta_from_safeguards[D1 to D6], test_anthropic_sdk_sync_safeguards_derive_the_beta, test_anthropic_sdk_async_stream_safeguards_derive_the_beta_and_log_spend, test_azure_ai_sdk_sync_safeguards_derive_the_beta, test_azure_ai_messages_derive_the_beta_instead_of_forwarding_the_client_header[D9, D11 to D13], test_anthropic_compatible_providers_receive_the_beta_only_where_the_proxy_derives_it[D14 to D19, D21 to D24], test_github_copilot_messages_forward_safeguards_without_deriving_the_beta, test_non_native_deployments_bridge_to_the_responses_api_without_safeguards_or_the_beta, test_chat_completions_forward_safeguards_verbatim_without_deriving_the_beta, test_responses_stream_forwards_safeguards_verbatim_without_deriving_the_beta, test_a_deployment_dropping_safeguards_sends_neither_the_field_nor_the_beta[anthropic, azure_ai, bedrock_claude_platform, vertex_ai] (X1, X2, X5, X4), test_a_deployment_dropping_context_management_sends_neither_the_field_nor_its_beta (X3), test_foundry_rejecting_a_non_array_safeguards_value_reaches_the_caller_after_one_attempt[S1 to S3], test_duplicate_safeguards_keys_resolve_to_the_last_value, test_the_same_safeguards_sent_twice_are_two_upstream_calls_with_two_spend_rows, test_upstream_errors_reach_the_caller_with_the_beta_sent_once[S6, S7], test_the_response_cache_serves_the_repeated_request_without_an_upstream_call), test_anthropic_safeguards_beta_chaos.py (C1 to C3, and C4 test_cold_workers_fetch_the_beta_map_only_for_filtered_safeguards_requests_off_the_shared_threads), and test_anthropic_wire.py::test_anthropic_messages_preserves_cli_beta_safeguards_and_result[non_stream, stream] (W1, W2)

Unit evidence: test_llm_http_handler.py::test_anthropic_messages_dropped_safeguards_send_neither_the_field_nor_its_beta pins the drop-before-headers order at the handler, and the azure_ai, github_copilot, and openai_like transformation tests (test_safeguards_request_carries_the_dangerous_tool_use_beta_without_the_client_header, test_outgoing_azure_request_sends_safeguards_with_the_dangerous_tool_use_beta, test_github_copilot_safeguards_do_not_derive_the_dangerous_tool_use_beta, test_safeguards_reach_an_openai_like_host_with_only_the_client_betas) pin the beta map gate per provider, all passing at the head with test_anthropic_beta_headers_filtering.py

Live rows are the /live-pr-risk rig above, run once per leg against the real vendors: L1 Foundry, L2 Anthropic direct, and L10 Claude Platform on AWS go 400 to 200 with safeguard_results (head ids msg_011Cg7LCW3tFadSZK1XwrJSf, msg_011Cg7LDjBgWmgbuKcokiUyd, msg_011Cg7LG4WqGMTiE2jnkKwRt). L3 DeepSeek, L4 Tencent, and L8 Eden AI answer 200 on both legs with the same wire and no beta, L12 MiniMax and L5 Sail answer 402 on both legs with the same wire, and L6 Meta and L11 Prism reject the body field with the same message on both legs. L13 Foundry and L14 Anthropic with additional_drop_params: [safeguards] send neither the field nor a derived beta on either leg and answer 200 on both. L15 Anthropic with additional_drop_params: [context_management] sends no field on either leg, the base still sends the context-management beta and the head sends none, 200 on both (head msg_011Cg7LGVtKekrLgBwcZowQ4)

Legacy suites: every other integration file naming safeguards or the beta (the 15 files in messages_endpoint/safeguards/, test_anthropic_wire.py, and test_bedrock_invoke_dangerous_tool_use_beta_wire.py) ran on the head, 135 passed and 3 skipped at 39fc45d, each skip a pre-existing BUG: marker

Exclusions, set before the run: L7 Vertex partner (the shared derivation does not reach it, and the X4 cell covers the moved drop step that does), L9 github_copilot live (Copilot has no beta map column, D20 pins its wire as unchanged, and no Copilot account with Claude access exists), live bedrock invoke and mantle (not callers of the shared derivation, D23 and D24 pin them)

Behavior changes the audit observed, each the change LIT-8284 asks for and shipped as the PR's design in its TLDR and alternatives: safeguards with no client beta, or safeguards: [], now answers 200 on anthropic, azure_ai, and the Claude Platform on AWS (D1, D4, D7 to D11, D21, L1, L2, L10); a non-array value still answers 400 with the vendor's array message (S1 to S3); additional_drop_params now applies before the provider headers are built, so a dropped param no longer drives its beta (X1 to X5, L13 to L15)

Type

🐛 Bug Fix

Caveats (if any)

Low

  • The opt-in Rust /v1/messages route for anthropic does not derive the beta yet, so safeguards with no client beta still gets the base's 400 there. Claude Code sends the beta itself, and fix(rust): add the dangerous-tool-use beta when an anthropic /v1/messages request carries safeguards #46102 fixes the Rust side
  • github_copilot with safeguards is unverified and left unchanged on purpose, as the alternatives explain
  • safeguards on /v1/chat/completions and /v1/responses still gets Anthropic's 400, as on the merge base. Fixing it needs safeguard_results in those response shapes, which a follow-up ticket tracks
  • An azure_ai request with any beta that is first in its worker still loads the remote map on the event loop, and waits there while a safeguards request's load runs. The merge base does the same, and a follow-up ticket 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
Changes hot-path /v1/messages header construction and ordering of additional_drop_params across all native Claude providers; behavior shifts from 400 to 200 for some safeguards shapes on supported providers.

Overview
Fixes Claude Code auto mode through Azure AI Foundry (and other filtered /v1/messages providers) by deriving anthropic-beta: dangerous-tool-use-2026-09-03 when the request body includes non-null safeguards, instead of relying on a client header that Foundry never receives.

The derivation is gated on the bundled anthropic_beta_headers_config.json via is_beta_header_supported_by_bundled_config (so only providers with a map entry, e.g. anthropic and azure_ai, get the beta). OpenAI-like native passthrough passes beta_map_provider=openai_like so JSON providers do not inherit the anthropic column.

/v1/messages handler: additional_drop_params is applied before headers are built, so dropping safeguards or context_management removes both the body field and its derived beta. For providers that filter betas, cold workers preload the remote beta map on a dedicated one-thread executor (aload_beta_headers_config) so bursts do not block shared asyncio threads used by chat completions.

Adds broad wire, chaos, and unit coverage for provider-specific beta behavior, drops, SDK paths, and beta-map fetch semantics.

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


Devin Review

@devin-ai-integration

devin-ai-integration Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new actionable issues found.

Summary

The PR derives dangerous-tool-use-2026-09-03 from non-null safeguards on native Messages requests. The latest changes use bundled support data and move remote loading onto a dedicated thread.

  • Messages add the dangerous-tool-use beta for supported safeguards.
  • Dropped message fields no longer trigger their beta headers.

Reviews (12) · Last reviewed commit: "fix(anthropic): gate safeguards on the b..." · Reviewed by Greptile

greptile-apps[bot]

This comment was marked as resolved.

@codspeed

codspeed Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 32 untouched benchmarks


Comparing litellm_azure_ai_safeguards_dangerous_tool_use_beta (39fc45d) with main (9f115be)

Open in CodSpeed

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.12195% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/anthropic_beta_headers_manager.py 93.33% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

greptile-apps[bot]

This comment was marked as resolved.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

greptile-apps[bot]

This comment was marked as resolved.

@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.

@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.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@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.

✅ 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 39fc45d. Configure here.

mateo-berri added a commit that referenced this pull request Oct 17, 2026
…and gate the derived beta on the map

Gate the dangerous-tool-use beta derivation on the beta map the way #43955 does, so GitHub Copilot, DeepSeek, and opt-in passthroughs keep the merge base wire. Recognize /serving-endpoints/anthropic api_bases, fall back to the merge base routing for an api_base path the workspace trim does not know, strip Bedrock invocation metrics from the streamed message_stop, forward client betas to Databricks filtered by the map, and keep tool_choice when a dropped server tool has no name

@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 eb5295b into main Oct 17, 2026
96 checks passed
@mateo-berri
mateo-berri deleted the litellm_azure_ai_safeguards_dangerous_tool_use_beta branch October 17, 2026 16:46
mateo-berri added a commit that referenced this pull request Oct 18, 2026
…es (#46091)

* fix(databricks): use the native Anthropic route for Claude /v1/messages

Claude models on a Databricks workspace were bridged through chat completions on /v1/messages, which drops the safeguards field and never returns safeguard_results. They now call the workspace's /serving-endpoints/anthropic/v1/messages, the proxy forwards the client's anthropic-beta and anthropic-version headers to Databricks deployments, and the beta header map marks dangerous-tool-use-2026-09-03 as supported there. Any route whose platform does not take that beta drops safeguards together with it instead of answering 400. Non-Claude Databricks models keep the chat completions bridge

* fix(databricks): derive the dangerous-tool-use beta from safeguards instead of forwarding client betas

A Databricks Claude serving endpoint answers 400 to betas Claude Code sends on every turn, prompt-caching-scope-2026-01-05 among them, so the proxy no longer forwards the client's anthropic-beta header to Databricks deployments. The beta the classifier needs is derived from the safeguards body field, the same way the Azure AI route derives it. The Rust beta-header mirror stops rejecting the Databricks dangerous-tool-use cell so its config-cell test matches the JSON again

* fix(databricks): keep the billing block, build the messages route once, and pass the partner user agent

* fix(databricks): route Unity Catalog Claude names to the gateway messages route and keep env credentials

Unity Catalog model-service names now reach the AI Gateway's native Anthropic
route instead of a serving-endpoints path that answers 404 for them, and the
native route resolves the key and base through the same order the chat route
uses, so environment-only deployments keep working.

The native route is limited to Databricks foundation-model Claude names, an
unlisted provider forwards safeguards and the beta as sent, and the ten betas
the workspace rejects are marked unsupported for Databricks in the beta map
and its Rust mirror.

* test(rust): expect Databricks to drop the advanced-tool-use beta

* fix(databricks): keep passthrough safeguards, partner user agent, and classifier fallback

Only the OpenAI-compatible JSON providers drop safeguards now, so a
deployment opted into /v1/messages passthrough forwards the field and
the beta as sent. When a route drops safeguards and the proxy has a
classifier model, the proxy answers the verdict itself, as the chat
completions bridge did. The Databricks Messages route also reads the
databricks_user_agent param like the chat route.

* fix(databricks): drop rejected server tools under drop_params, short-circuit web search, route UC names from a full Messages URL

* fix(databricks): drop container on the native Messages route, as the chat completions bridge did

* fix(databricks): keep every api_base on a route the workspace serves and gate the derived beta on the map

Gate the dangerous-tool-use beta derivation on the beta map the way #43955 does, so GitHub Copilot, DeepSeek, and opt-in passthroughs keep the merge base wire. Recognize /serving-endpoints/anthropic api_bases, fall back to the merge base routing for an api_base path the workspace trim does not know, strip Bedrock invocation metrics from the streamed message_stop, forward client betas to Databricks filtered by the map, and keep tool_choice when a dropped server tool has no name

* test(databricks): cover the native Messages route, derived beta and JSON provider safeguards drop on the wire

* test(anthropic): expect the dangerous-tool-use beta derived from safeguards next to the client's betas

* fix(databricks): send client anthropic headers only on the native Messages route and keep SDK auth

Databricks chat completions, called directly or through the Messages bridge,
no longer receive the client's anthropic-beta and anthropic-version, as at the
merge base. The native Messages route still forwards them, filtered by the
beta map, without counting them as caller credentials, so a deployment with no
api_key keeps falling back to Databricks SDK auth. A pathless api_base goes to
the native route only for Unity Catalog names, matching the chat route.

* test(databricks): cover SDK auth with client anthropic headers and a Unity Catalog workspace root on the native route

* fix(databricks): keep client anthropic headers off an opted-in passthrough api_base

A databricks Claude deployment whose api_base is no workspace route and that opts
into /v1/messages with supported_endpoints falls back to the OpenAI-like
passthrough. That config does not filter betas through the beta map, yet it
received the native-only Databricks header entry, so Claude Code's
prompt-caching-scope beta reached the upstream raw and got a 400 where the merge
base answered 200.

Each Messages config now says whether it is the provider's native route, the
OpenAI-like passthrough says no, and the handler passes that answer when it
reads provider-specific headers, so native-only entries reach only native configs.

* test(databricks): cover client anthropic betas on an opted-in passthrough api_base

A databricks Claude deployment whose api_base is no workspace route and whose
model_info.supported_endpoints opts into /v1/messages takes the OpenAI-like
passthrough. The cell sends Claude Code's prompt-caching-scope and context-1m
betas through the proxy and asserts the caller gets the upstream's message and
the gateway receives no anthropic-beta, as on the merge base. The scripted
gateway answers 400 on the prompt-caching-scope beta, as the real one does

* fix(anthropic): keep beta map loads off shared threads and build the safeguards evaluator only when the proxy classifies

Unfiltered configs such as first-party Anthropic never read the beta map to decide safeguards support. Filtered configs await the map on its dedicated loader before reading it, on both the native and the MCP paths. The native handler decides after the upstream call and builds the evaluator only when the proxy classifies, so malformed messages keep the upstream 400. The Databricks dispatch tests assert the dispatched route instead of the config class, and the sail and Eden AI wire rows expect safeguards dropped, as JSON providers do.

* test(databricks): cover a loaded beta map that marks the safeguards beta unsupported

A remote beta map that nulls dangerous-tool-use for databricks while the bundled map allows it must send neither safeguards nor the beta to the serving endpoint, with or without a client beta, and the caller gets a 200 with no verdict.

* test(anthropic): annotate the MCP beta map recordings as Final

* fix(anthropic): drop safeguards on routes without the classifier only under drop_params

A route whose upstream does not answer safeguards (a JSON provider, or a map
that marks the dangerous-tool-use beta unsupported) now forwards the field and
the beta as the merge base did unless drop_params is set or the proxy runs its
own classifier, matching how litellm treats any unsupported param. Databricks
keeps dropping both, since its merge base bridge never forwarded the field.

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
pamanseau pushed a commit to KubeTEE-AI/litellm that referenced this pull request Oct 25, 2026
…equest carries safeguards (BerriAI#43955)

Backport of BerriAI#43955 to stable/1.103.x.
Cherry-picked from eb5295b (main).
Adapted to the line: the transformation lives under anthropic/experimental_pass_through, the integration tests live under tests/integration/providers, and the CLI-beta wire assertion change is dropped since that test is not on the line.
The github_copilot safeguards test uses the line's authenticator mock, since per-user Copilot sessions are not on this line.
pamanseau pushed a commit to KubeTEE-AI/litellm that referenced this pull request Oct 25, 2026
…ds wire test imports

Backport prerequisite for BerriAI#43955 on stable/1.103.x.
Copied from tests/integration/_support/vertex.py on main (added by BerriAI#43900).
Cartofante pushed a commit to CartoDB/litellm that referenced this pull request Oct 26, 2026
…equest carries safeguards (BerriAI#43955)

Backport of BerriAI#43955 to stable/1.106.x.
Cherry-picked from eb5295b (main).
Adapted to the line: the existing CLI-beta wire assertion change is dropped since that test is not on the line.
haowang1013 pushed a commit to directivegames/litellm that referenced this pull request Nov 3, 2026
…equest carries safeguards (BerriAI#43955)

Backport of BerriAI#43955 to stable/1.105.x.
Cherry-picked from eb5295b (main).
Handler import conflict resolved by keeping the line's imports plus aload_beta_headers_config; the CLI-beta wire assertion change is dropped since that test is not on the line.
DeoLeung pushed a commit to aiyou178/litellm that referenced this pull request Nov 5, 2026
…equest carries safeguards (BerriAI#43955)

* fix(anthropic): add the dangerous-tool-use beta when a /v1/messages request carries safeguards

* test(azure_ai): pin the outgoing Foundry request keeps the dangerous-tool-use beta next to safeguards

* test(azure_ai): inject the Foundry client and scope the beta cache reset to the test

* test(azure_ai): own and close the mock transport client, drop the docstring entry

* test(integration): audit the safeguards beta derivation across anthropic-compatible providers

* fix(github_copilot): keep safeguards from deriving the dangerous-tool-use beta

* test(integration): kill the chaos victim worker through the harness helper

* fix(anthropic): derive the dangerous-tool-use beta only where the beta map supports it and honor additional_drop_params

The safeguards beta is now added only for providers whose beta map column accepts it, so github_copilot, Eden AI and the OpenAI-compatible JSON providers keep their base wire. additional_drop_params now runs before the provider headers are built, so a dropped param no longer drives its derived beta.

* fix(anthropic): load the beta map off the event loop and pin a dropped context_management

The first /v1/messages request that needs the remote beta map now loads it in a worker thread,
so a slow fetch no longer stalls every other request on the worker. An integration cell pins that a
deployment dropping context_management sends neither the field nor its derived beta.

* fix(anthropic): load the beta map only for safeguards requests, once per worker

* fix(anthropic): gate safeguards on the bundled beta map and load the remote map on its own thread

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
(cherry picked from commit eb5295b)
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.

[Bug]: Anthropic safeguards are dropped or sent without the required beta

2 participants