","error":{"type":"invalid_request_error","message":"***.***.content.0: unexpect...
🚨 错误信息
{"type":"error","error":{"type":"invalid_request_error","message":"***.***.content.0: unexpected `tool_use_id` found in `tool_result` blocks: tooluse_AEWdfDxjSmmbmzot12ayuo. Each `tool_result` block must have a corresponding `tool_use` block in the previous message."},"request_id":"req_011CYc7j61xJq7J6VqjtrYvU"}(traceid: 2abbb2e74aad9818ea5be94970fe90ce) (request id: 20260301092310460570461xJggOAD8)
🤖 AI解决方案
报错分析报告
1. 错误翻译
``
原文:..content.0: unexpected tool_use_id found in tool_result blocks: tooluse_AEWdfDxjSmmbmzot12ayuo. Each tool_result block must have a corresponding tool_use block in the previous message.
译文:..content.0:在tool_result块中发现意外的tool_use_id(值为tooluse_AEWdfDxjSmmbmzot12ayuo)。每个tool_result块必须在前一条消息中存在对应的tool_use块。
`2. 原因分析
根本原因: tool_result块引用了未在前一条消息中定义的tool_use_id(tooluse_AEWdfDxjSmmbmzot12ayuo)。
发生位置:..content.0处的 tool_result块,上下文是工具调用的结果与前序工具使用不匹配。3. 解决方案
确保tool_result的tool_use_id与前一条消息的tool_use块一一对应。以下是正确示例(以JSON为例):json
// 前一条消息(含tool_use)
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "tooluse_AEWdfDxjSmmbmzot12ayuo", // 需与后续tool_result的id一致
"name": "your_tool_name",
"input": { / 工具参数 / }
}
]
}// 当前消息(含对应tool_result)
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_AEWdfDxjSmmbmzot12ayuo", // 必须匹配前序tool_use的id
"content": "工具执行结果"
}
]
}
修复步骤:
找到 tool_result中的tool_use_id: tooluse_AEWdfDxjSmmbmzot12ayuo;
检查前一条消息是否有相同id的 tool_use块;
若无,则删除该 tool_result块或补充对应的tool_use块。4.️ 预防措施
最佳实践1:编写工具调用逻辑时,先定义 tool_use块并保存其id,再生成对应的tool_result`块(强制配对)。