Skip to content

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

Merged
mateo-berri merged 9 commits into
mainfrom
litellm_rust_anthropic_safeguards_beta
Oct 17, 2026
Merged

mateo-berri merged 9 commits into
mainfrom
litellm_rust_anthropic_safeguards_beta

Conversation

@devin-ai-integration

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

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

  • Rust adds dangerous-tool-use-2026-09-03 when safeguards is set, filtered through the beta map's anthropic, vertex_ai and azure_ai columns, with Claude Platform reading anthropic
  • The proxy reaches it for anthropic and vertex_ai, and the Rust gateway also for azure_ai and bedrock/claude_platform. Vertex drops its own copy
  • Hosts with no column, like DeepSeek, get no derived beta, as in fix(anthropic): add the dangerous-tool-use beta when a /v1/messages request carries safeguards #43955
  • Rust unit and proxy wire tests cover each

Rust now drops an explicit "safeguards": null on 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 untouched

User Flow

Before: a developer sending safeguards through a Rust-routed Anthropic deployment gets a 400 every time

  1. The proxy admin runs the proxy with LITELLM_RUST=true and an anthropic/claude-sonnet-5-5 deployment
  2. The developer sends POST https://litellm-domain/v1/messages with "safeguards": [{"type": "dangerous_tool_use", ...}] and no anthropic-beta header
  3. It comes back 400 safeguards: Extra inputs are not permitted, while the request without safeguards gets 200

After: the same request gets 200 with the classifier's verdict

  1. The developer sends the same POST to the same proxy
  2. It comes back 200 with safeguard_results on the message or the streaming message_delta
  3. Claude Code auto mode, which sends the beta itself, keeps /status at Auto mode server: Enabled

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

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 2 and no database, against real Anthropic and Vertex AI. The proxy does not send azure_ai or bedrock/claude_platform to Rust, so those rows ran the Rust gateway against real Azure AI Foundry and Claude Platform on AWS

Case Before (aa32e4c) After (0906914)
Anthropic, safeguards 400 200
Anthropic, safeguards, streaming 400 200
Anthropic, no safeguards 200 200
Anthropic SDK extra_body 400 200
Anthropic SDK, streaming 400 200
Vertex AI, safeguards 200 200
Vertex AI, safeguards, streaming 200 200
Azure AI gateway, safeguards 400 200
Azure AI gateway, streaming 400 200
Azure AI gateway, no safeguards 200 200
Azure AI gateway, "safeguards": null 400 200
Claude Platform gateway, safeguards 400 200
Claude Platform gateway, streaming 400 200
Claude Platform gateway, no safeguards 200 200
Claude Platform gateway, "safeguards": null 400 200
Claude Code auto mode works works

Anthropic, safeguards (headline)

  1. Start the proxy with LITELLM_RUST=true litellm --config config.yaml --num_workers 2 --port <port>
  2. Send payload_safeguards.json (safeguards plus a Bash tool) with curl and no anthropic-beta header
config.yaml and payload_safeguards.json
model_list:
  - model_name: claude-sonnet-5-5
    litellm_params:
      model: anthropic/claude-sonnet-5-5
      api_key: os.environ/ANTHROPIC_API_KEY
  - model_name: claude-haiku-5-5
    litellm_params:
      model: anthropic/claude-haiku-5-5
      api_key: os.environ/ANTHROPIC_API_KEY
  - model_name: vertex-claude-sonnet-5-5
    litellm_params:
      model: vertex_ai/claude-sonnet-5-5
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY

litellm_settings:
  drop_params: false

payload_safeguards_stream.json adds "stream": true, payload_control.json drops safeguards, and the Vertex payloads swap the model to vertex-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: true marks a Rust answer, and the control case shows Rust serves both legs

