# openai.BadRequestError: function_call 参数必须是有效 JSON - 检测到输入被截断

- **ID:** `llm/function-call-argument-truncation`
- **领域:** llm
- **类别:** input_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

使用函数调用时，LLM 生成的参数 JSON 超过了模型的上下文窗口，导致其在 JSON 中间被截断，产生格式错误的参数。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| openai==1.14.0 | active | — | — |
| openai==1.20.0 | active | — | — |
| gpt-4-0125-preview | active | — | — |
| gpt-3.5-turbo-0125 | active | — | — |

## 解决方案

1. ```
   减小函数描述或参数的大小，使其适应上下文窗口。
   ```
2. ```
   将函数调用拆分为多个较小的调用，每个调用使用更少的参数。
   ```
3. ```
   使用具有更大上下文窗口的模型（例如 gpt-4-32k 或 gpt-4-turbo）进行复杂函数调用。
   ```

## 无效尝试

- **** — The issue is context window exhaustion, not response token limit; max_tokens only caps the output length, not the input. (70% 失败率)
- **** — The truncation is deterministic given the same input; retrying won't change the behavior. (95% 失败率)
