A Python walkthrough for catching model regressions that an overall score can hide.
A new model routes 28 more support tickets correctly in a test of 1,000. It also misroutes eight additional critical tickets. Would you give it live traffic?
To answer that, decide which mistakes you can accept before you compare scores. Then test the candidate in three stages. Use replay to compare decisions, shadow traffic to check how the candidate behaves in production, and a small live rollout to measure what happens when its decisions take effect.
Compare the models on the same tickets
For a support-ticket router, the action is the queue a ticket goes to. Replay a recent, held-out set of tickets through both models using only the information available when each ticket first arrived. Apply each model's intended production thresholds, fallback behavior, and routing rules when comparing their final decisions.
Use a reference queue and severity label reviewed independently of either model's output. Define the critical slice using that reference severity. If you define it using the candidate's predictions, the very tickets it fails to recognize can disappear from the slice.
Here's an illustrative replay. Each row compares the two models on the same tickets.
| Ticket slice | Tickets | Current model correct | Candidate correct |
|---|---|---|---|
| Critical | 100 | 92 (92%) | 84 (84%) |
| Other | 900 | 738 (82%) | 774 (86%) |
| All tickets | 1,000 | 830 (83%) | 858 (85.8%) |
Suppose the team agreed before testing that critical-ticket routing could drop by at most two percentage points. The candidate drops by eight. Hold the release and inspect the critical tickets where the models disagree. For instance, check whether tickets that mention a service disruption indirectly tend to be sent to a general queue.
Reproduce the decision with Python
Save the snippet as compare_routes.py and run python compare_routes.py with Python 3. The script expands groups of synthetic outcomes into paired predictions. The inputs for each group are the ticket slice, reference queue, current route, candidate route, and number of tickets with that outcome.
def evaluate(tickets):
current_correct = candidate_correct = fixes = regressions = 0
for _, expected, current, candidate in tickets:
current_ok = current == expected
candidate_ok = candidate == expected
current_correct += int(current_ok)
candidate_correct += int(candidate_ok)
fixes += int(candidate_ok and not current_ok)
regressions += int(current_ok and not candidate_ok)
return current_correct, candidate_correct, fixes, regressions
groups = [
('Critical', 'incident', 'incident', 'incident', 80),
('Critical', 'incident', 'incident', 'general', 12),
('Critical', 'incident', 'general', 'incident', 4),
('Critical', 'incident', 'general', 'general', 4),
('Other', 'billing', 'billing', 'billing', 702),
('Other', 'billing', 'billing', 'general', 36),
('Other', 'billing', 'general', 'billing', 72),
('Other', 'billing', 'general', 'general', 90),
]
tickets = [group[:4] for group in groups for _ in range(group[4])]
critical = [ticket for ticket in tickets if ticket[0] == 'Critical']
for label, sample in [('All', tickets), ('Critical', critical)]:
current, candidate, fixes, regressions = evaluate(sample)
total = len(sample)
print(f'{label}: {current / total:.1%} -> {candidate / total:.1%}')
print(f' fixed: {fixes}; newly wrong: {regressions}')
current, candidate, _, _ = evaluate(critical)
max_drop_pp = 2
passes = 100 * (current - candidate) <= max_drop_pp * len(critical)
print('Replay decision:', 'PASS' if passes else 'HOLD')
All: 83.0% -> 85.8%
fixed: 76; newly wrong: 48
Critical: 92.0% -> 84.0%
fixed: 4; newly wrong: 12
Replay decision: HOLD
The paired counts show where to start debugging. Four critical tickets moved to the right queue, while 12 moved to the wrong one. Inspect those 12 before tuning a threshold or changing a feature. If you use those tickets to tune the model, set aside a fresh labeled sample for the next release decision.
The two-percentage-point limit is an example. For a real release, agree on the tolerated regression, the minimum number of labeled tickets per slice, and how you'll handle uncertain results before running the comparison. If a critical slice has too few labeled examples, collect more before calling it a pass.
Mirror live requests before letting the model act
Once the candidate passes replay, send copies of a sample of live requests to it. The current model still routes each ticket. The candidate records where it would have routed the ticket. Keep the candidate's path free of side effects such as changing queues or sending notifications. The SageMaker shadow testing documentation shows how a shadow response can be captured while the production response goes back to the caller.
Watch for missing inputs, timeouts, and routing disagreements by slice. Track tail latency, such as p95, which is the time within which 95% of measured requests complete. Log the model and routing configuration versions with each sampled decision. When reference labels arrive, join them to the paired decisions so you can separate disagreements from verified mistakes.
Shadow traffic shows how the candidate behaves on real inputs. To measure whether its decisions lead to more reassignments or longer waits, it has to route some tickets.
Run a canary with a rollback owner
A canary sends a small share of live traffic to the candidate while the current model continues serving a comparison group. Assign tickets consistently so updates to the same ticket stay on the same version. Keep track of who gets each version and check whether the groups cover the slices you need to judge. Google's SRE workbook on canarying explains how to compare the two versions and why a test needs enough representative traffic.
Before you start, save three decisions in the release ticket:
- Roll back if a defined stop condition fires, such as a verified critical ticket reaching an unowned queue. Name the on-call owner, rehearse the switch back, and make sure someone can find and reassign tickets already affected.
- Hold at the current traffic share if quality labels are too sparse, the first-response window is still open, or the evidence is ambiguous. Agree on how long you can wait before stopping the test.
- Expand after the observation window closes and the agreed quality and serving thresholds pass. For the router, compare measures such as critical-ticket routing, reassignment rate, first-response time, and serving errors.
Write down which result would change your mind before you look at the dashboard. If overall routing improves while critical tickets wait longer, the release ticket should already tell the on-call owner what to do.
For a wider view of what to measure before any release, including accuracy, latency, cost, safety, and release gates, see Lucent Innovation's AI evaluation framework guide.
This article was assisted by AI. The ticket-routing example and its figures are illustrative.
Top comments (0)