Skip to content

fix(bedrock): stop sending toolConfig tool definitions to guardrails on passthrough converse - #39281

Merged
yucheng-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_lit5797_bedrock_passthrough_tool_defs
Sep 5, 2026
Merged

yucheng-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_lit5797_bedrock_passthrough_tool_defs

Conversation

@yucheng-berri

@yucheng-berri yucheng-berri commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Bedrock passthrough guardrails scanned tool definitions as user content
  • Tool names, descriptions and schema strings each became a separate scan item
  • A benign prompt was blocked because a term sat in a tool description
  • No way to turn it off; stricter than our own /chat/completions path

How it solves it:

  • toolConfig.tools is no longer collected into the guardrail input texts
  • Matches every other guardrail translation handler in the repo
  • Caller content stays scanned: messages, toolUse, toolResult, additionalModelRequestFields
  • Also closes a bypass under experimental_use_latest_role_message_only

User Flow

Before: a developer calling Bedrock Converse through the gateway gets a benign question blocked because one of their tool definitions mentions a term their guardrail denies

  1. Their app sends POST https://litellm-domain/bedrock/model/us.anthropic.claude-sonnet-4-5-20250929-v1:0/converse with one user message, How much lag is there in my data?, and a toolConfig holding a single tool whose description mentions a denied term
  2. The gateway answers 400 with Violated guardrail policy and the guardrail's blocked-input message, even though the user never typed the denied term
  3. The same request with "converse-stream" fails the same way
  4. They open https://litellm-domain/ui/?page=guardrails-monitor and see every one of their requests counted as a Blocked Request, 0% pass rate
  5. There is no setting that turns this off, so their only option is to rewrite their tool descriptions

After: the same request goes through, and only text the user actually sent is scanned

  1. Their app sends the same POST https://litellm-domain/bedrock/model/us.anthropic.claude-sonnet-4-5-20250929-v1:0/converse with the same message and the same toolConfig
  2. The gateway answers 200 with the model's reply
  3. The same request with "converse-stream" streams normally
  4. A request that really does carry the denied term in the user message still answers 400 Violated guardrail policy
  5. https://litellm-domain/ui/?page=guardrails-monitor now shows 66.7% pass rate, with only the genuine violation counted as blocked

Security consequence: with experimental_use_latest_role_message_only turned on, another user could previously push a denied term past the guardrail by appending any tool definition to the request, because the guardrail only inspected the last extracted string and tool strings were appended after the message. That no longer works.

Relevant issues

Linear ticket

Resolves LIT-5797

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/test_litellm/<your_test_file>.py -v
  • 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

Screenshots / Proof of Fix

Shared setup for every case below, identical on both sides.

Real AWS Bedrock guardrail 6hbgpnnqoeb1 in us-east-1, word policy denying hexblade, blocked-input message BLOCKED_BY_LIT5797_GUARDRAIL_INPUT. Real model us.anthropic.claude-sonnet-4-5-20250929-v1:0. Real Postgres. No mocks anywhere.

config.yaml

model_list:
  - model_name: "us.anthropic.claude-sonnet-4-5-20250929-v1:0"
    litellm_params:
      model: "bedrock/us.anthropic.claude-sonnet-4-5-20250929-v1:0"
      aws_region_name: us-east-1

guardrails:
  - guardrail_name: "bedrock-word-guard"
    litellm_params:
      guardrail: bedrock
      mode: "pre_call"
      guardrailIdentifier: os.environ/LIT5797_GUARDRAIL_ID
      guardrailVersion: "DRAFT"
      aws_region_name: us-east-1
      default_on: true

general_settings:
  master_key: sk-1234

tooldesc.json, the ticket's repro: the denied term appears only in the tool description, never in the prompt

{
  "messages": [{"role": "user", "content": [{"text": "How much lag is there in my data?"}]}],
  "toolConfig": {
    "tools": [
      {
        "toolSpec": {
          "name": "lookup_agent",
          "description": "Look up the hexblade agent registry for an agent",
          "inputSchema": {
            "json": {
              "type": "object",
              "properties": {
                "agent_name": {"type": "string", "title": "Agent Name", "enum": ["alpha", "beta", "gamma"]}
              }
            }
          }
        }
      }
    ]
  }
}

