{
  "id": "llm/llm-structured-output-enum-violation-streaming",
  "signature": "ValidationError: 1 validation error for ResponseModel\ncolor\n  Input should be 'red', 'green', or 'blue' [type=enum, input_value='purple', input_type=str]",
  "signature_zh": "验证错误：ResponseModel的color字段应为'red'、'green'或'blue'，但收到'purple'。",
  "regex": "Input should be.*enum.*input_value",
  "domain": "llm",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "LLM generates enum values outside the allowed set when using structured output with streaming, due to incomplete constraint enforcement during partial token generation.",
  "root_cause_type": "generic",
  "root_cause_zh": "在流式处理中使用结构化输出时，由于部分令牌生成期间约束执行不完整，LLM生成超出允许集合的枚举值。",
  "versions": [
    {
      "version": "openai 1.12.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "openai 1.13.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "pydantic 2.5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Setting temperature to 0 to reduce randomness",
      "why_fails": "Enum violations occur due to token-level decoding constraints, not sampling randomness.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Increasing max_tokens hoping for complete output",
      "why_fails": "More tokens don't fix constraint enforcement; the model still generates invalid values.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use post-processing to map invalid values to nearest valid enum: valid_colors = {'red','green','blue'}; if output.color not in valid_colors: output.color = 'blue'  # fallback",
      "success_rate": 0.85,
      "how": "Use post-processing to map invalid values to nearest valid enum: valid_colors = {'red','green','blue'}; if output.color not in valid_colors: output.color = 'blue'  # fallback",
      "condition": "",
      "sources": []
    },
    {
      "action": "Switch to non-streaming mode for structured outputs: response = client.chat.completions.create(model='gpt-4', response_format={'type':'json_object'}, stream=False)",
      "success_rate": 0.95,
      "how": "Switch to non-streaming mode for structured outputs: response = client.chat.completions.create(model='gpt-4', response_format={'type':'json_object'}, stream=False)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use post-processing to map invalid values to nearest valid enum: valid_colors = {'red','green','blue'}; if output.color not in valid_colors: output.color = 'blue'  # fallback",
    "Switch to non-streaming mode for structured outputs: response = client.chat.completions.create(model='gpt-4', response_format={'type':'json_object'}, stream=False)"
  ],
  "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.82,
  "fix_success_rate": 0.75,
  "resolvable": "partial",
  "first_seen": "2024-04-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}