{
  "id": "llm/prompt-caching-ignored-with-system-message-change",
  "signature": "Warning: Prompt caching disabled because system message changed between requests",
  "signature_zh": "警告：由于系统消息在请求之间发生变化，提示缓存已禁用",
  "regex": "Prompt caching disabled because system message changed",
  "domain": "llm",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "LLM API prompt caching (e.g., Anthropic's prompt caching) requires identical system messages across requests to reuse cached prefixes; any change invalidates the cache.",
  "root_cause_type": "generic",
  "root_cause_zh": "LLM API 提示缓存（如 Anthropic 的提示缓存）要求跨请求的系统消息相同才能重用缓存前缀；任何更改都会使缓存失效。",
  "versions": [
    {
      "version": "anthropic-python>=0.25.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "claude-3-opus-20240229",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "claude-3-sonnet-20240229",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This defeats the purpose of caching and actually guarantees cache misses.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Caching is most effective on system messages; user messages vary too much to benefit from caching.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The warning indicates caching is disabled; ignoring it means paying for full compute on every request.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure system messages are identical across requests that should benefit from caching. Use a template system: `system_message = {\"role\": \"system\", \"content\": [{\"type\": \"text\", \"text\": \"You are a helpful assistant.\", \"cache_control\": {\"type\": \"ephemeral\"}}]}` and reuse this object.",
      "success_rate": 0.9,
      "how": "Ensure system messages are identical across requests that should benefit from caching. Use a template system: `system_message = {\"role\": \"system\", \"content\": [{\"type\": \"text\", \"text\": \"You are a helpful assistant.\", \"cache_control\": {\"type\": \"ephemeral\"}}]}` and reuse this object.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If system message must change, structure the prompt so that the variable part is in the user message, keeping system message static. Example: system = \"You are a math tutor.\", user = \"Solve: {problem}\".",
      "success_rate": 0.85,
      "how": "If system message must change, structure the prompt so that the variable part is in the user message, keeping system message static. Example: system = \"You are a math tutor.\", user = \"Solve: {problem}\".",
      "condition": "",
      "sources": []
    },
    {
      "action": "Monitor cache metrics via API response headers (e.g., `x-should-cache`) to verify caching is working.",
      "success_rate": 0.7,
      "how": "Monitor cache metrics via API response headers (e.g., `x-should-cache`) to verify caching is working.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure system messages are identical across requests that should benefit from caching. Use a template system: `system_message = {\"role\": \"system\", \"content\": [{\"type\": \"text\", \"text\": \"You are a helpful assistant.\", \"cache_control\": {\"type\": \"ephemeral\"}}]}` and reuse this object.",
    "If system message must change, structure the prompt so that the variable part is in the user message, keeping system message static. Example: system = \"You are a math tutor.\", user = \"Solve: {problem}\".",
    "Monitor cache metrics via API response headers (e.g., `x-should-cache`) to verify caching is working."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-06-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}