Before (aa32e4c):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:20270/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @payload_safeguards.json
HTTP 400
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":null,"stop_reason":null,"safeguard_results":null,"error":{"type":"invalid_request_error","message":"litellm.BadRequestError: AnthropicException - (400, '{\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"safeguards: Extra inputs are not permitted\"},\"request_id\":\"req_011Cg7HLqtrfs4sFuwKE6zmT\"}')\n\nLiteLLM: model group 'claude-sonnet-5-5' failed with the error above. No fallback was attempted."},"text":null}
$ grep -i '^x-litellm-rust' headers.txt

After (0906914):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:51104/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @payload_safeguards.json
HTTP 200
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":"claude-sonnet-5-5","stop_reason":"end_turn","safeguard_results":[{"type":"dangerous_tool_use","status":{"type":"available","tool_uses":{}}}],"error":null,"text":"ok"}
$ grep -i '^x-litellm-rust' headers.txt
x-litellm-rust: true

Other cases

Anthropic, safeguards, streaming

Before (aa32e4c):

$ curl -sN -D headers.txt -w '\nHTTP %{http_code}\n' http://127.0.0.1:20270/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @payload_safeguards_stream.json | grep -E 'event: message_start|safeguard_results|message_stop|"error"|HTTP '
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: AnthropicException - (400, '{\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"safeguards: Extra inputs are not permitted\"},\"request_id\":\"req_011Cg7HLhNt6Bz3YWDwcw9R5\"}')\n\nLiteLLM: model group 'claude-sonnet-5-5' failed with the error above. No fallback was attempted."}}
HTTP 400
$ grep -i '^x-litellm-rust' headers.txt

After (0906914):