usercontent.json, the control: the denied term is in the prompt itself

{"messages": [{"role": "user", "content": [{"text": "Tell me about the hexblade please"}]}]}

Before (31ca4dd)

1 Benign prompt, denied term only in the tool definition

  1. curl -sS -o /dev/null -w "%{http_code}" http://127.0.0.1:20799/bedrock/model/us.anthropic.claude-sonnet-4-5-20250929-v1:0/converse -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" -d @tooldesc.json
  2. 400, body {"error":{"message":"Violated guardrail policy", ... "bedrock_guardrail_response":"BLOCKED_BY_LIT5797_GUARDRAIL_INPUT", ...}}

2 Same request, streaming

  1. Same curl against .../converse-stream
  2. 400, same Violated guardrail policy body

3 Denied term in the user message

  1. Same curl with -d @usercontent.json
  2. 400 Violated guardrail policy

4 What the guardrail was handed

  1. A CustomGuardrail loaded through the documented extension point recorded the texts list it received for case 1
  2. 9 items: ["How much lag is there in my data?", "lookup_agent", "Look up the hexblade agent registry for an agent", "object", "string", "Agent Name", "alpha", "beta", "gamma"]

5 Guardrails Monitor after the three requests above

  1. Open http://127.0.0.1:20799/ui/?page=guardrails-monitor
  2. Total Evaluations 3, Blocked Requests 3, Pass Rate 0%, fail rate 100%

before guardrails monitor

6 Request Logs after the three requests above

  1. Open http://127.0.0.1:20799/ui/?page=logs
  2. Three rows, all Failure, cost -, 0 tokens, because none of them reached the model

before request logs

After (63ef60e)

1 Benign prompt, denied term only in the tool definition

  1. curl -sS -o /dev/null -w "%{http_code}" http://127.0.0.1:20797/bedrock/model/us.anthropic.claude-sonnet-4-5-20250929-v1:0/converse -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" -d @tooldesc.json
  2. 200, body {"metrics":{"latencyMs":3368},"output":{"message":{"content":[{"text":"I'd be happy to help you check the lag in your data ..."}]}}}

2 Same request, streaming

  1. Same curl against .../converse-stream
  2. 200, a normal vnd.amazon.eventstream response starting with messageStart

3 Denied term in the user message

  1. Same curl with -d @usercontent.json
  2. 400 Violated guardrail policy, unchanged

4 What the guardrail was handed

  1. Same recorder, same case 1 request
  2. 1 item: ["How much lag is there in my data?"]

5 Guardrails Monitor after the three requests above

  1. Open http://127.0.0.1:20797/ui/?page=guardrails-monitor
  2. Total Evaluations 3, Blocked Requests 1, Pass Rate 66.7%, fail rate 33.3%

after guardrails monitor

6 Request Logs after the three requests above

  1. Open http://127.0.0.1:20797/ui/?page=logs
  2. Two Success rows with real cost and real token counts, and one Failure, the genuine violation

after request logs

Native AWS Bedrock evidence

The same policy was driven directly against the Bedrock Converse API, with no LiteLLM in the path: the same real guardrail, real model, and denied word.

Denied word location Native Converse result
toolConfig.tools[].toolSpec.description Allowed; the definition text was excluded from guardrail input coverage
User message text Blocked by the word policy

AWS documents this behavior in Use a guardrail with the Converse API: toolConfig.tools[].toolSpec.description and .inputSchema are not evaluated by guardrail filters. The content-filter documentation independently says tool definitions are not evaluated in tool-use workloads.

This change removes a passthrough-only policy that was stricter than native Bedrock for tool definitions. It does not stop LiteLLM from scanning caller message text, tool inputs, tool results, or additionalModelRequestFields.

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • A Converse body whose only scannable strings were tool definitions no longer runs the guardrail at all

Low

  • additionalModelRequestFields is still scanned on purpose
    • It is a free-form model-parameter bag with no schema, so caller text can genuinely live there
    • The ticket's expected outcome names tool definitions only
  • Tool definitions are not forwarded in the structured tools input either
    • Bedrock toolSpec is not the OpenAI tool shape guardrails expect there
    • Worth a follow-up if a tool-allowlist guardrail should cover this route
  • The ticket's unverified secondary claim did not reproduce
    • Bedrock passthrough blocks do reach the Guardrails Monitor on both sides, screenshots above

