Skip to content

fix(anthropic): forward the dangerous-tool-use beta to Azure AI Foundry - #43934

Merged
mateo-berri merged 1 commit into
mainfrom
litellm_azure_ai_dangerous_tool_use_beta_mapping
Sep 30, 2026
Merged

mateo-berri merged 1 commit into
mainfrom
litellm_azure_ai_dangerous_tool_use_beta_mapping

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • main's beta map nulls dangerous-tool-use-2026-09-03 for azure_ai
  • When the gateway forwards safeguards and the client's anthropic-beta to Foundry, that beta is stripped, so Foundry answers 400
  • Claude Code auto mode through an Azure AI Foundry deployment then runs every tool call without the server-side classifier

How it solves it:

  • Map the beta for azure_ai, so Foundry gets the header next to safeguards whenever the gateway forwards it
  • The beta filtering test now covers azure_ai for the dangerous-tool-use beta

What it does not solve: at a default config (no general_settings.forward_client_headers_to_llm_api) the proxy never hands azure_ai the client's anthropic-beta header, so Claude Code auto mode through Foundry is unchanged on main by this PR alone. The real Claude Code legs below show it. The default-config fix is #43955 (LIT-8284), which adds the beta from the safeguards body field

User Flow

Before: a Claude Code user in auto mode whose gateway routes Claude to Azure AI Foundry runs every tool call without the server-side classifier

  1. The proxy admin adds an azure_ai/claude-sonnet-4-6 deployment on a Foundry /anthropic base and sets forward_client_headers_to_llm_api: true
  2. The user starts Claude Code with ANTHROPIC_BASE_URL at the gateway and --permission-mode auto, then asks it to read a file and run a shell command
  3. Claude Code sends POST https://litellm-domain/v1/messages?beta=true with safeguards: [{"type": "dangerous_tool_use", ...}] and anthropic-beta: ...,dangerous-tool-use-2026-09-03
  4. The gateway forwards safeguards but drops that beta, and Foundry answers 400 safeguards: Extra inputs are not permitted
  5. Claude Code retries the same turn without safeguards, the Bash tool runs with no Allowed by auto mode classifier line, and /status shows Auto mode server: Disabled

After, with forward_client_headers_to_llm_api: true: the same session runs its tool calls through the classifier

  1. The proxy admin adds the same deployment with the same setting
  2. The user starts the same Claude Code session and sends the same prompt
  3. Claude Code sends the same POST https://litellm-domain/v1/messages?beta=true with safeguards and the beta
  4. The gateway forwards the beta next to safeguards, and Foundry answers 200 with safeguard_results ("outcome": "not_flagged"), streaming included
  5. The Bash output ends with Allowed by auto mode classifier and /status shows Auto mode server: Enabled

After, at a default config: steps 1 to 5 of Before, unchanged, until #43955 lands

Relevant issues

Needed by #43662, the v1.103.x backport of the safeguards passthrough: every proxy fetches this map from main at boot, so its Foundry case answers 400 until this lands

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
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

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

#43934 alone does not cure Claude Code auto mode through Azure AI Foundry on main. At a default config, real Claude Code behaves the same before and after this PR: the first tool-call request gets a 400 from the gateway, Claude Code retries it without safeguards, the tool runs on the client-side classifier only, and /status reports Auto mode server: Disabled. The map change itself works, which the third leg shows with forward_client_headers_to_llm_api: true on. What is left is the proxy's header scoping, fixed in #43955 (LIT-8284)

QA ran on ed4caeb, this PR's squash commit on main; the PR branch tip ded5957 carries the same product diff. The earlier curl-only proof at ded5957 is replaced by this run, since a curl is not the request shape Claude Code sends

Setup, shared by all three legs

The client is real Claude Code v2.1.286 driven in a tmux pane, the way a developer uses it. Each proxy ran on its own from the tree named by the leg, with --num_workers 2, no database, on port 51823, one at a time, with LITELLM_LOCAL_ANTHROPIC_BETA_HEADERS=True so it reads the beta map checked out in its own tree instead of fetching main's. The default config is this file, with nothing under general_settings:

model_list:
  - model_name: claude-sonnet-4-6
    litellm_params:
      model: azure_ai/claude-sonnet-4-6
      api_key: os.environ/AZURE_FOUNDRY_API_KEY
      api_base: https://litellm-e2e-suite-resource.services.ai.azure.com/anthropic
  - model_name: claude-haiku-4-5
    litellm_params:
      model: azure_ai/claude-haiku-4-5
      api_key: os.environ/AZURE_FOUNDRY_API_KEY
      api_base: https://litellm-e2e-suite-resource.services.ai.azure.com/anthropic

Claude Code was started in an empty directory holding one notes.txt:

ANTHROPIC_BASE_URL=http://127.0.0.1:51823 ANTHROPIC_AUTH_TOKEN=<proxy key> \
ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-6 ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5 \
claude --permission-mode auto --model claude-sonnet-4-6

