{
  "id": "llm/structured-output-schema-mismatch",
  "signature": "openai.BadRequestError: Invalid schema for response_format: 'properties' must be an object with string keys.",
  "signature_zh": "openai.BadRequestError: response_format的schema无效：'properties'必须是字符串键的对象。",
  "regex": "Invalid schema for response_format.*properties.*must be an object with string keys",
  "domain": "llm",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "The JSON schema provided in the response_format parameter is malformed, e.g., using integer keys or missing required fields like 'type'.",
  "root_cause_type": "generic",
  "root_cause_zh": "response_format参数中提供的JSON schema格式错误，例如使用整数键或缺少必需的字段如'type'。",
  "versions": [
    {
      "version": "openai>=1.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "openai>=1.12.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "OpenAI's schema validation is stricter than standard JSON; it requires specific keys like 'type': 'object' and 'properties' must be an object.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Older models may not support the same schema features; the schema must comply with OpenAI's JSON Schema subset.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use the Pydantic library to generate the schema automatically and validate it:\nfrom pydantic import BaseModel\nfrom openai import OpenAI\n\nclass ResponseModel(BaseModel):\n    name: str\n    age: int\n\nclient = OpenAI()\nschema = ResponseModel.model_json_schema()\nprint(schema)  # Check that 'properties' has string keys\nresponse = client.chat.completions.create(\n    model='gpt-4o-mini',\n    messages=[{'role': 'user', 'content': 'Extract info'}],\n    response_format={\n        'type': 'json_schema',\n        'json_schema': {'name': 'response', 'schema': schema}\n    }\n)",
      "success_rate": 0.95,
      "how": "Use the Pydantic library to generate the schema automatically and validate it:\nfrom pydantic import BaseModel\nfrom openai import OpenAI\n\nclass ResponseModel(BaseModel):\n    name: str\n    age: int\n\nclient = OpenAI()\nschema = ResponseModel.model_json_schema()\nprint(schema)  # Check that 'properties' has string keys\nresponse = client.chat.completions.create(\n    model='gpt-4o-mini',\n    messages=[{'role': 'user', 'content': 'Extract info'}],\n    response_format={\n        'type': 'json_schema',\n        'json_schema': {'name': 'response', 'schema': schema}\n    }\n)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Manually ensure the schema has the correct structure:\n{\n    'type': 'object',\n    'properties': {\n        'name': {'type': 'string'},\n        'age': {'type': 'integer'}\n    },\n    'required': ['name', 'age']\n}",
      "success_rate": 0.9,
      "how": "Manually ensure the schema has the correct structure:\n{\n    'type': 'object',\n    'properties': {\n        'name': {'type': 'string'},\n        'age': {'type': 'integer'}\n    },\n    'required': ['name', 'age']\n}",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用Pydantic库自动生成并验证schema：\nfrom pydantic import BaseModel\nfrom openai import OpenAI\n\nclass ResponseModel(BaseModel):\n    name: str\n    age: int\n\nclient = OpenAI()\nschema = ResponseModel.model_json_schema()\nprint(schema)  # 检查'properties'是否有字符串键\nresponse = client.chat.completions.create(\n    model='gpt-4o-mini',\n    messages=[{'role': 'user', 'content': '提取信息'}],\n    response_format={\n        'type': 'json_schema',\n        'json_schema': {'name': 'response', 'schema': schema}\n    }\n)",
    "手动确保schema具有正确的结构：\n{\n    'type': 'object',\n    'properties': {\n        'name': {'type': 'string'},\n        'age': {'type': 'integer'}\n    },\n    'required': ['name', 'age']\n}"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://platform.openai.com/docs/guides/structured-outputs",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-11-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}