Final-head live-pr-risk rerun at 63ef60e completed after the bot loop. The full matrix and configuration-family checks used the real Bedrock guardrail, real Bedrock model, real Postgres, and two live proxy processes.

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

ran /live-pr-risk and found no regressions/backward incompatible risks

…on passthrough converse

Bedrock passthrough Converse routes flattened every non-empty string under
toolConfig.tools into the guardrail INPUT texts, so tool names, tool
descriptions and JSON-schema strings (object, property names, titles, type
names, enum values) each arrived as a separate guardrail item. A request whose
only prompt was one benign user message could be blocked outright because a
denied term appeared in an app-authored tool definition.

Tool definitions are now excluded from the extracted texts, matching every
other guardrail translation handler, which carries tool definitions in the
structured tools input rather than in texts. Caller content stays scanned:
message text, toolUse.input, toolResult content and json, and
additionalModelRequestFields are unchanged.

Resolves LIT-5797
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

bugbot run

@codspeed

codspeed Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_lit5797_bedrock_passthrough_tool_defs (63ef60e) with litellm_internal_staging (31ca4dd)

Open in CodSpeed

@devin-ai-integration devin-ai-integration 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.

Devin Review found 1 potential issue.

2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines -124 to -126
tool_config: Final = body.get("toolConfig")
if isinstance(tool_config, dict):
_collect_strings(tool_config.get("tools"), holders)

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.

🟥 Tool definitions bypass input guardrails

A caller can place prohibited instructions in toolConfig.tools. Bedrock receives them, while the configured guardrail cannot inspect or block them

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

This one is the ticket's ask, not a defect the PR introduced. LIT-5797 says outright: "Tool definitions excluded from guardrail evaluation by default".

The behavior you describe is what /v1/chat/completions already does, and I checked it on the same rig with the same guardrail rather than arguing it. Real AWS Bedrock guardrail with a word policy denying hexblade, real model us.anthropic.claude-sonnet-4-5-20250929-v1:0, one proxy at the merge base (31ca4dd) and one at this head (63ef60e):

request base head
POST /v1/chat/completions, denied term only in tools[].function.description 200, not blocked 200, not blocked
POST /v1/chat/completions, denied term in the user message 400 blocked 400 blocked
POST /bedrock/model/{id}/converse, denied term only in the tool description 400 blocked 200, not blocked
POST /bedrock/model/{id}/converse, denied term in the user message 400 blocked 400 blocked

So the first row is the product-wide behavior on both sides, and Bedrock passthrough was the one route that differed. Three more things that make it the right default here:

  1. Every other guardrail translation handler keeps tool definitions out of texts. The chat and messages handlers pass them in the structured tools input, which a hook opts into; this handler flattened each name, description and JSON-schema string into texts, so every text-scanning hook saw them as user content.
  2. Bedrock's own native guardrail does not scan toolConfig either, so passthrough was stricter than the service it fronts.
  3. Tool definitions are written by the same application that configures the guardrail. A caller who can set toolConfig can also set messages, and messages are still scanned, along with toolUse.input, toolResult text and json, system blocks, and additionalModelRequestFields. All four verified still blocking at this head.

The old behavior was also a bypass in the other direction. Under experimental_use_latest_role_message_only the guardrail inspects only the last extracted text, and tool strings were appended after the message text, so a denied term in the real user message went through: base 200, head 400 blocked.

Leaving as is. The omission is written into the PR description under Caveats so it does not get re-litigated.

@greptile-apps

greptile-apps Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR stops Bedrock Converse passthrough guardrails from treating tool definitions as user input while continuing to scan messages, tool-use content, tool results, and additional model request fields.

  • Removes toolConfig.tools from extracted guardrail text.
  • Preserves tool definitions unchanged in the forwarded Bedrock request.
  • Adds regression coverage for multiple tools, skipped tool messages, tool-use input, masking, and blocking behavior.

Confidence Score: 5/5

