# How Do You Order a Prompt So Caching Hits?

> Why the order of a prompt decides whether the provider's cache hits, what breaks a hit, and how to set it up, explained simply for your AI interview.

**In short:** Put everything that stays the same at the start of the prompt, in a fixed order: tools, then the system prompt, then reference material. Put the changing parts, such as a timestamp or the user's message, after a cache breakpoint at the end of the fixed part.

AI and LLM interview question Q089, Prompt and context engineering. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-do-you-order-a-prompt-so-caching-hits

## Say it in 30 seconds

A model reads the whole prompt on every call, and the provider can save the start of it, so the next call skips that work. The match runs from the very top, so I put what stays the same first: the tool list, the system prompt, then reference material. The cache breakpoint sits after that block. Anything that changes, like a timestamp or the customer's message, goes last. One timestamp near the top, and the cache misses on every chat.

## Say it in 2 minutes

Caching means the provider keeps the work it already did on the start of your prompt. The match is strict: the saved copy is reused only when the new request starts with the same text, in the same order. So the order question comes down to which parts stay the same from one call to the next.

My rule is fixed first, changing last. Tools come first, then the system prompt, then reference material like a fee table. The cache breakpoint goes at the end of that block. The timestamp, the customer's question and the chat history so far come after it, because they change on every call. If the timestamp sat at the top, every request would miss, and we would process the fee table again and again.

Three things break a hit in practice. Rewriting a tool's description changes the start of the prompt. Summarising old turns in the middle of the prompt does the same. Sending parallel requests before the first one has saved the cache means nothing is there to hit. On a bank's support assistant, with the same tools and fee table on every chat, fixing the order can be one of the cheapest savings to make.

I also check the result, not just the layout. The response usage fields show whether a prompt was cached, so I can see the hit rate on real traffic and not guess.

## What is prompt caching, in plain words?

A model reads your whole prompt on every call. Prompt caching lets the provider keep the work it already did on the start of that prompt, so a later call that begins the same way can skip it. The reused part is faster, and it costs less.

The provider checks whether the start of your prompt, up to a marked point, is already saved from a recent call. If it is, it reuses the saved copy. If not, it processes the prompt and saves it for next time.

Think of a hospital triage nurse with a protocol binder. The first pages are the same at the start of every shift, so she keeps her place in them. If someone swaps a page near the front, she has to reread everything after it, including the notes she has written since. A support bot works the same way. A made-up bank's assistant sends the same tool list and fee table on every chat. If a timestamp sits near the top, nothing after it can match a saved copy.

- **Prefix:** The start of the prompt, read in order from the top, and the only part the cache can match.
- **Cache breakpoint:** The marked point where the saved part ends. You place it, or the provider does.
- **Cache hit:** The new request's start matches a saved copy, so the saved part is reused.
- **Cache miss:** Something before the breakpoint changed, so the saved copy is not used.
- **Changing part:** Text that differs on each call, such as a timestamp or the user's message.

So the order decides the match. Put what stays the same first, and what changes last.

## What order makes the cache hit?

The provider's own docs describe the saved part as a fixed run of blocks, read from the top. Two quotes make the point:

> "Prompt caching covers the full prefix: tools, system, and messages (in that order), up to and including the block designated with cache_control" (Anthropic)
>
> "If developer instructions or shared material contain timestamps, user-specific content, or other dynamic content, place those at the end rather than the beginning" (OpenAI)

Anthropic's guide gives the same advice in plain terms: static content, meaning tool definitions, instructions, context and examples, goes at the start, and the breakpoint goes at the end of that fixed part, not on the block that changes. Some setups place the breakpoint for you: Anthropic's automatic caching puts it on the last cacheable block, so check where it lands.

*Diagram, Fixed parts first, changing parts last: The fixed parts sit in front and form one saved block. The breakpoint marks where that block ends. The timestamp and the customer's question come after it, so they never change the part the cache has already matched.*
1. The fixed part is read first and saved as one block.
2. The saved part stops at the breakpoint.
3. Next come the parts that change, timestamp first.
4. The model reads the saved part and the new part together.

