[Bug]: Bedrock Claude 5 json_schema without thinking: the json tool path returns empty content_filtered replies (Opus/Sonnet 5.5)

在 LiteLLM 中给 Bedrock Claude 5 系列(Opus 5.5 / Sonnet 5.5 等)传 response_format 且不启用 thinking 时,请求会走 json tool 路径,该路径在 Bedrock 上返回空内容且 finish_reason="conte

快速结论:在 LiteLLM 中给 Bedrock Claude 5 系列(Opus 5.5 / Sonnet 5.5 等)传 response_format 且不启用 thinking 时,请求会走 json tool 路径,该路径在 Bedrock 上返回空内容且 finish_reason="content_filter"。优先升级到包含 #49703 修复的版本,并确认模型已切到 native output 路径。

适用环境:LiteLLM 1.88.6、1.106.1、1.107.0rc2 及 main @ 6bc1b2b3;boto3 1.43.116;Python 3.12。测量走 Bedrock Converse(boto3),区域 us-east-1,global. 推理配置文件;涉及模型 Opus 5、Opus 5.5、Sonnet 5、Sonnet 5.5(以及 Haiku 5.5 的对照测试)。

最快修复方案:升级到含 #49703 的 LiteLLM 版本;按维护者说明,自 v1.110.0 起 Opus 5 使用 native output,示例请求不再出现 content_filter。

注意事项:#49703 的修复思路是:不启用 thinking 的 json_schema 请求改用 native output,不再走不受支持的 forced tool;无法用 native output 表达的 schema 按现状回退到 tool 路径,这部分仍可能受原问题影响。native output 在 Opus 5.5 上会停止 adaptive thinking,但非 thinking 请求不存在这一取舍。另需注意本次示例的回复接近 700 tokens,max_tokens=800 余量偏小,应适当调高。

问题场景

通过 LiteLLM 调用 Bedrock 上的 Claude 5 系列模型(如 bedrock/global.anthropic.claude-opus-5-5),传入 Pydantic 模型作为 response_format(JSON schema),且不启用 thinking。自 #46870 起,这类请求会走 json tool 路径;该路径在 Bedrock 上对这批模型不可靠:Opus 5.5 / Sonnet 5.5 返回空回复并带 finish_reason="content_filter"(旧版本 1.88–1.99 强制 tool 时改报 400),Opus 5 出现 content_filter 或不合 schema 的 payload,Sonnet 5 偶发嵌套对象被转成字符串。相同请求若改用 native output(outputConfig.textFormat,schema 按 AnthropicConfig.native_output_schema 清洗),每次都能返回合法 JSON。

报错原文

[Bug]: Bedrock Claude 5 json_schema without thinking: the json tool path returns empty content_filtered replies (Opus/Sonnet 5.5)

finish_reason: content_filter
message.content: ''

# 旧版本强制 tool 时的报错:
tool_choice: type "tool" and "any" are not supported for this model

原因分析

根因在于请求路径选择:在 LiteLLM 中,无 thinking 的 JSON schema 请求被路由到 json tool 路径。而 Bedrock 上这批 Claude 5 模型既不支持强制 tool choice(tool_choice: type "tool"/"any" 直接 400),对非强制(auto)tool 又返回空的 content_filter 回复,因此该路径无法服务这些模型。Issue 中的测量显示,native output 路径 30/30 全部返回合法 JSON,forced tool 仅 13/30,auto tool 在 Opus/Sonnet 5.5 的扁平 schema 上 6/6 为空 content_filter。另需区分:当时 Sonnet 5.5 带有 supports_bedrock_native_structured_output 能力标记,Opus 5.5 没有,这可能是导致其无法自动切到 native output 的原因之一。

环境排查

  • 确认 LiteLLM 版本:升级前为 1.88.6 / 1.106.1 / 1.107.0rc2 / main @ 6bc1b2b3,修复由 PR #49703 引入,维护者说明自 v1.110.0 起 Opus 5 走 native output。
  • 确认 Python 版本(Issue 中为 3.12)与 boto3 版本(Issue 中为 1.43.116)。
  • 确认调用的 Bedrock 模型 ID 与推理配置文件(如 global.anthropic.claude-opus-5-5)。
  • 确认请求是否启用 thinking:该问题只出现在不启用 thinking 的 json_schema 请求中。
  • 确认 schema 复杂度:扁平 schema 与含 Literal、Optional、ge/le、min_length/max_length 的嵌套 schema 都可能触发,无法被 native output 表达的 schema 会回退到 tool 路径。

解决步骤

  1. 升级 LiteLLM 到包含 #49703 修复的版本(维护者已确认 #49703 合并;按回复,v1.110.0 起 Opus 5 使用 native output)。
  2. 保持原请求写法不变(response_format 传 Pydantic 模型、不启用 thinking),使 schema 请求走 native output 而不是 forced tool。
  3. 适当提高 max_tokens:Issue 中示例回复接近 700 tokens,max_tokens=800 容易截断。
  4. 若升级后仍复现,记录模型 ID、LiteLLM 版本、schema 类型(扁平或嵌套)和 finish_reason,并在原 Issue 中重新打开反馈。

验证方法

重新运行 Issue 中的复现脚本,检查 r.choices[0].finish_reason 不再是 content_filter、r.choices[0].message.content 不再为空字符串,且返回内容能通过对应 Pydantic schema 的校验。修复后维护者反馈该示例在 v1.110.0 上不再出现 content_filter。

参考来源

BerriAI/litellm #47687

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

这个方案解决了吗?

celebrityanime
celebrityanime
文章: 39644

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注