Each leg then sends the prompt Read notes.txt, then use the Bash tool to run: echo hello from the gateway, waits for the turn to finish, and runs /status

Before (b41715b, default config)

  1. Boot the proxy from b41715b with the default config, start Claude Code as above, send the prompt
  2. Claude Code reads notes.txt and runs the Bash tool, and the Bash output carries no Allowed by auto mode classifier line. The gateway's access log shows the first POST /v1/messages?beta=true answered 400 and the retry answered 200

pr43934-ed4caebb65-before_b41715b0c2_bash.png

  1. /status reports Auto mode server: Disabled

pr43934-ed4caebb65-before_b41715b0c2_status.png

After (ed4caeb, default config): unchanged

  1. Boot the proxy from ed4caeb with the default config, start Claude Code as above, send the prompt
  2. Same as Before: the tool runs with no Allowed by auto mode classifier line, and the gateway's access log shows the same 400 then 200 pair

pr43934-ed4caebb65-after_ed4caebb65_bash.png

  1. /status still reports Auto mode server: Disabled

pr43934-ed4caebb65-after_ed4caebb65_status.png

After (ed4caeb, forward_client_headers_to_llm_api: true): classifier on

  1. Boot the proxy from ed4caeb with the default config plus general_settings: {forward_client_headers_to_llm_api: true}, start Claude Code as above, send the prompt
  2. The Bash output ends with Allowed by auto mode classifier, and every POST /v1/messages?beta=true in the gateway's access log answered 200

pr43934-ed4caebb65-after_ed4caebb65_fwd_bash.png

  1. /status reports Auto mode server: Enabled

pr43934-ed4caebb65-after_ed4caebb65_fwd_status.png

The same setting on b41715b still answers 400 (the second row of the curl table below), so the map change is necessary for the classifier on main and the setting alone does nothing

Secondary check: curl

Run against each proxy right after its Claude Code leg, with $BODY being the JSON below, "stream" flipped per case, and the control case with safeguards removed:

BETAS='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'
curl -s -w '\nHTTP %{http_code}\n' http://localhost:51823/v1/messages \
  -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' \
  -H 'anthropic-version: 2023-06-01' -H "anthropic-beta: $BETAS" -d "$BODY"
{"model":"claude-sonnet-4-6","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"}]}
Proxy Setting safeguards, non-streaming safeguards, streaming control, no safeguards
b41715b default 400 req_011CfaXvAbfj7TmQzszjCPYm 400 200 msg_011CfaXvF92VNmvsiRAfeoFy
b41715b forwarding on 400 req_011CfaW8LKfV6vpQjQcJT1Ba 400 200 msg_011CfaW8Qg79i9nsXv5APn8b
ed4caeb default 400 req_011CfaYLzuxKi5r5gke94AXN 400 200 msg_011CfaYM6QcKryXAN9yKc714
ed4caeb forwarding on 200 msg_011CfaYaS88kH8L5EEVJhUYL 200 200 msg_011CfaYapdUCXJ21uL2y1hCQ

The 400 body is Foundry's, passed through: safeguards: Extra inputs are not permitted. The two 200s with safeguards carry safeguard_results ("outcome": "not_flagged"), in the message body when not streaming and in the message_delta event when streaming. The second row ran earlier on the same tree through a claude-haiku-4-5 deployment on port 61287; the rest ran on port 51823 through claude-sonnet-4-6

Observations from the run:

  • Haiku 4.5 alias: Claude Code refuses auto mode client-side. Not this PR, left alone
  • Claude Code hides the 400, tools run, server classifier silently off. Not this PR, left alone at default config
  • Forwarding setting plus this PR enables the classifier on main. This PR, observed live

Type

🐛 Bug Fix

Caveats (if any)

Medium

Low

  • The map is fetched from main at boot, so a running proxy picks this up on its next restart, and one pinned with LITELLM_LOCAL_ANTHROPIC_BETA_HEADERS=True on its next upgrade

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

Map dangerous-tool-use-2026-09-03 for azure_ai in the beta header config so the
Claude Code auto mode beta reaches Foundry instead of being stripped, matching
the anthropic, bedrock, and vertex_ai entries
@devin-ai-integration

devin-ai-integration Bot commented Sep 30, 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 Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Enables a Claude beta feature for Azure AI Foundry.

The PR appears safe to merge

Summary

The PR allows the dangerous-tool-use beta header through the Azure AI Foundry mapping and adds Azure to the existing forwarding test

Reviews (1) · Last reviewed commit: "fix(anthropic): forward the dangerous-to..."

@codecov

codecov Bot commented Sep 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_azure_ai_dangerous_tool_use_beta_mapping (ded5957) with main (b41715b)

Open in CodSpeed

@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 ded5957. Configure here.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

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.

1 participant