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 and Infographic
Here's the deal — 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.
Full explanation below image
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 first dynamic element. This maximizes tokens cached per hit. Option A caches the full prompt including dynamic context, which changes every request — cache hit rate would be 0% for documents with unique content. Option C caches only the definitions (2,000 tokens), leaving 4,000 tokens of cacheable few-shot examples uncached — suboptimal. Option D (per-example caching) misunderstands prompt caching: caching works on prefixes, not arbitrary segments; individual examples in the middle of a messages array cannot be independently cached.