# openai.BadRequestError：在使用'tools'参数时不支持'response_format'参数

- **ID:** `llm/function-call-json-mode-conflict`
- **领域:** llm
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

OpenAI API 强制要求通过 response_format 进行结构化输出与函数/工具调用互斥，同一请求中不能同时指定两者。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| openai>=1.0.0 | active | — | — |
| gpt-4-turbo-2024-04-09 | active | — | — |
| gpt-4o-2024-05-13 | active | — | — |

## 解决方案

1. ```
   使用单个工具的函数调用包装所需的结构化输出：定义一个函数，其参数为输出模式，并将函数调用参数解析为结构化结果。
   ```
2. ```
   使用带有 response_format 的 JSON 模式，通过提示工程手动处理工具调用：在系统消息中包含工具描述，并解析 LLM 的自然语言响应以提取工具调用。
   ```
3. ```
   如果使用 OpenAI Python SDK v1.x，在使用 response_format 时显式传递 tools=None，并在后处理步骤中单独管理工具逻辑。
   ```

## 无效尝试

- **** — LLM cannot reliably execute tool calls without explicit tools parameter; output format may not match expected schema (75% 失败率)
- **** — response_format enforces strict output schema; tool calls have reserved structure that conflicts with arbitrary schemas (90% 失败率)
- **** — Older API versions may lack the feature entirely or have different buggy behavior; not a sustainable fix (60% 失败率)