The PR appears safe to merge, with the changed guardrail scope and its acknowledged empty-text behavior covered by focused regression tests.

The extraction change consistently excludes only tool definitions, keeps caller content scanning and positional write-back intact, and introduces no unacknowledged blocking failure.

Important Files Changed

Filename Overview
litellm/llms/bedrock/passthrough/guardrail_translation/handler.py Removes tool-definition string extraction while preserving existing extraction, ordering, masking, and empty-input behavior.
tests/test_litellm/llms/bedrock/passthrough/guardrail_translation/test_handler.py Updates and expands tests to verify tool definitions are excluded without weakening coverage for caller-provided message and tool-use content.

Reviews (1): Last reviewed commit: "fix(bedrock): stop sending toolConfig to..." | Re-trigger Greptile

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

as well as ``additionalModelRequestFields``, a free-form model-parameter bag
with no schema that a caller can route blocked content through.

``toolConfig.tools`` is deliberately NOT scanned. Tool definitions are

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.

High: Guardrail bypass through tool definitions

Bedrock passthrough clients supply the raw request body, so these definitions are not necessarily trusted app-authored configuration. An authenticated caller can put denied or sensitive text in toolSpec.description or its input schema; this handler omits it from the guardrail inputs and then forwards it unchanged to Bedrock. Convert the Bedrock tool definitions to the guardrail's structured tools format, or selectively scan and write back their semantic text fields rather than excluding the entire subtree.

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.

Same finding Devin raised, and it is the ticket's ask rather than a hole this PR opened. LIT-5797 says outright: "Tool definitions excluded from guardrail evaluation by default".

I did not argue this one, I ran it. Real AWS Bedrock guardrail with a word policy denying hexblade, real model us.anthropic.claude-sonnet-4-5-20250929-v1:0, real Postgres, one proxy at the merge base (31ca4dd) and one at this head (63ef60e), same config on both:

request base head
POST /v1/chat/completions, denied term only in tools[].function.description 200, not blocked 200, not blocked
POST /v1/chat/completions, denied term in the user message 400 blocked 400 blocked
POST /bedrock/model/{id}/converse, denied term only in the tool description 400 blocked 200, not blocked
POST /bedrock/model/{id}/converse, denied term in the user message 400 blocked 400 blocked

Row 1 is the product-wide behavior on both sides. Bedrock passthrough was the single route that differed, and it differed because it flattened every tool name, description and JSON-schema string ("object", property titles, type names, enum values) into the guardrail texts list, so a benign prompt got blocked by a word sitting in an app-authored tool description. That is the reported bug.

What still reaches the guardrail at this head, all verified blocking live: message text, system blocks, toolUse.input, toolResult text and json, and additionalModelRequestFields. A caller who can set toolConfig can also set messages, and messages are scanned.

Two more reasons this is the right default. Bedrock's own native guardrail does not scan toolConfig, so passthrough was stricter than the service it fronts. And every other guardrail translation handler in the repo keeps tool definitions out of texts; the chat and messages handlers pass them in the structured tools input, which a hook opts into.

The old behavior was itself a bypass in the other direction. Under experimental_use_latest_role_message_only the guardrail inspects only the last extracted text, and tool strings were appended after the message text, so a denied term in the real user message went straight through: base 200, head 400 blocked. This PR closes that.

Leaving as is. The omission is written into the PR description under Caveats and into the function docstring so it does not get re-litigated.

@veria-ai

veria-ai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

PR overview

This PR changes Bedrock passthrough Converse guardrail translation so tool definitions in toolConfig are excluded from guardrail requests while the original request is forwarded to Bedrock.

A significant guardrail bypass remains open: an authenticated caller can place denied or sensitive text in tool descriptions or input schemas, which are excluded from scanning but forwarded unchanged to Bedrock. No security issues have yet been addressed in this PR.

Open issues (1)

Fixed/addressed: 0 · PR risk: 7/10

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

@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yucheng-berri
yucheng-berri merged commit 853fed8 into litellm_internal_staging Sep 5, 2026
87 of 88 checks passed
@yucheng-berri
yucheng-berri deleted the litellm_lit5797_bedrock_passthrough_tool_defs branch September 5, 2026 01:40
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.

2 participants