Eval metrics lab
Handle failures and retries
Eval metrics lab is production work only when one frozen failure can be reproduced, one measurable gate can stop a release, and one operator can safely reverse it.
Before you start
Why this matters
Read this incident aloud: a canary prompt improves median latency but quietly reduces grounded answers for billing questions. In two minutes, write the earliest deterministic check that should fail, the telemetry signal you would inspect, and the action that must not happen automatically. Compare your answer with this chapter's boundary: telemetry excludes prompt text and customer identifiers; only pseudonymous request IDs are retained.
1Learn the idea
Read
Reproduce failures and debug safely
Reproduce an average-latency chart stays green while the p95 and billing groundedness collapse without editing the prompt first. Load the frozen fixture, set a known release, replace network calls with the failing response, and capture one trace. Confirm that the failure happens twice. If it does not, the reproduction is not controlled enough to support a fix. Debug in transaction order: input acceptance, normalization, retrieval or routing, model/tool decision, output validation, then side effects.
Classify the fault before retrying. Timeouts, 429s, and temporary 5xx responses may be retryable with capped exponential backoff and jitter. Schema violations, authorization mismatches, unsafe tool requests, and failed quality assertions are not transient; retrying repeats risk and cost. Use a maximum attempt count and a deadline. For side effects, retry only behind an idempotency key or transactional outbox.
A fix is complete only when the reproduction becomes a permanent regression case. Add a negative assertion so the old unsafe or incorrect behavior cannot return silently. Preserve the trace ID and policy version in the test output, but redact payloads according to the same production policy. The operational response is to stop canary promotion, compare retriever spans, and roll back only if the quality breach persists.
For failure handling, start with the named reproduction and add controlled timeout, malformed output, duplicate delivery, and forbidden-action variants where relevant. Demonstrate that retries cannot multiply side effects.
Read
Focused implementation artifact
def execute_with_policy(operation, *, attempts=3):
for attempt in range(attempts):
try:
return operation()
except (TimeoutError, ConnectionError):
if attempt == attempts - 1:
raise
except (PermissionError, ValueError):
raise # deterministic or unsafe: never retry
def test_known_failure_is_contained():
case = {"route":"/api/chat","status":200,"latency_ms":4210,"groundedness":0.61,"tokens":1840,"cost_usd":0.018,"release":"canary-v17"}
report = aggregate(samples, window="5m", group_by=["release", "intent"])
assert report.p95_ms < 3000 and report.quality_rate >= 0.92
Read
Diagnose before retrying
Run the named reproduction—an average-latency chart stays green while the p95 and billing groundedness collapse—with a frozen clock and recording adapters. Capture the ordered calls and one trace. Re-run it to prove determinism, then locate the first stage whose actual output differs from its contract. Change only that stage. Prompt tuning is not a substitute for an authorization, idempotency, schema, or accounting fix.
Inject a timeout before any side effect and another after the dependency reports success. The first may be retried under a deadline; the second requires reconciliation because blind retry could duplicate work. Prove attempt count, backoff cap, and final error classification. Deterministic policy failures must make one attempt. Side effects require an idempotency key or transactional outbox.
Turn the reproduction into a permanent test and assert the old behavior is absent. Recompute grounded success rate and p95 latency under retries so hidden attempts do not improve the denominator. Emit rag_grounded_success_ratio with error_type from a bounded enum. If containment fails, stop canary promotion, compare retriever spans, and roll back only if the quality breach persists.
Continue learning · glossary & guides
-
Are transient and deterministic failures classified differently?
-
Are deadlines, retry caps, and idempotency tested?
-
Does telemetry expose the first broken stage safely?
-
Local references: Glossary: SLO · Glossary: observability · Cheatsheet: production ops signals