Certopolis

Claude Certified Architect – Foundations

What invalidates the Claude prompt cache

A change invalidates its own level of the prompt and every level after it, in the order tools, system, messages. Changing a tool definition invalidates everything, while changing tool_choice or adding an image invalidates only the message blocks.

The invalidation order

The cache is a prefix match over tools, then system, then messages. Changing tool definitions, including their order, invalidates all three. Toggling web search or citations, or changing the speed setting, keeps the tools cache but invalidates system and messages. Changing tool_choice or adding or removing images keeps tools and system cached and invalidates only messages.

Thinking and effort settings always invalidate message blocks. Whether they also invalidate the tools and system cache depends on the model.

Common silent causes

A timestamp or request ID interpolated into the system prompt changes the prefix on every call, so each request writes a new entry and never reads one. Move that value into the first user message, after the breakpoint.

A tools array built by iterating a hash map can arrive in a different order after a restart, or with schema keys in a different order. Send the same tools in a fixed order and serialize schemas with sorted keys.

Rebuilding messages from a database can re-serialize earlier assistant turns or tool_result blocks slightly differently. Treat history as append-only and send earlier content back exactly as it came.

Finding the cause with cache diagnostics

Include a diagnostics object on every request, with previous_message_id set to null on the first turn and to the previous response id after that. The response then reports a cache_miss_reason such as system_changed, tools_changed or messages_changed, naming the first point where the two requests diverged. previous_message_not_found is not evidence your prompt changed. It usually means the earlier request did not include the diagnostics object. Diagnostics reports the earliest divergence only, so fix that one first.

Where the exam catches people

  • Believing a tool_choice flip rebuilds the whole cache: tools and system stay cached and only messages are invalidated.
  • Believing reordering tools is harmless: tools come first in the prefix, so any change there invalidates the entire cache.
  • Believing a longer TTL fixes a timestamp in the system prompt: the prefix differs on every request, so no TTL helps.
  • Believing cache diagnostics needs a beta header: the diagnostics object is the opt-in, and the old header is no longer required.

Written from Anthropic's documentation

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. Your support application keeps its tool definitions in the request for prompt-cache stability, but during a maintenance window the backing services are offline and Claude must answer from context alone without calling anything. Which approach should you take?

    Right. In the game that’s Renown for your Tool Design, MCP and Server Tools building.

    Not that one: D is right. In the game your Tool Design, MCP and Server Tools building would lose a little Renown, and this question would come back later.

  2. Your team relies on prompt caching to keep a large shared system prompt affordable and wants an alert that fires when the cache silently stops being hit — for example after an unnoticed change inside the cached prefix. The alert must key on a field the API already returns on every response. Which approach should you take?

    Right. In the game that’s Renown for your Context Management and Reliability building.

    Not that one: B is right. In the game your Context Management and Reliability building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    A prefix that is silently invalidated — by a timestamp, a per-request id or a reordered tool list — produces repeated writes and no reads, so the field sitting at zero across successive requests is the canonical diagnostic.

    Written from platform.claude.com/docs/en/build-with-claude/prompt-caching

  3. Your platform team runs a retrieval-augmented assistant on Claude Opus 5 (claude-opus-5). Every request assembles the retrieved chunks for the current question first, then a 40,000-token frozen policy prompt, and places a single cache_control breakpoint at the end of the policy text. The corpus rarely changes, yet usage.cache_read_input_tokens is zero on every request. What is the most likely cause?

    Right. In the game that’s Renown for your Prompt Engineering, Structured Output and Retrieval building.

    Not that one: A is right. In the game your Prompt Engineering, Structured Output and Retrieval building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    Putting per-question retrieved chunks ahead of the frozen policy text places volatile content inside the cached prefix, so no two requests share a prefix and the cache never hits. The fix is to order stable content first and let volatile content fall after the last breakpoint.

    Written from platform.claude.com/docs/en/build-with-claude/prompt-caching