1. **Tools first:** The tool list is the same on every call, so it goes at the very top. Change one tool's description and everything after it misses.
2. **System prompt next:** The role, the rules and the house style rarely change. They sit straight after the tools.
3. **Reference material after that:** A fee table or a policy pack that changes rarely goes here, and the breakpoint goes at its end.
4. **Changing parts last:** The timestamp, the customer's question and the chat so far go after the breakpoint, where they cannot break the saved part.

Worked example. A bank's support assistant gets the same 12 tools, a 40-page fee table and its rules on every chat. These are made-up numbers, but the shape is real: the fixed part is large and identical from chat to chat. With the fixed block first and the breakpoint after the fee table, each new chat reuses that block. With the timestamp at the top, each chat writes it again.

## What breaks a cache hit?

Anything that changes before the breakpoint stops the match for everything after it. OpenAI's guide says the whole prefix has to match, and that a change before a breakpoint means the prefix after it cannot match the saved entry.

*Diagram, Same lines, two orders, two results: Two prompts with the same lines in different orders. With the clock at the top, the second request misses. With the clock last, the fixed text matches and the second request hits.*
1. The first line changes, so everything after it changes too.
2. The fixed text comes first, so it stays the same.
3. The second request finds no match and processes it all again.
4. The second request reuses the fixed part; the clock and the question are new.

Here it is in plain Python, with a made-up bank bot. A hash of the prompt's start stands in for the saved copy, so you can see the match fail.

```python
# A made-up bank support bot. No real model: a hash of the prompt's start stands in for the provider's saved copy.
import hashlib

TOOLS = "lookup_account(card_id), open_dispute(txn_id)"
SYSTEM = "You are the support assistant for a mid-size bank. Quote fees only from the fee table."
FEES = "Fee table 2026: foreign card use 2.5%, late payment 29 pounds."

def saved_copy_key(blocks, breakpoint):
    # Everything up to the breakpoint must match, or the saved copy is not reused.
    upto = blocks[: blocks.index(breakpoint) + 1]
    return hashlib.sha256("\n".join(upto).encode()).hexdigest()[:8]

def clock_first(stamp, question):
    return ["Sent at " + stamp, TOOLS, SYSTEM, FEES, question]

def fixed_first(stamp, question):
    return [TOOLS, SYSTEM, FEES, "Sent at " + stamp, question]

for name, build in [("clock first", clock_first), ("fixed first", fixed_first)]:
    first = build("09:01", "Why was my card charged twice?")
    second = build("09:02", "Can I dispute the fee?")
    key1 = saved_copy_key(first, FEES)
    key2 = saved_copy_key(second, FEES)
    result = "hit" if key1 == key2 else "miss"
    print(name + ": request 1 key " + key1 + ", request 2 key " + key2 + ", request 2 is a " + result)
```

Output:

```text
clock first: request 1 key ea79421d, request 2 key 1dba1780, request 2 is a miss
fixed first: request 1 key e11d201b, request 2 key e11d201b, request 2 is a hit
```

1. **A timestamp at the top:** Dates, times and per-user names belong at the end. OpenAI says so directly, and a changed line up top is enough to lose the hit.
2. **Tools that change between calls:** OpenAI lists tool names, descriptions, schemas and ordering as things that change the tool part of the prefix. Keep them fixed.
3. **History rewritten in the middle:** Summarising, compacting or cutting old turns changes the prefix, so the saved copy resets.
4. **Parallel calls sent too early:** Anthropic's advice: if you need hits on parallel requests, wait for the first response before sending the rest. Nothing is saved until then.

Two more limits to know. A short prompt is not cached at all, even when it is marked. And a cache hit is never a promise: a key helps the provider route related requests together, but it does not guarantee a hit.

### How would you cut a support bot's caching bill?

