{
  "id": "llm/streaming-chunk-missing-content-field",
  "signature": "KeyError: 'content' in streaming response chunk",
  "signature_zh": "KeyError: 流式响应块中缺少 'content' 字段",
  "regex": "KeyError.*'content'",
  "domain": "llm",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Streaming chunks from LLM APIs may omit the 'content' field when they contain only metadata (e.g., finish_reason, usage info) or when the chunk is empty due to internal processing.",
  "root_cause_type": "generic",
  "root_cause_zh": "来自 LLM API 的流式块可能省略 'content' 字段，当它们仅包含元数据（如 finish_reason、使用信息）或由于内部处理而为空时。",
  "versions": [
    {
      "version": "openai-python>=1.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "gpt-4-1106-preview",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "gpt-3.5-turbo-1106",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This handles missing content but doesn't account for chunks that have no 'choices' array at all, which can still cause errors.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This causes silent data loss or crashes when the error occurs.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Streaming inherently delivers partial data; the issue is about chunk structure, not completeness.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use robust parsing that handles all chunk structures. Example: `for chunk in response: if chunk.choices and chunk.choices[0].delta and chunk.choices[0].delta.content: yield chunk.choices[0].delta.content`",
      "success_rate": 0.9,
      "how": "Use robust parsing that handles all chunk structures. Example: `for chunk in response: if chunk.choices and chunk.choices[0].delta and chunk.choices[0].delta.content: yield chunk.choices[0].delta.content`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use the OpenAI Python library's built-in streaming iterator which handles these edge cases internally: `for chunk in client.chat.completions.create(..., stream=True):` and access via `chunk.choices[0].delta.content` with null checks.",
      "success_rate": 0.95,
      "how": "Use the OpenAI Python library's built-in streaming iterator which handles these edge cases internally: `for chunk in client.chat.completions.create(..., stream=True):` and access via `chunk.choices[0].delta.content` with null checks.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement a retry with exponential backoff for chunks that raise KeyError, logging the raw chunk for debugging.",
      "success_rate": 0.7,
      "how": "Implement a retry with exponential backoff for chunks that raise KeyError, logging the raw chunk for debugging.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use robust parsing that handles all chunk structures. Example: `for chunk in response: if chunk.choices and chunk.choices[0].delta and chunk.choices[0].delta.content: yield chunk.choices[0].delta.content`",
    "Use the OpenAI Python library's built-in streaming iterator which handles these edge cases internally: `for chunk in client.chat.completions.create(..., stream=True):` and access via `chunk.choices[0].delta.content` with null checks.",
    "Implement a retry with exponential backoff for chunks that raise KeyError, logging the raw chunk for debugging."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://platform.openai.com/docs/api-reference/streaming",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-08-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}