Choose a cache key for a versioned prompt
Check units and version numbers as you type. · 183 words
A cache stores a result for reuse instead of running the AI again. The cache key is the lookup name for that result. It must cover every input that could change the answer: the full prompt, prompt version, model version, and settings such as temperature. For example, book prompt v1 asks for three titles, while v2 asks for five and adds a genre. If the key contains only the user's question, the v2 request may receive the v1 list. This failure is silent because the answer looks valid but ignores the new instructions.
Now consider a shop assistant whose v1 prompt says, "Answer in one sentence" and whose v2 prompt says, "Answer in one sentence and list the price." A key containing only the user's question would collide across those versions. A safer key is shop-prompt:v2:sha256:8ac1..., where the version labels the template and the hash fingerprints the fully rendered input, including the actual user question. Including model-x and temperature=0 makes it more complete. A content hash changes after even a tiny edit. Version numbers organize releases; hashes detect edits that were not recorded.
Check your recall
A team changes the book prompt from v2 to v3 but leaves the model and temperature unchanged. What should change in the cache key, and why?
Check your answer
The key should include the new version and a hash of the exact v3 text, such as book-prompt:v3:sha256:<new hash>. Keeping the old v2 key could return the old five-title result to a request that should follow v3.
Sources and credits
Original KeyTouch lesson. Background reading · Google · Rules of Machine Learning.