A legal document processing platform generates Claude calls for contract clause classification. Their system prompt includes: 50 static legal definitions (2,000 tokens), 20 few-shot examples (4,000 tokens), and per-document context injected dynamically (500-2,000 tokens). They want to apply prompt caching strategically to maximize cost reduction. Which cache_control placement achieves the highest cache hit rate?
Select an answer to reveal the explanation.
Short Explanation
Here's the deal — prompt caching only hits when the cached prefix is identical. Put cache_control right after the static definitions and examples, before the changing document context, so you cache the full 6,000-token stable prefix every time.
Full Explanation
Prompt caching requires that the cached prefix be identical across requests. Dynamic content (per-document context) changes every request, so any cache boundary that includes dynamic content will never hit. The optimal strategy caches the maximal stable prefix — both the legal definitions and the few-shot examples (6,000 tokens total) — by placing cache_control at the boundary immediately before the changing document context. This maximizes tokens cached per hit. The approach that applies cache_control to the entire messages array, including the dynamic document context, caches the full prompt including dynamic context, which changes every request — cache hit rate would be 0% for documents with unique content. The approach that applies cache_control only to the static legal definitions caches only 2,000 tokens, leaving 4,000 tokens of cacheable few-shot examples uncached — suboptimal. The approach that applies cache_control to each few-shot example individually misunderstands prompt caching: caching works on prefixes, not arbitrary segments; individual examples in the middle of a messages array cannot be independently cached.