A made-up bank support bot is slow and costly. The logs show almost no cache hits, even though every chat starts with the same 12 tools and fee table. Someone added the current time to the system prompt last month, and nobody noticed that it sat at the top.

- **Before: Clock at the top.** The system prompt opens with the time, so the saved copy never matches. Every chat pays full price for the tools and the fee table.
- **After: Fixed first, clock last.** Tools, rules and fees come first, with one breakpoint after them. Each chat reuses them, and only the question and the time are new.

Cache reads cost significantly less than normal input, so the fix pays off on every chat after the first one that writes the cache.

> **Tip:** Check it, don't assume it. Read the usage fields on each response to see whether the prompt was cached. If the hit count stays at zero, the order or the size is still wrong.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] Caching reuses the start of a prompt, and the match is exact from the top.
- [ ] Fixed parts first: tools, system prompt, then reference material.
- [ ] One breakpoint at the end of the fixed part, with the changing parts after it.
- [ ] Named breakers: a timestamp at the top, changed tools, rewritten history.
- [ ] Hits checked in the usage fields, not guessed.
- [ ] A key helps routing, but nothing guarantees a hit.

**Common traps**

- Trap: "Put the user message first, so the model sees it." Better: The message changes on every call, so it belongs after the fixed block. The model still sees it.
- Trap: "Add the date to the system prompt so the model knows it." Better: Put the date in the last block, after the breakpoint. The model still sees it, and the cache still hits.
- Trap: "A cache key makes the hit guaranteed." Better: A key only helps routing. The order of the prompt is what you control.

## Can you spot the cache breaker?

**Spot the cache breaker:** Each chat sends one of these system prompts. Which one misses the cache on every chat?

A. You are the support assistant for a mid-size bank. Quote fees only from the fee table.
B. Current time: 14:05, 26 November. You are the support assistant for a mid-size bank.
C. Keep answers under 120 words. Say when a human agent will take over.
D. Never promise a refund yourself. Refunds come from the case system.

**Answer:** B. The clock is the first line and changes between chats, so the saved copy never matches. Move the time into the customer's message, after the breakpoint.

**Quick check:** A bank's support assistant sends the same tools and fee table on every chat. Each chat adds a timestamp and the customer's question. Which order caches best?

A. Customer question, timestamp, fee table, system prompt, tools
B. Timestamp, tools, system prompt, fee table, customer question
C. Tools, system prompt, fee table, timestamp, customer question
D. Tools, timestamp, system prompt, fee table, customer question

**Answer:** C. Everything that stays the same comes first, and the breakpoint sits after the fee table. The timestamp and the question change on every chat, so they come last. The other orders put a changing line ahead of fixed text, and the match breaks there.

## Can you answer these from memory?

**Flash cards**

- **What does a cache hit need?** The start of the prompt must match the saved copy exactly, in the same order.
- **Where do the fixed parts go?** First: tools, then the system prompt, then reference material.
- **Where does the timestamp go?** After the breakpoint, at the end, with the other changing parts.
- **What breaks a hit?** A changed line before the breakpoint, such as a clock at the top or rewritten tools.
- **Is a hit guaranteed?** No. A key helps routing, but the provider does not promise a hit.
- **How do you check hits?** Read the usage fields in each response to see whether the prompt was cached.

## Likely follow-up questions

- Q095 How do you handle very long documents? https://designervenkat.online/interview/ai/how-do-you-handle-very-long-documents
- Q096 What is compaction (summarising history)? https://designervenkat.online/interview/ai/what-is-compaction-summarising-history
- Q097 What is structured note-taking (external memory)? https://designervenkat.online/interview/ai/what-is-structured-note-taking-external-memory
- Q098 How do you pick and order few-shot examples? https://designervenkat.online/interview/ai/how-do-you-pick-and-order-few-shot-examples
- Q326 Prompt cache vs semantic cache vs KV cache? (full answer coming)

## Learn it in depth

- [Prompt Caching](https://designervenkat.online/learn/ai-engineering/prompt-caching)
