{
  "id": "llm/structured-output-schema-mismatch-on-retry",
  "signature": "openai.BadRequestError: Invalid schema for response_format: 'properties' must be an object",
  "signature_zh": "openai.BadRequestError：response_format 的架构无效：'properties' 必须是一个对象",
  "regex": "Invalid schema for response_format.*'properties' must be an object",
  "domain": "llm",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "OpenAI API enforces strict JSON Schema validation for response_format; an empty or malformed 'properties' field (e.g., after schema transformation or caching) triggers this error on retry.",
  "root_cause_type": "generic",
  "root_cause_zh": "OpenAI API 对 response_format 强制执行严格的 JSON Schema 验证；空的或格式错误的 'properties' 字段（例如在架构转换或缓存后）会在重试时触发此错误。",
  "versions": [
    {
      "version": "openai==1.30.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "openai==1.35.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "pydantic==2.7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The schema is fundamentally broken; the API will reject it consistently until the schema is corrected.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Removing structured output forces the LLM to return free-form text, breaking downstream parsing logic that expects a JSON object.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The API expects the schema directly under 'response_format', not nested; this causes a different validation error.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Validate the schema before sending: ensure 'properties' is a non-empty object with valid JSON Schema types. Example: `if not isinstance(schema.get('properties'), dict) or len(schema['properties']) == 0: raise ValueError('Invalid schema')`",
      "success_rate": 0.9,
      "how": "Validate the schema before sending: ensure 'properties' is a non-empty object with valid JSON Schema types. Example: `if not isinstance(schema.get('properties'), dict) or len(schema['properties']) == 0: raise ValueError('Invalid schema')`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a schema generation library like Pydantic to create the JSON Schema, then convert to dict with `model_json_schema()`. Example: `from pydantic import BaseModel; class MyModel(BaseModel): name: str; schema = MyModel.model_json_schema()`",
      "success_rate": 0.95,
      "how": "Use a schema generation library like Pydantic to create the JSON Schema, then convert to dict with `model_json_schema()`. Example: `from pydantic import BaseModel; class MyModel(BaseModel): name: str; schema = MyModel.model_json_schema()`",
      "condition": "",
      "sources": []
    },
    {
      "action": "If caching schemas, deep-copy the schema dict before modification to avoid mutating the cached version (which may become empty). Example: `import copy; schema = copy.deepcopy(cached_schema)`",
      "success_rate": 0.85,
      "how": "If caching schemas, deep-copy the schema dict before modification to avoid mutating the cached version (which may become empty). Example: `import copy; schema = copy.deepcopy(cached_schema)`",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Validate the schema before sending: ensure 'properties' is a non-empty object with valid JSON Schema types. Example: `if not isinstance(schema.get('properties'), dict) or len(schema['properties']) == 0: raise ValueError('Invalid schema')`",
    "Use a schema generation library like Pydantic to create the JSON Schema, then convert to dict with `model_json_schema()`. Example: `from pydantic import BaseModel; class MyModel(BaseModel): name: str; schema = MyModel.model_json_schema()`",
    "If caching schemas, deep-copy the schema dict before modification to avoid mutating the cached version (which may become empty). Example: `import copy; schema = copy.deepcopy(cached_schema)`"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://platform.openai.com/docs/api-reference/chat/create#chat-create-response_format",
  "official_doc_section": null,
  "error_code": "invalid_response_format",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.88,
  "resolvable": "true",
  "first_seen": "2024-06-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}