Projects › Safe AI caching

Case study · stage 9, Loyalty Support Modernization

Safe AI caching, decided by measurement

Where can a support workflow reuse AI work safely? Measured first: answer caching would be wrong every time here. Prompt caching was the safe win: 26.0% lower cost per case, with the same quality. The recommendation is to turn it on, with four conditions.

Independent project: a simulated client engagement for a fictional hotel group (two properties). Members, cases and messages are synthetic; there are no real customers and no production traffic. The model is Claude Haiku 5.5. One count uses public conversation data (MultiWOZ 2.2, crowd-written role-play: MIT licence per its repository, Apache-2.0 per its Hugging Face card). Money per year is a projection, not a measured saving. Built with an AI coding assistant (Claude Code), which wrote most of the code, tests and documents under my direction; I made the decisions, approved every live spend, and answer an exercise at the end of each milestone, logged apart from the assistant's work.

01 · The decision

Prompt caching on, answer caching never

In this workflow, answer caching is unsafe: 910 pairs of look-alike messages, and 0 share a correct answer. Prompt caching is the safe win: the AI re-reads the same instructions and the case's own conversation on every step, and the provider can bill those re-reads at a tenth of the input price.

The recommendation is to turn prompt caching on, with four conditions:

  • watch cost per case and cache reads for the first week, and switch it off if cost goes up;
  • keep quality checks as they are, and switch it off if validation failures pass their drift threshold;
  • get a security sign-off on how the provider holds cached prompts;
  • re-check the cache prices whenever the model or its price changes.

It's off by default, and one switch turns it off again without a restart.

02 · The result

26.0% lower cost per case, the same quality

The same 80 frozen cases, three runs without caching (A) and three with it (D), alternating, with every pass mark written down before the first run. All six pass marks were met.

No cache (A) against prompt caching (D), Claude Haiku 5.5, 80 cases a run
MeasureNo cachePrompt caching
Case success, each run78, 78, 78 of 8078, 78, 78 of 80
False approvals, each run0, 0, 00, 0, 0
Cost per case, all three runs$0.001723$0.001275 (−26.0%)
Cost per case, runs 1 and 2 (the clean comparison)$0.001732$0.001205 (−30.4%)
Calls after a case's first that read the cache, all three runs0 of 658650 of 678 (95.9%)
Model calls per case, runs 1 and 23.763.69
p95 time to a ready draft, runs 1 and 212.7 s, 13.8 s11.5 s, 12.0 s

Before any run, a projection from the stored token counts said 30.2%. Runs 1 and 2 came in at 30.4%. No model calls were avoided: caching makes the same calls cheaper. Latency isn't claimed either way: p95 was lower with caching, but p50 was the same or higher, and six runs on a shared laptop can't separate that from noise.

03 · Three flags

What travels with these numbers

  • A requeued job in run A3. A database lock error made the worker retry one case's investigation. That case took 464.7 s, A3's slowest, but A3's p95 is 14.78 s with or without it. The rule for which case a requeue hit was fixed before the run. The likely cause is a SQLite lock race in the benchmark setup, since fixed with a test that reproduces it.
  • Shared CPU in runs A3 and D3. Another batch ran on the same laptop during both: 29 CPU samples between 12% and 100%. That's why runs 1 and 2 are the clean comparison. Runs 1 and 2's CPU load wasn't sampled.
  • Invalid results in run D3. D3 had 5 rejected AI drafts, against 0 or 1 in every other run. The cause isn't established. Caching can't change what the model reads, and the two runs under load had the most fallbacks. Case success held at 78 of 80.
04 · Why not an answer cache

Same words, different right answer

An answer cache reuses a reply when a new message looks like an old one. Measured on the 280 frozen cases before anything was built:

  • After masking names, numbers and dates, 910 pairs of messages are word for word the same. None of those pairs shares the correct answer, and 654 even need a different next step. Each answer depends on that member's own stays and points.
  • Only 5 of the 280 cases contain a question mark, and none is a general policy question.
  • In public hotel dialogues (MultiWOZ 2.2, crowd-written role-play, 1,000 test dialogues), 148 of 1,713 hotel turns ask a public question about a named hotel, and 22 of those repeat an earlier one about the same hotel. Keyed without the hotel, 106 of 109 "repeats" would have had another hotel's answer to reuse.

So an answer cache can fit in front of a knowledge assistant for public questions, keyed by property and policy version. It doesn't fit in a claims workflow.

05 · How it was measured

Measure, build only what's supported, then prove it

  1. Measure first, from stored files. Split each stored live case into its model calls. On the three held-out runs, 68% of the input tokens were a re-send of the call before. This analysis made no model calls.
  2. Build only that layer. One request option, off by default, with the tests written first. Cached tokens are priced at their own rates and counted against the spending caps.
  3. Pre-register the comparison. Arms, cases, runs, pass marks and the cost estimate were all committed before any call. The code was frozen and checked before each run.
  4. Run it, and keep what went wrong. The first attempt at one run was killed by a bug in the run script, and that partial spend is kept on the record. Live spend was $0.81 of the approved $1.55.
06 · What it's worth

Small dollars, a rate that scales

The model is cheap, so the dollar saving is small: about $101 a year at 100 properties (16,000 cases a month, runs 1–2; $86 a year from all three runs), and about $2 a year at two properties. Projections, from the measured cost per case and an assumed volume.

The point is the method and the percentage. A 26 to 30% cut is a share of each case's cost, so it doesn't shrink as volume grows, and on a dearer model or a longer prompt a similar share would be worth far more (a projection, not measured here). And the method is what stops the costly mistake: an answer cache that looks like a win and gives members the wrong answer.

07 · Engineering

Engineering

  • One top-level cache marker on the provider request; a test checks the request is byte for byte the same otherwise.
  • A feature flag (off by default) and an administrator switch that turns caching off from the next AI run, with a reason and an audit trail.
  • Cached tokens priced at their own rates. When a rate is unknown, they're charged at twice the input price, so no cap can be passed.
  • Cache counts on each run record, the metrics page, a dashboard gauge and the OpenTelemetry spans.
  • main now needs all eight CI checks to merge, administrators included.
08 · Limitations

Limitations

  • Synthetic cases from templates, 80 per run, three runs per arm, on one laptop. No real customers, members or production traffic.
  • The held-out cases' labels were already public, so this is a paired comparison, not a held-out claim.
  • Latency isn't settled, and D3's invalid results are unexplained.
  • Not deployed to any live environment. Turning it on anywhere would be a separate, reviewed change for that environment.
09 · What's next

What's next

  • A pilot on real cases repeats the paired comparison before any claim.
  • An answer cache where answers really are shared: in front of the stage 1 knowledge assistant.
  • A test that publishes a policy whose own text carries an instruction, so the malicious-policy exercise (SEC-21) can be verified.
  • A longer retry window, so investigations outlast a customer-system outage longer than 16 s.

Drills (Milestone 13b): all seven failure drills passed in CI, each on its own throwaway stack with mock AI and synthetic data. The restore drill measured an RTO of 5.5 s and 9.2 s in two runs, with 1.2 s and 1.4 s of changes lost after the backup. These are a GitHub runner's numbers on a small synthetic database, not a production estimate; the targets stay RTO 1 hour and RPO 24 hours. The drill also found a real bug: a session revoked after the backup worked again after the restore. The fix ends every session, API token and break-glass grant after each restore (ADR-0096). The drills report

See every stage →