Code: invalid_request_error, HTTP Status: 400)

2026年05月21日 09:53 18.72 秒 success

错误信息

Invalid schema for function 'GetDiagnostics': null is not of type "array" (Model Provider Error Code: invalid_request_error, HTTP Status: 400)

AI 解决方案

🌐 错误翻译


原文: Invalid schema for function 'GetDiagnostics': null is not of type "array"
译文: 函数 'GetDiagnostics' 的定义模式无效:null 不是 "array"(数组)类型。

🎯 原因分析


根本原因是在定义 GetDiagnostics 函数(供AI模型调用)时,其参数模式(JSON Schema)定义有误。具体来说,某个本应为数组("array")类型的参数,其类型被错误地设置为 null,导致模型服务无法解析请求,从而返回 HTTP 400 错误。

💡 解决方案


检查并修正您传给模型API的 functions 定义。确保所有参数都正确定义了类型。以下是一个错误正确定义的对比示例:

错误示例(导致报错):

{
  "name": "GetDiagnostics",
  "parameters": {
    "type": "object",
    "properties": {
      "symptoms": {
        "type": "null", // ❌ 错误:此处应为数组类型
        "description": "A list of symptoms"
      }
    }
  }
}

正确修复:

{
  "name": "GetDiagnostics",
  "parameters": {
    "type": "object",
    "properties": {
      "symptoms": {
        "type": "array", // ✅ 修正为数组类型
        "items": {
          "type": "string" // 定义数组元素的类型
        },
        "description": "A list of symptoms"
      }
    }
  }
}

🛡️ 预防措施


  • 仔细校验Schema:在发送请求前,使用JSON Schema验证工具(如在线的[JSON Schema Validator](https://www.jsonschemavalidator.net/))检查您的 functions 定义是否合规。

  • 查阅官方文档:严格遵循模型提供商的API文档,特别是关于 functions 参数结构和数据类型的说明,确保每个字段都符合其 typerequireditems 等要求。