Repository navigation
fix(bedrock): stop sending toolConfig tool definitions to guardrails on passthrough converse - #39281
Conversation
…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
|
bugbot run |
There was a problem hiding this comment.
Devin Review found 1 potential issue.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| tool_config: Final = body.get("toolConfig") | ||
| if isinstance(tool_config, dict): | ||
| _collect_strings(tool_config.get("tools"), holders) |
There was a problem hiding this comment.
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:
- Every other guardrail translation handler keeps tool definitions out of
texts. The chat and messages handlers pass them in the structuredtoolsinput, which a hook opts into; this handler flattened each name, description and JSON-schema string intotexts, so every text-scanning hook saw them as user content. - Bedrock's own native guardrail does not scan
toolConfigeither, so passthrough was stricter than the service it fronts. - Tool definitions are written by the same application that configures the guardrail. A caller who can set
toolConfigcan also setmessages, and messages are still scanned, along withtoolUse.input,toolResulttext and json, system blocks, andadditionalModelRequestFields. 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 SummaryThis 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.
Confidence Score: 5/5The 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.
|
| 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
|
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
PR overviewThis PR changes Bedrock passthrough Converse guardrail translation so tool definitions in 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 |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 63ef60e. Configure here.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
853fed8
into
litellm_internal_staging
TLDR
Problem this solves:
How it solves it:
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
How much lag is there in my data?, and atoolConfigholding a single tool whose description mentions a denied term400withViolated guardrail policyand the guardrail's blocked-input message, even though the user never typed the denied term"converse-stream"fails the same way0%pass rateAfter: the same request goes through, and only text the user actually sent is scanned
toolConfig200with the model's reply"converse-stream"streams normally400 Violated guardrail policy66.7%pass rate, with only the genuine violation counted as blockedSecurity consequence: with
experimental_use_latest_role_message_onlyturned 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
uv run pytest tests/test_litellm/<your_test_file>.py -vScreenshots / Proof of Fix
Shared setup for every case below, identical on both sides.
Real AWS Bedrock guardrail
6hbgpnnqoeb1inus-east-1, word policy denyinghexblade, blocked-input messageBLOCKED_BY_LIT5797_GUARDRAIL_INPUT. Real modelus.anthropic.claude-sonnet-4-5-20250929-v1:0. Real Postgres. No mocks anywhere.config.yamltooldesc.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
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.json400, body{"error":{"message":"Violated guardrail policy", ... "bedrock_guardrail_response":"BLOCKED_BY_LIT5797_GUARDRAIL_INPUT", ...}}2 Same request, streaming
.../converse-stream400, sameViolated guardrail policybody3 Denied term in the user message
-d @usercontent.json400 Violated guardrail policy4 What the guardrail was handed
CustomGuardrailloaded through the documented extension point recorded thetextslist it received for case 1["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
http://127.0.0.1:20799/ui/?page=guardrails-monitor6 Request Logs after the three requests above
http://127.0.0.1:20799/ui/?page=logsFailure, cost-, 0 tokens, because none of them reached the modelAfter (63ef60e)
1 Benign prompt, denied term only in the tool definition
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.json200, 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
.../converse-stream200, a normalvnd.amazon.eventstreamresponse starting withmessageStart3 Denied term in the user message
-d @usercontent.json400 Violated guardrail policy, unchanged4 What the guardrail was handed
["How much lag is there in my data?"]5 Guardrails Monitor after the three requests above
http://127.0.0.1:20797/ui/?page=guardrails-monitor6 Request Logs after the three requests above
http://127.0.0.1:20797/ui/?page=logsSuccessrows with real cost and real token counts, and oneFailure, the genuine violationNative 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.
toolConfig.tools[].toolSpec.descriptionAWS documents this behavior in Use a guardrail with the Converse API:
toolConfig.tools[].toolSpec.descriptionand.inputSchemaare 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
toolConfigis present/chat/completionsbehaves this way todayLow
additionalModelRequestFieldsis still scanned on purposetoolsinput eithertoolSpecis not the OpenAI tool shape guardrails expect thereFinal-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
ran /live-pr-risk and found no regressions/backward incompatible risks