快速结论:在 LiteLLM Proxy 上给模型挂 Bedrock guardrail 后,只有消息文本会送去 ApplyGuardrail,模型返回的 tool-call 名称与参数、以及请求历史里 assistant 消息中的 tool calls 都不会被检查,日志却显示输出检查 success。排查时应先确认 guardrail 结果里是否存在“无 provider、无 usage 的 success 输出项”,再确认是否已开启 tool-call 扫描开关。
适用环境:Issue 涉及 LiteLLM(讨论提到 main bcd80b6 与 v1.105.1 表现一致)、LiteLLM Proxy 的 Bedrock guardrail hook(litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py)、Bedrock 真实 ApplyGuardrail API 调用;模型为 mock(openai/fake + mock_response),以便固定回复。操作系统、Python、CUDA、显卡等信息 Issue 未给出。
最快修复方案:升级到包含 PR #52999 的 LiteLLM 版本,并在 Bedrock guardrail 上开启 opt-in 开关 scan_tool_calls_as_text,让 tool-call 名称与参数以序列化文本形式送去筛查。
注意事项:该开关是 opt-in 而非默认行为:Bedrock 的 ApplyGuardrail 只接受 text 和 image 内容块,没有 tool-call 原生类型,因此参数只能按序列化文本送检,JSON 在 Bedrock 过滤器下的表现尚未明确。另一个细节是 ANONYMIZE 掩码逻辑只回写 choice.message.content,若不单独处理 tool arguments 的回写,可能出现“扫描时被掩码、实际仍按未掩码执行”的情况,因此 tool calls 更适合采用阻断而非掩码。具体开关配置写法以对应版本文档或 PR 为准,Issue 中未给出完整示例。
问题场景
用户在 LiteLLM Proxy 上配置了带 PII 过滤的 Bedrock output guardrail,并通过 POST /v1/chat/completions 调用一个带 send_email tool 的 agent。当模型这一轮只返回 tool calls(finish_reason: "tool_calls"、content 为空)时,参数中的收件地址 "to": "test@example.com" 不会被送去筛查;请求历史的 assistant tool call 也不会被当作 INPUT 送检。管理员的 guardrail 结果里仍会出现一条 success 输出记录,但 CloudWatch 只有 1 次 ApplyGuardrail 调用,且没有 EMAIL finding。
报错原文
[Feature]: Let the Bedrock guardrail screen tool-call arguments
原因分析
根据 Issue 评论中的代码定位,Bedrock guardrail hook 从未读取 tool_calls:
- 输出侧:
_build_response_content_items(L463)只在choice.message.content为非空字符串时取值(L473-477),纯 tool-call 回复因此没有内容可送检。 - 输入侧:
get_content_items_for_message(L505)在content为 None 时返回 None(L512-513),只含tool_calls的 assistant 历史消息因此不会贡献任何内容。 - 空内容分支(L990-997)会刻意跳过 ApplyGuardrail,因为 Bedrock 对空内容列表返回 400;这次跳过被记录成了 success,也就是管理员看到“已检查”但实际上未检查的原因。
因此这是功能缺口而非近期回归,Issue 称 v1.105.1 上逻辑相同。
环境排查
- 确认 LiteLLM 版本是否早于 PR #52999 合入的版本;讨论中点名了 main bcd80b6 与 v1.105.1 都存在该行为。
- 确认 Bedrock guardrail 配置中是否已开启
scan_tool_calls_as_text;未开启时 tool calls 不会被送检。 - 确认 guardrail 类型为 Bedrock,且检查走的是真实 ApplyGuardrail 调用;Issue 中模型为 mock,但 guardrail 调用是真实的。
- 查看 CloudWatch 中单次请求的 ApplyGuardrail 调用次数,以及 LiteLLM 请求的 guardrail results 里输出项是否带 provider 和 usage。
- Issue 未提供操作系统、Python、PyTorch、CUDA、显卡等环境信息,无需据此排查。
解决步骤
- 将 LiteLLM 升级到包含 PR #52999 的版本,避免继续使用未读取 tool_calls 的旧 hook 逻辑。
- 在 Bedrock guardrail 配置中开启
scan_tool_calls_as_text开关。开启后,模型返回的 tool-call 名称与参数会作为 OUTPUT 送检,请求历史 assistant 消息中的 tool calls 会作为 INPUT 送检。 - 保持 detect-only guardrail 时,可先观察结果是否出现 EMAIL / PROMPT_ATTACK 等 finding;不需要立即阻断业务。
- 如需阻断,优先把 tool calls 设为 block-only,而不是依赖 ANONYMIZE。因为掩码回写只作用于
choice.message.content,tool arguments 需要独立的回写路径,否则可能只掩码了扫描副本、实际执行仍为原文。 - 若仍需要自定义处理,可参考 Issue 中用户的做法:用 custom callback 自行把 tool-call 参数送到 ApplyGuardrail。这只是绕过方案,不是官方修复。
验证方法
用与 Issue 相同的场景复测:模型 mock 返回只含 send_email tool call、参数中带 test@example.com 的回复。开启 scan_tool_calls_as_text 后,请求的 guardrail results 中应出现带 Bedrock provider 的输出检查项及 EMAIL finding,CloudWatch 中该请求的 ApplyGuardrail 调用次数应为 2 而不是 1。再构造一条历史 assistant 消息只含携带 prompt attack 的 tool call,输入检查应出现 PROMPT_ATTACK finding。若使用阻断型 guardrail,被 Bedrock 判定的 tool call 应与被判定文本一样被阻断。
参考来源
AI 工具推荐
想把多个 AI 模型放在一个入口?
GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。
推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。
这个方案解决了吗?
可以继续搜索完整报错,或查看同一工具的其他排查指南。


