LLM service quality and rollback
Keep fallback bounded and compatible
A fallback is an alternative route selected when the primary is unavailable or unsuitable under an explicit policy. A timeout or rate limit can justify a bounded retry or alternate provider, but a refusal, invalid answer or failed safety check must not automatically trigger another model to bypass policy. Before routing, verify the target supports the same response contract, modality, language, tool restrictions and data residency/processing permissions; test quality on the same suite. A fallback that costs less but leaks private data is unacceptable. This read-only FAQ example returns a decision, not a request. A 300 ms reserve must fit the remaining deadline and at least one call must remain. A 500 ms budget allows a preview, while 200 ms does not. The reserve is a hypothetical estimate, not a guarantee of completion. An actual orchestrator must enforce a deadline and cap total attempts across routes.
def choose_route(outcome, remaining_ms, remaining_calls, fallback): # Trusted policy metadata for a read-only FAQ service. if outcome == "ok": return "return_answer" if outcome not in ("timeout", "rate_limit"): return "review" if (remaining_calls > 0 and remaining_ms >= fallback["reserve_ms"] and fallback["compatible"] and fallback["approved"] and fallback["data_allowed"]): return "fallback_preview" return "review"
fallback = dict(reserve_ms=300, compatible=True, approved=True, data_allowed=True)print(choose_route("rate_limit", 500, 1, fallback))print(choose_route("timeout", 200, 1, fallback))print(choose_route("invalid", 500, 1, fallback))Rate limits, caches and version identity
Rate limits may count requests or tokens in a time window; quotas and retry headers vary by provider. Use bounded exponential backoff with jitter and honor applicable retry guidance within the overall deadline. Avoid retry storms by limiting concurrency, using a queue and circuit breaker, and escalating when the budget is exhausted. Do not replay side effects without an idempotency and reconciliation contract. Distinguish a provider prefix/KV cache (reuses intermediate computation) from an application response cache (returns an earlier answer). A response cache key must bind the authorized tenant/scope, request, release, model configuration, index/version and policy revision; recheck access and deletion status on every hit. A change of prompt, permissions or source data invalidates affected entries. TTL is a freshness limit, not an access check. Avoid storing sensitive responses unless authorized; use appropriate retention and encryption. A cache hit does not establish correctness. Measure hits, misses, invalidations and quality separately.
Gate releases on evidence
A new prompt can increase the invalid-answer rate without changing the model. Compare frozen r1 and r2 on the same versioned, disjoint evaluation set with predeclared rubric and safety cases. Suppose r1 passes 10/10 and r2 passes 8/10, with a 90% minimum. The gate fails r2. A single safety failure blocks even a perfect ordinary score; safety cases may overlap ordinary successes. Empty evidence is not a pass. This deliberately tiny synthetic fixture demonstrates policy, not statistically reliable quality. Use denominators and uncertainty, separate slices, check regressions against baseline and require accountable approval. The code returns rollback_review when the baseline is verified safe and compatible; otherwise pause_escalate. No live version change occurs. At the exact threshold the quality condition passes, but approval is still necessary.
def release_decision(correct, total, safety_failures, contract_ok, baseline_ready, approved, min_percent=90): # Synthetic held-out fixture; return advice, never change a live alias. if any(type(x) is not int for x in (correct, total, safety_failures, min_percent)): raise ValueError("integer counts required") if not (0 <= correct <= total and 0 <= safety_failures <= total and 0 <= min_percent <= 100): raise ValueError("invalid evaluation") if not contract_ok or safety_failures or (total and 100 * correct < min_percent * total): return "rollback_review" if baseline_ready else "pause_escalate" if not total: return "collect_evidence" return "eligible" if approved else "await_approval"
print(release_decision(8, 10, 0, True, True, True))print(release_decision(10, 10, 1, True, True, True))print(release_decision(10, 10, 0, True, True, False))print(release_decision(10, 10, 0, True, True, True))Plan recovery and verify quality drift
Track answer correctness, grounded citations, structured output validity, refusal appropriateness, retrieval relevance and human escalation by release. An error spike is a signal to investigate, not proof of a prompt defect: traffic composition, index staleness, provider behavior or validator changes could explain it. Pause rollout on critical failures, preserve redacted evidence, identify a compatible and safe previous release, restore its entire configuration bundle under approval, invalidate obsolete cache entries, reconcile any pending effects and rerun the regression suite. Verify actual resolved version, health, quality and permissions after the rollback; rollback cannot retract an answer already delivered. If the previous release is unsafe or unavailable, use manual handling or a non-AI baseline. Chapter 52 covers deployment monitoring; deeper serving infrastructure and distributed observability belong in LLM Engineering.
Practice and common mistakes
Use the same fixture to compare 9/10, 8/10 and 0/0. Introduce a safety failure with 10/10 ordinary quality and test an unavailable baseline. Change fallback data_allowed to False and verify that no preview is selected. Write a release record containing evidence version, owner, prior bundle, cache invalidation plan and post-change checks. Do not promote a version from an average alone, allow fallback to widen permission, reset an attempt budget for each provider or report a proposed rollback as an executed rollback.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
LLM service quality and rollback quiz
Assess trace minimization, cost, fallback and release recovery.
When may the mock fallback be selected?
Which condition must hold for an application response cache hit?
What happens with 10/10 correct and one safety failure?
What does an empty evaluation set establish?
What should be verified after an approved rollback?