400 Invalid JSON payload received. Unknown name "propertyNames" at 'tools[0].fun...

2026年06月13日 17:20 33.95 秒 success

错误信息

⏺ API Error: 400 Invalid JSON payload received. Unknown name "propertyNames" at 'tools[0].function_declarations[1].***.properties[0].value': Cannot find field. Invalid JSON payload received. Unknown name "propertyNames" at 'tools[0].function_declarations[1].***.properties[1].value': Cannot find field. Invalid JSON payload received. Unknown name "const" at 'tools[0].function_declarations[14].***.properties[1].value': Cannot find field. Invalid JSON payload received. Unknown name "propertyNames" at 'tools[0].function_declarations[19].***.properties[2].value': Cannot find field. Invalid JSON payload received. Unknown name "propertyNames" at 'tools[0].function_declarations[24].***.properties[4].value': Cannot find field. Invalid JSON payload received. Unknown name "const" at 'tools[0].function_declarations[24].***.properties[6].value.any_of[1]': Cannot find field. Invalid JSON payload received. Unknown name "propertyNames" at 'tools[0].function_declarations[33].***.properties[0].value': Cann…

AI 解决方案

🔍 分析报告

1. 🌐 错误翻译


原文:API Error: 400 Invalid JSON payload received. Unknown name "propertyNames" at 'tools[0].function_declarations[1].***.properties[0].value': Cannot find field.
译文:API错误:400 收到无效的JSON载荷。在 'tools[0].function_declarations[1].***.properties[0].value' 处发现未知名称 "propertyNames":找不到该字段。

2. 🎯 原因分析


  • 根本原因:您发送给API(很可能是Google Cloud或类似服务)的请求体中,function_declarations 的JSON Schema定义包含了一些该API版本不支持或不认识的字段(如 propertyNames, const)。

  • 错误位置:错误发生在 tools 数组的第0个元素(tools[0])内部的 function_declarations 数组里,具体是函数声明的参数描述部分(properties)。API的解析器在验证JSON结构时,发现了它不认识的字段名。
  • 3. 💡 解决方案


    您需要检查并修改您的 function_declarations 的JSON结构,移除或替换API不支持的字段。以下是常见的修正方向:

    方案一:使用基础字段(推荐)
    API通常只支持JSON Schema的一个子集。将复杂的JSON Schema字段替换为API支持的字段(如 type, description, enum, items, required 等)。

    方案二:简化参数结构
    如果参数结构过于复杂,考虑将其简化,或改用 type: "string" 并在 description 中描述期望的格式。

    示例:修正一个不兼容的函数声明

    {
      "name": "example_function",
      "description": "一个示例函数",
      "parameters": {
        "type": "object",
        "properties": {
          "param1": {
            "type": "string",
            "description": "参数1的描述"
          },
          "param2": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": ["option1", "option2", "option3"] // ✅ 使用支持的 `enum`
            },
            "description": "参数2,必须是给定选项之一"
          }
          // ❌ 移除或替换不支持的字段,如 "propertyNames", "const", "$ref"
        },
        "required": ["param1"] // ✅ 使用支持的 `required`
      }
    }
    

    4. 🛡️ 预防措施


  • 查阅官方文档:在构建请求前,务必查阅目标API的官方文档,明确其JSON Schema的精确规范和支持的字段列表。

  • 使用验证工具:在本地发送请求前,使用JSON Schema验证工具(如 ajv 库)对您的 function_declarations 结构进行预验证。

  • 增量构建:从最简单的函数声明开始,确保通过后再逐步添加复杂的参数定义,便于定位不兼容字段。