$ curl -sN -D headers.txt -w '\nHTTP %{http_code}\n' http://127.0.0.1:51104/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @payload_safeguards_stream.json | grep -E 'event: message_start|safeguard_results|message_stop|"error"|HTTP '
event: message_start
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"container":null,"safeguard_results":[{"type":"dangerous_tool_use","status":{"type":"available","tool_uses":{}}}]},"usage":{"input_tokens":370,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":4,"output_tokens_details":{"thinking_tokens":0}}    }
event: message_stop
data: {"type":"message_stop"        }
HTTP 200
$ grep -i '^x-litellm-rust' headers.txt
x-litellm-rust: true
Anthropic, no safeguards (control)

Before (aa32e4c):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:20270/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @payload_control.json
HTTP 200
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":"claude-sonnet-5-5","stop_reason":"end_turn","safeguard_results":null,"error":null,"text":"ok"}
$ grep -i '^x-litellm-rust' headers.txt
x-litellm-rust: true

After (0906914):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:51104/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @payload_control.json
HTTP 200
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":"claude-sonnet-5-5","stop_reason":"end_turn","safeguard_results":null,"error":null,"text":"ok"}
$ grep -i '^x-litellm-rust' headers.txt
x-litellm-rust: true
Anthropic SDK 1.15.0, safeguards in extra_body

Before (aa32e4c):

$ client-venv/bin/python sdk_case.py 20270 $LITELLM_MASTER_KEY
non-streaming: 400 Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'litellm.BadRequestError: AnthropicException - (400, \'{"type":"error"
streaming: 400 Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'litellm.BadRequestError: AnthropicException - (400, \'{"type":"error"

After (0906914):

$ client-venv/bin/python sdk_case.py 51104 $LITELLM_MASTER_KEY
non-streaming: end_turn [{'type': 'dangerous_tool_use', 'status': {'type': 'available', 'tool_uses': {}}}]
streaming: end_turn None

SDK 1.15.0's streamed final message omits safeguard_results, which is not this PR

sdk_case.py
import sys
import anthropic

port = sys.argv[1]
client = anthropic.Anthropic(base_url=f"http://127.0.0.1:{port}", api_key=sys.argv[2], max_retries=0)
safeguards = [{"type": "dangerous_tool_use", "classifier_context": {"v": 1, "permission_mode": "auto"}}]
messages = [{"role": "user", "content": "Reply with the single word ok"}]
try:
    reply = client.messages.create(model="claude-sonnet-5-5", max_tokens=64, messages=messages, extra_body={"safeguards": safeguards})
    print("non-streaming:", reply.stop_reason, getattr(reply, "safeguard_results", None))
except anthropic.APIStatusError as error:
    print("non-streaming:", error.status_code, str(error)[:160])
try:
    with client.messages.stream(model="claude-sonnet-5-5", max_tokens=64, messages=messages, extra_body={"safeguards": safeguards}) as stream:
        final = stream.get_final_message()
    print("streaming:", final.stop_reason, getattr(final, "safeguard_results", None))
except anthropic.APIStatusError as error:
    print("streaming:", error.status_code, str(error)[:160])
Vertex AI, safeguards

Before (aa32e4c):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:20270/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @payload_vertex_safeguards.json
HTTP 200
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":"vertex-claude-sonnet-5-5","stop_reason":"end_turn","safeguard_results":[{"type":"dangerous_tool_use","status":{"type":"available","tool_uses":{}}}],"error":null,"text":"ok"}
$ grep -i '^x-litellm-rust' headers.txt
x-litellm-rust: true

After (0906914):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:51104/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @payload_vertex_safeguards.json
HTTP 200
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":"vertex-claude-sonnet-5-5","stop_reason":"end_turn","safeguard_results":[{"type":"dangerous_tool_use","status":{"type":"available","tool_uses":{}}}],"error":null,"text":"ok"}
$ grep -i '^x-litellm-rust' headers.txt
x-litellm-rust: true
Vertex AI, safeguards, streaming

Before (aa32e4c):

$ curl -sN -D headers.txt -w '\nHTTP %{http_code}\n' http://127.0.0.1:20270/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @payload_vertex_safeguards_stream.json | grep -E 'event: message_start|safeguard_results|message_stop|"error"|HTTP '
event: message_start
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"container":null,"safeguard_results":[{"type":"dangerous_tool_use","status":{"type":"available","tool_uses":{}}}]},"usage":{"input_tokens":370,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":4,"output_tokens_details":{"thinking_tokens":0}}       }
event: message_stop
data: {"type":"message_stop"         }
HTTP 200
$ grep -i '^x-litellm-rust' headers.txt
x-litellm-rust: true

After (0906914):

$ curl -sN -D headers.txt -w '\nHTTP %{http_code}\n' http://127.0.0.1:51104/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @payload_vertex_safeguards_stream.json | grep -E 'event: message_start|safeguard_results|message_stop|"error"|HTTP '
event: message_start
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"container":null,"safeguard_results":[{"type":"dangerous_tool_use","status":{"type":"available","tool_uses":{}}}]},"usage":{"input_tokens":370,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":4,"output_tokens_details":{"thinking_tokens":0}}}
event: message_stop
data: {"type":"message_stop"        }
HTTP 200
$ grep -i '^x-litellm-rust' headers.txt
x-litellm-rust: true
Azure AI through the Rust gateway

Each leg built the gateway with cargo build --locked --manifest-path litellm-rust/Cargo.toml -p litellm-gateway in its worktree and started it with LITELLM_CONFIG=gateway.yaml HOST=127.0.0.1 PORT=<port> litellm-gateway, with LITELLM_MASTER_KEY, AZURE_API_BASE (the Foundry resource) and AZURE_API_KEY in its env. The payloads are the Anthropic ones with the model set to azure-claude-sonnet-5-5. The gateway sets no x-litellm-rust header, since all of it is Rust

model_list:
  - model_name: azure-claude-sonnet-5-5
    litellm_params:
      model: azure_ai/claude-sonnet-5-5
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY

Before (aa32e4c):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:21237/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @azure_safeguards.json
HTTP 400
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":null,"stop_reason":null,"safeguard_results":null,"error":{"type":"invalid_request_error","message":"safeguards: Extra inputs are not permitted"},"text":null}

After (0906914):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:35486/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @azure_safeguards.json
HTTP 200
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":"claude-sonnet-5-5","stop_reason":"end_turn","safeguard_results":[{"type":"dangerous_tool_use","status":{"type":"available","tool_uses":{}}}],"error":null,"text":"ok"}

Before (aa32e4c):

$ curl -sN -D headers.txt -w '\nHTTP %{http_code}\n' http://127.0.0.1:21237/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @azure_safeguards_stream.json | grep -E 'event: message_start|safeguard_results|message_stop|"error"|HTTP '
{"type":"error","error":{"type":"invalid_request_error","message":"safeguards: Extra inputs are not permitted"},"request_id":"req_011Cg7HCEfogeo9Kd6odyz9A"}
HTTP 400

After (0906914):

$ curl -sN -D headers.txt -w '\nHTTP %{http_code}\n' http://127.0.0.1:35486/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @azure_safeguards_stream.json | grep -E 'event: message_start|safeguard_results|message_stop|"error"|HTTP '
event: message_start
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"container":null,"safeguard_results":[{"type":"dangerous_tool_use","status":{"type":"available","tool_uses":{}}}]},"usage":{"input_tokens":370,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":4,"output_tokens_details":{"thinking_tokens":0}}   }
event: message_stop
data: {"type":"message_stop"           }
HTTP 200

Before (aa32e4c):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:21237/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @azure_control.json
HTTP 200
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":"claude-sonnet-5-5","stop_reason":"end_turn","safeguard_results":null,"error":null,"text":"ok"}

After (0906914):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:35486/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @azure_control.json
HTTP 200
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":"claude-sonnet-5-5","stop_reason":"end_turn","safeguard_results":null,"error":null,"text":"ok"}

Before (aa32e4c):

$ jq -c '{model, safeguards}' azure_null.json
{"model":"azure-claude-sonnet-5-5","safeguards":null}
$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:24439/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @azure_null.json
HTTP 400
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":null,"stop_reason":null,"safeguard_results":null,"error":{"type":"invalid_request_error","message":"safeguards: Extra inputs are not permitted"},"text":null}

After (0906914):

$ jq -c '{model, safeguards}' azure_null.json
{"model":"azure-claude-sonnet-5-5","safeguards":null}
$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:35486/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @azure_null.json
HTTP 200
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":"claude-sonnet-5-5","stop_reason":"end_turn","safeguard_results":null,"error":null,"text":"ok"}
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-gateway in its worktree and started it with LITELLM_CONFIG=gateway.yaml HOST=127.0.0.1 PORT=<port> litellm-gateway, with LITELLM_MASTER_KEY, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION=us-west-2 and ANTHROPIC_AWS_WORKSPACE_ID in its env. The payloads are the Anthropic ones with the model set to cp-claude-sonnet-5-5

model_list:
  - model_name: cp-claude-sonnet-5-5
    litellm_params:
      model: bedrock/claude_platform/claude-sonnet-5-5
  - model_name: cp-claude-haiku-4-5
    litellm_params:
      model: bedrock/claude_platform/claude-haiku-4-5-20251001
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY

Before (aa32e4c):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:45212/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @cp_sonnet_safeguards.json
HTTP 400
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":null,"stop_reason":null,"safeguard_results":null,"error":{"type":"invalid_request_error","message":"safeguards: Extra inputs are not permitted"},"text":null}

After (0906914):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:24885/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @cp_sonnet_safeguards.json
HTTP 200
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":"claude-sonnet-5-5","stop_reason":"end_turn","safeguard_results":[{"type":"dangerous_tool_use","status":{"type":"available","tool_uses":{}}}],"error":null,"text":"ok"}

Before (aa32e4c):

$ curl -sN -D headers.txt -w '\nHTTP %{http_code}\n' http://127.0.0.1:45212/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @cp_sonnet_safeguards_stream.json | grep -E 'event: message_start|safeguard_results|message_stop|"error"|HTTP '
{"type":"error","error":{"type":"invalid_request_error","message":"safeguards: Extra inputs are not permitted"},"request_id":"req_011Cg7KH6Pc549HsNwnSV6Qs"}
HTTP 400

After (0906914):

$ curl -sN -D headers.txt -w '\nHTTP %{http_code}\n' http://127.0.0.1:24885/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @cp_sonnet_safeguards_stream.json | grep -E 'event: message_start|safeguard_results|message_stop|"error"|HTTP '
event: message_start
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"container":null,"safeguard_results":[{"type":"dangerous_tool_use","status":{"type":"available","tool_uses":{}}}]},"usage":{"input_tokens":370,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":4,"output_tokens_details":{"thinking_tokens":0}}           }
event: message_stop
data: {"type":"message_stop"               }
HTTP 200

Before (aa32e4c):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:45212/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @cp_sonnet_control.json
HTTP 200
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":"claude-sonnet-5-5","stop_reason":"end_turn","safeguard_results":null,"error":null,"text":"ok"}

After (0906914):

$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:24885/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @cp_sonnet_control.json
HTTP 200
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":"claude-sonnet-5-5","stop_reason":"end_turn","safeguard_results":null,"error":null,"text":"ok"}

Before (aa32e4c):

$ jq -c '{model, safeguards}' cp_sonnet_null.json
{"model":"cp-claude-sonnet-5-5","safeguards":null}
$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:40420/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @cp_sonnet_null.json
HTTP 400
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":null,"stop_reason":null,"safeguard_results":null,"error":{"type":"invalid_request_error","message":"safeguards: Extra inputs are not permitted"},"text":null}

After (0906914):

$ jq -c '{model, safeguards}' cp_sonnet_null.json
{"model":"cp-claude-sonnet-5-5","safeguards":null}
$ curl -s -D headers.txt -o body.json -w 'HTTP %{http_code}\n' http://127.0.0.1:24885/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -d @cp_sonnet_null.json
HTTP 200
$ jq -c '{model, stop_reason, safeguard_results, error, text: .content[0].text}' body.json
{"model":"claude-sonnet-5-5","stop_reason":"end_turn","safeguard_results":null,"error":null,"text":"ok"}
Claude Code 2.1.299 auto mode

Claude Code ran in tmux with ANTHROPIC_BASE_URL set to each leg's proxy, model claude-sonnet-5-5, and auto mode on. It was asked to read notes.txt and then run echo hello from the gateway with Bash. Both legs finished the turn with no permission prompt, and /status shows Auto mode server: Enabled on both, since Claude Code sends the beta header itself. The screenshots show the turn, not safeguard_results, which curl and the SDK show

Before (aa32e4c):

pr46102-aa32e4cc88-tui_before_turn.png

pr46102-aa32e4cc88-tui_before_status.png

After (0906914):

pr46102-0906914990-tui_after_turn.png

pr46102-0906914990-tui_after_status.png

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

Contract Base Head
Anthropic list safeguards get the beta red green
Null or absent safeguards send no beta green green
Duplicate keys use the last value red green
Malformed values reach the vendor with the beta red green
Bad key never reaches the vendor green green
Vertex keeps the beta green green
DeepSeek gets no derived beta green green
Outage, SIGKILL, shutdown mid-burst red green
Live Anthropic list 400 200
Live Vertex list 200 200
Live Azure AI Foundry list, null 400 200
Live Claude Platform list, null 400 200

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 permitted

The 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 safeguards key that the base forwarded

The 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

Path Base Head
Proxy, Anthropic, safeguards set 400 200, beta added
Proxy, safeguards int or "" 400 extra input 400 invalid array
Gateway, Anthropic, null 400 200, key dropped
Gateway, Vertex, null 400 200, key dropped
Gateway, Mantle, null 200, null and beta sent 200, neither sent
Gateway, DeepSeek or Tencent, null 200, null sent 200, key dropped

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

Path Risk State
Python /v1/messages, safeguards No beta, 400 Same on base, test skipped
DeepSeek, client anthropic-beta Header not forwarded Same on base
Vertex, safeguards and web_search Org policy 400 Same on base

Dependency graph

Host Entry State
anthropic Proxy, Rust Verified live
vertex_ai Proxy, Rust Verified live
deepseek Proxy, Rust Verified live, wire unchanged
azure_ai Gateway only /qa live
claude_platform Gateway only /qa live
bedrock_mantle Gateway only Verified live
tencent Gateway only Verified live
minimax Gateway only Wire only
openrouter, edenai Gateway only Code unchanged
bedrock invoke Gateway only Code unchanged

No proxy path reaches azure_ai or claude_platform through Rust, because catalog.py sends only anthropic, deepseek and vertex_ai there. The PR changes no Python code, so the Python Messages path is unchanged

Not verified

Target Reason
MiniMax live answer 402 "insufficient balance (1008)" on both sides

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

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 upstream request shaping and beta headers on the Rust messages path for multiple providers; behavior differs for null safeguards and hosts without a beta-map column, though tests lock the intended contracts.

Overview
Rust-routed Anthropic /v1/messages requests that include safeguards now get the dangerous-tool-use-2026-09-03 anthropic-beta header when the host’s beta map supports it (Anthropic, Vertex, Azure AI, Claude Platform), fixing upstream 400 “Extra inputs are not permitted” when callers omit the beta.

Shared logic in transformation.rs derives that beta from any non-null safeguards value, merges it with existing feature/client betas via provider_feature_betas / update_headers_with_safeguards_beta, and strips "safeguards": null from the wire body so disabled safeguards are not forwarded. Vertex drops its duplicate safeguards beta path in favor of the shared helper; DeepSeek still forwards safeguards without adding the derived beta.

Coverage adds Rust unit/crate tests and proxy integration tests (SDK, streaming, malformed payloads, worker kill/restart chaos).

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

@devin-ai-integration

devin-ai-integration Bot commented Oct 12, 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

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@litereview

litereview Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

⚠️ code-review

5/5 · Ready for human review

Scope: full · Full PR review.

Completed · Some checks not run.

No correctness findings.

Rust now derives dangerous-tool-use-2026-09-03 from a non-null safeguards on Anthropic, Vertex AI, Azure AI and Claude Platform. Hosts with no column in the beta map get no derived beta. The shared transform_messages_request drops "safeguards": null before the headers are computed, so Bedrock Mantle's contains_key check no longer adds the beta for a null value. Rust unit and wire tests pass locally at head. The PR description includes real-provider E2E runs for every changed host.

Checks and execution details
  • Passed · Real testing evidence (required): The PR changes Rust LLM translation under litellm-rust/crates/llms/**: request beta headers and the null-safeguards body drop.

  • Manual E2E: The PR description records proxy and gateway runs at 0906914990 against real Anthropic, Vertex AI, Azure AI Foundry and Claude Platform on AWS. Each run lists the config, payloads, curl/SDK commands and observed HTTP status, safeguard_results and x-litellm-rust. Before (aa32e4cc88) and after runs cover the safeguards, streaming, no-safeguards and "safeguards": null cases (null on Azure and Claude Platform). Only test files changed between 0906914990 and head 78e110d7eb (GitHub compare: request.rs and _anthropic_safeguards_beta_support.py, 2 lines each).

  • Local Rust tests: cargo test -p litellm-llms --lib -- safeguards request_headers feature_betas gave 58 passed, 0 failed, covering Anthropic, Vertex, Azure, Claude Platform, DeepSeek and Mantle cases. cargo test -p litellm-inference-messages --test messages -- safeguards gave 8 passed: wire-level beta and null drop for anthropic, azure_ai, bedrock_mantle, deepseek and minimax.

  • Integration tests: The Python wire tests use a hand-scripted peer, so I did not count them as provenance-verified evidence. The real-provider manual E2E covers the changed paths instead.

  • Passed · Compatibility requirements (required): No supported behavior breaks.

  • Non-null safeguards: On Anthropic, Azure AI and Claude Platform, these requests got 400 Extra inputs are not permitted before the PR and now get 200. Vertex already added the beta before the PR; the helper move keeps the same vertex_ai column result.

  • "safeguards": null: Rust now drops the key on all transform_messages_request hosts. Before, Anthropic-family hosts answered 400 (per the PR's real before/after runs). On DeepSeek, MiniMax and Tencent, dropping a null key matches the proxy's Python behavior of dropping None params.

A PR title without ! is correct here.

  • Passed · Changed behavior and result consistency (required): Standards read: litellm-rust/crates/llms/src/anthropic/messages/AGENTS.md, bedrock/claude_platform/messages/AGENTS.md, azure_ai/messages/AGENTS.md, and tests/integration/AGENTS.md (the pytest.skip("BUG: ...") rule, followed at test_rust_anthropic_safeguards_beta_wire.py:337).

Traced path: prepare_provider_request (inference-messages/src/prepare.rs) calls transform_anthropic_messages_request, which calls without_null_safeguards. Then config.request_headers(.., &transformed) runs on the transformed body, followed by merge_beta_headers.

Boundary cases checked:

  • Absent, null, empty list and non-list: Covered by unit cases and the 5-provider wire test.
  • Caller betas merged with the derived beta: Covered by the Azure and Anthropic header cases.
  • Per-host column filtering: AnthropicBeta::on rejects DangerousToolUse20260903 only for BedrockConverse and Databricks.
  • Mantle: It checks contains_key on the already-transformed request, where null was already removed.

DeepSeek, MiniMax, Tencent, EdenAI and OpenRouter still use update_headers_with_anthropic_beta, so they get no derived beta, as the PR intends. Every decision above is reflected in the structured result.

  • Not run · Python integration wire/chaos tests (optional): Not run: they need a full proxy with Postgres, Redis and the built Rust wheel. Per tests/integration/AGENTS.md, CircleCI first runs them on main.

View review · Reviewed 78e110d7eb8b

@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor

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

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@litereview

litereview Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

@mateo-berri

Copy link
Copy Markdown
Contributor

DeepSeek leg stays unverified: the only DeepSeek key answers 402 Insufficient Balance and the console blocks this box. Tracked as a Medium caveat

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@litereview

litereview Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

…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.
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@litereview

litereview Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

@mateo-berri

Copy link
Copy Markdown
Contributor

@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
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Oct 17, 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

Rust adds the safeguards beta for supported Anthropic-compatible hosts. The latest changes also remove null safeguards before building provider headers

  • Safeguards requests now carry the beta their provider allows.
  • Null safeguards are omitted instead of sent upstream.

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

Copy link
Copy Markdown
Contributor

@litereview code-review

1 similar comment
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

1 similar comment
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…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.
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…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.
@mateo-berri

Copy link
Copy Markdown
Contributor

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

@mateo-berri
mateo-berri merged commit 5b042c0 into main Oct 17, 2026
165 of 168 checks passed
@mateo-berri
mateo-berri deleted the litellm_rust_anthropic_safeguards_beta branch October 17, 2026 16:48
Cartofante pushed a commit to CartoDB/litellm that referenced this pull request Oct 26, 2026
…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.
haowang1013 pushed a commit to directivegames/litellm that referenced this pull request Nov 3, 2026
…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.
DeoLeung pushed a commit to aiyou178/litellm that referenced this pull request Nov 5, 2026
…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)
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

1 participant