Invalid schema for response_format 'vision_structured_output': In context=(), 'a...

2025年11月26日 14:13 状态: processing

🚨 错误信息

Invalid schema for response_format 'vision_structured_output': In context=(), 'additionalProperties' is required to be supplied and to be false.

🤖 AI解决方案

错误翻译


原文:Invalid schema for response_format 'vision_structured_output': In context=(), 'additionalProperties' is required to be supplied and to be false.
译文:response_format 'vision_structured_output' 的模式无效:在 context=() 中,'additionalProperties' 必须提供并且必须为 false。

原因分析

这是一个 JSON Schema 验证错误。在使用视觉结构化输出格式时,模式定义中缺少了必需的 additionalProperties 字段配置,或者该字段的值不是必需的 false

解决方案

json
{
"type": "object",
"properties": {
"analysis": {
"type": "string",
"description": "对图像的分析结果"
},
"confidence": {
"type": "number",
"description": "分析结果的置信度"
}
},
"required": ["analysis", "confidence"],
"additionalProperties": false
}

或者如果你的响应格式配置是这样:

python
response_format = {
"type": "object",
"properties": {
# 你的属性定义
},
"additionalProperties": false # 必须添加这一行
}

️ 预防措施

  • 完整的模式验证:在使用 JSON Schema 时,始终确保包含所有必需的关键字段,特别是 additionalProperties

  • 使用验证工具:推荐使用 JSON Schema 验证工具(如 ajv)在开发阶段进行模式验证,避免运行时错误