![[Bug]: `experimental_use_latest_role_message_only` erroneously sending tool and assistant prompts to guardrail](https://www.chat-gpts.plus/wp-content/uploads/2026/06/23476-036ac554.jpg)
[Bug]: experimental_use_latest_role_message_only erroneously sending tool and assistant prompts to guardrail
快速结论:该 Bug 发生在 LiteLLM Proxy 使用 Bedrock Guardrail 并启用 experimental_use_latest_role_message_only: true 时。配置期望仅将最新角色的用户消息发送给护栏检查,但实际错误地将 role: "tool" 和 role: "assistant" 的提示也发送给了护栏,导致预期外的拦截。优先排查是否在 pre_call 模式下错误地包含了非用户角色的消息。
问题场景
用户在 LiteLLM Proxy 中配置了 Bedrock Guardrail,并启用了 experimental_use_latest_role_message_only: true(该功能预期只发送最新的系统提示和第一条用户提示)。但在实际使用中,当最新角色消息是 tool 或 assistant 时,这些消息也被发送给了护栏检查,即使护栏配置为 mode: [pre_call](仅调用前执行)。用户预期护栏应过滤掉非用户角色的消息,但实际发生了误判。
报错原文
Error: Guardrail blocked due to assistant prompt sent during pre_call mode.
Showing role: "tool" prompt getting send to guardrail.
Showing role: "assistance" prompt getting sent to guardrail even though it's configured for only pre_call.
Desired behaviour is that the system role will be validated in the post_call.
原因分析
可能原因:experimental_use_latest_role_message_only 在判断“最新角色消息”时存在逻辑漏洞。
- 角色过滤不严格:该功能设计上可能仅过滤了
role: "user"的消息,但未正确处理或排除role: "tool"和role: "assistant"的消息。导致这些非用户角色的消息被错误地纳入护栏检查的有效负载中。 - 预调用模式逻辑缺陷:配置为
mode: [pre_call]时,系统本应只在调用前检查用户输入。但当前代码可能错误地将tool和assistant角色的消息也视为需要检查的“最新角色消息”。
环境排查
- LiteLLM 版本:v1.81.0(用户报告版本)
- 护栏提供商:AWS Bedrock Guardrail
- 护栏配置:
mode: [pre_call],并设置experimental_use_latest_role_message_only: true
解决步骤
- 确认 Bug 存在:在
guardrails配置中移除experimental_use_latest_role_message_only: true,改为默认行为。观察护栏是否还会错误拦截tool和assistant消息。这可以排除是否有其他配置干扰。 - 等待上游修复:该 Issue 已由维护者 @krrish-berri-2 标记优先处理,但 Issue 关闭时并未提供具体修复补丁。建议关注 Repo 中的最新 Release 或 PR,更新至 v1.81.0 之后的版本以获取修复。
- 临时规避方案:如果必须使用
experimental_use_latest_role_message_only,可在应用层确保发送给护栏的消息结构中,手动过滤掉role: "tool"和role: "assistant"的消息,只保留role: "user"和必要的system提示。但需注意这并非根本解决方法。 - 确认 post_call 行为:如果护栏在
post_call模式下执行,Bug 可能影响不同。开发者应确认在post_call模式下,系统角色消息是否会被正确处理。Issue 中提到“Desired behaviour is that the system role will be validated in the post_call”,意味着当前 post_call 对此逻辑也可能有隐患,需谨慎测试。
验证方法
在修复后的版本中,使用包含 tool 和 assistant 角色的最后一条消息(如用户消息后跟工具调用结果)再次发送请求。确认护栏仅拦截包含冒犯性内容的用户消息,而不再拦截 tool 或 assistant 角色消息。如果环境允许,可以对比 experimental_use_latest_role_message_only: true 开启前后护栏的拦截日志,确保非用户角色消息被正确跳过。

![[Question]: Knowledge graph extraction problem](https://www.chat-gpts.plus/wp-content/uploads/2026/06/7119-a01a8c11-768x403.jpg)
![Misc. bug: [ROCm] Significantly lower token generation performance vs Vulkan on RX 7900 XTX (gfx1100)](https://www.chat-gpts.plus/wp-content/uploads/2026/06/20934-97b8a216-768x403.jpg)
