Let’s Get Certified
Module 10 / 14 · Evaluation, testing, and optimization

Diagnose regressions and migrate models

Read a failing trace, account for latency and cost, and qualify a replacement model.

A release brings longer responses and more support escalations. Several components changed during the same week. Start by reconstructing the path from the user’s input to the observable outcome.

4.5 · Isolate the cause of a failed run

Replay one failing case against a known baseline with fixed inputs and revisions. If the correct passage is absent from the retrieval span, inspect query construction and index freshness. If evidence appears at retrieval but disappears before the model call, inspect serialization and truncation. If the model receives the passage but invents another value, test the prompt, evidence binding, and model suitability. A tool error shown as an empty success requires an adapter fix. Preserve correlation IDs and partial worker results through the join.

Bisect the trace before retuning a prompt

Case K17 previously cited clause 9. The current trace shows retrieval returning passages 3 and 9, both from the expected revision. The formatter keeps passage 3 and truncates passage 9. The model answers “insufficient evidence.” A second trace includes both passages in the serialized request but the answer cites an incompatible exception. Which experiments distinguish the failures?

Replay the first divergent stage

For K17, hold model, prompt and source fixed and replay with passage 9 preserved through formatting. If the correct citation returns, target serialization and evidence budgeting. Raising model tier leaves the missing evidence out of its input. Add a regression that checks the critical passage in the actual serialized request.

For the second trace, preserve both passages and test the decision rule about exceptions. Use an expert-labeled comparison and change one variable per replay. A prompt change that fixes that case and similar held-out examples supports an interpretation failure. If only the candidate model regresses under identical inputs, investigate model suitability separately.

4.6 · Optimize measured cost and latency

Break latency into queue wait, dependent network calls, time to first token, and generated output. Parallel calls contribute their critical path to elapsed time. Keep per-request cost separate from elapsed time. For example, if output generation consumes 2.8 of 3.5 seconds and users need four fields, test a concise structured reply before adding retrieval replicas. If unchanged prefixes repeatedly miss cache, examine the prefix order, traffic intervals, and cache-read statistics. Compare the proposed optimization against the same held-out quality floor and peak load.

Price a cache fix and time the critical path

One observed request waits 0.3 s in a queue, runs two independent reads taking 0.8 and 1.1 s in parallel, then generates for 2.4 s. The latency target is 3.0 s. An output limit reduces generation by 1.0 s and preserves the measured quality floor. A cache fix reduces billed input cost 35% but saves only 0.2 s on this request. Which change addresses the immediate complaint?

Trace the elapsed time

Elapsed time is 0.3 + max(0.8, 1.1) + 2.4 = 3.8 s. The output change projects 2.8 s. The cache change alone projects 3.6 s. Try the output limit on representative traffic and examine truncation, required fields and grounding. A single trace explains the mechanism. A load replay with the right arrival pattern establishes whether the p95 target is met.

Investigate the cache independently when cost remains a concern. Split creation, reads, uncached suffix and output tokens by workload and version. A high hit count on tiny prefixes can save less than a few hits on large ones.

Video background · freeCodeCamp at 0:54:00 · comparing caches at different stages of retrieval

Choose the cache that can safely serve a hit

Three caches can all report a hit while saving different work. Reusing a query embedding avoids recomputing its vector and needs a matching encoder and preprocessing version. Reusing retrieval results also depends on corpus and filter revisions and current entitlements. Reusing a final answer adds dependencies on the prompt, model, evidence and permissible audience. A Claude prompt-prefix cache still generates the answer for the current request.

Replay two callers asking the same question just after one caller loses access to the source. Recheck authorization before serving retrieved passages or a cached answer. Evict or bypass entries when the evidence is superseded. Measure saved milliseconds and cost at the stage actually reused. A longer expiry can make access or freshness failures persist even when the hit rate improves.

Further study · freeCodeCamp at 0:54:00 · caching embeddings, search results and generated answers · Claude documentation

4.7 · Plan a model version migration

Inventory pinned model IDs and the actual retirement deadline. Compare old and candidate versions on the same held-out set, with identical prompts and tools. Diagnose regressions by segment. Pinning can buy time only while the old version remains supported. Tune the candidate on a development set, then run the frozen release tests. Re-baseline a grader or expected output only if the desired behavior legitimately changed, with an owner and rationale. Canary the approved candidate, monitor outcomes, and verify that rollback or another qualified fallback is available during the intended window.

Keep a rollback available through retirement

An old version retires in 20 days. Its candidate passes the aggregate release target but falls from 95% to 82% on one required locale. Incident responders need two days to activate an alternate human queue. A proposed rollout pins the old model as the only fallback until day 21. Write a dated decision with a rehearsal.

Review a workable migration window

Pin the supported version during diagnosis. By day 8 isolate whether the candidate, prompt, or changed grading target explains the locale failures. Tune on separate development examples and rerun the frozen held-out suite. By day 14 canary eligible traffic with a named stop owner and measure that locale independently.

If the candidate still misses its gate, start qualifying or activating the human queue while the old version is available. Rehearse on day 16, allowing two operating days plus margin to verify capacity. By retirement, rollback must target something that still exists. An expected-answer rewrite requires an approved change in business behavior, not merely a new model giving a different answer.

Design exercise

A model cutoff is 20 days away and a candidate fails one critical locale. Budget time to repair and retest on unseen cases in that locale. Set a decision date before retirement, define a fallback for unresolved failures, and identify the person authorized to pause rollout.

Further reading · Claude model comparison and availability · Prompt caching · Evaluation design for agents

Knowledge check

Diagnose regressions and migrate models quiz

Answer 10 questions. Check each answer for an explanation.