llm
input_error
ai_generated
true
openai.BadRequestError: function_call 参数必须是有效 JSON - 检测到输入被截断
openai.BadRequestError: function_call arguments must be valid JSON - truncated input detected
ID: llm/function-call-argument-truncation
85%修复率
88%置信度
1证据数
2024-02-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| openai==1.14.0 | active | — | — | — |
| openai==1.20.0 | active | — | — | — |
| gpt-4-0125-preview | active | — | — | — |
| gpt-3.5-turbo-0125 | active | — | — | — |
根因分析
使用函数调用时,LLM 生成的参数 JSON 超过了模型的上下文窗口,导致其在 JSON 中间被截断,产生格式错误的参数。
English
When using function calling, the LLM generates argument JSON that exceeds the model's context window, causing it to truncate mid-JSON, resulting in malformed arguments.
官方文档
https://platform.openai.com/docs/guides/function-calling解决方案
-
减小函数描述或参数的大小,使其适应上下文窗口。
-
将函数调用拆分为多个较小的调用,每个调用使用更少的参数。
-
使用具有更大上下文窗口的模型(例如 gpt-4-32k 或 gpt-4-turbo)进行复杂函数调用。
无效尝试
常见但无效的做法:
-
70% 失败
The issue is context window exhaustion, not response token limit; max_tokens only caps the output length, not the input.
-
95% 失败
The truncation is deterministic given the same input; retrying won't change the behavior.