{
  "id": "llm/streaming-assistant-content-empty",
  "signature": "KeyError: 'content' — streaming response chunk missing 'content' field in assistant message delta",
  "signature_zh": "KeyError: 'content'——流式响应块中助手消息增量缺少'content'字段",
  "regex": "KeyError.*'content'.*streaming response chunk",
  "domain": "llm",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "When streaming responses that include tool calls, some chunks may contain only tool_calls without content; code that expects 'content' in every delta raises KeyError.",
  "root_cause_type": "generic",
  "root_cause_zh": "当流式响应包含工具调用时，某些块可能仅包含 tool_calls 而没有 content；期望每个 delta 中都有 'content' 的代码会引发 KeyError。",
  "versions": [
    {
      "version": "openai>=1.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "gpt-4-turbo-2024-04-09",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "gpt-4o-2024-05-13",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This masks the error but does not handle tool_calls; the application may miss tool call data entirely",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Skipping chunks may lose tool call data or other important deltas, corrupting the response",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Disabling streaming eliminates the error but increases latency and defeats the purpose of streaming for user experience",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check for both 'content' and 'tool_calls' in each delta: if 'tool_calls' is present, handle them separately; if 'content' is absent, initialize an empty string.",
      "success_rate": 0.95,
      "how": "Check for both 'content' and 'tool_calls' in each delta: if 'tool_calls' is present, handle them separately; if 'content' is absent, initialize an empty string.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use the OpenAI SDK's built-in streaming helper that automatically parses deltas into complete messages, such as client.beta.chat.completions.stream()",
      "success_rate": 0.9,
      "how": "Use the OpenAI SDK's built-in streaming helper that automatically parses deltas into complete messages, such as client.beta.chat.completions.stream()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement a robust delta accumulator that tracks both content and tool_calls across chunks, assembling them into a complete message before processing.",
      "success_rate": 0.85,
      "how": "Implement a robust delta accumulator that tracks both content and tool_calls across chunks, assembling them into a complete message before processing.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在每个 delta 中检查 'content' 和 'tool_calls'：如果存在 'tool_calls'，则单独处理；如果缺少 'content'，则初始化为空字符串。",
    "使用 OpenAI SDK 内置的流式处理辅助函数，自动将 delta 解析为完整消息，例如 client.beta.chat.completions.stream()",
    "实现一个健壮的 delta 累加器，跨块跟踪 content 和 tool_calls，在处理前组装成完整消息。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://platform.openai.com/docs/guides/streaming-responses/streaming-tool-calls",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-03-22",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}