Skip to content

Lesson 8 of 9 · 27m

Failure Modes and Graceful Degradation

Design for wrong answers, missing evidence, provider outages, unsafe output, and partial tool success before production designs them for you.

Traditional backend failures are often binary: the service is up or down, the query succeeds or errors. LLM applications fail in gradients. The answer can be fluent but wrong, grounded but incomplete, safe but useless, or correct for yesterday's policy. If the only failure mode you designed for is a provider 500, production will introduce you to the rest.

Build a failure taxonomy

Start by naming what can go wrong:

input failures          ambiguous request, missing data, unsupported language
retrieval failures      no evidence, wrong evidence, stale evidence, ACL leakage
model failures          hallucination, contradiction, verbosity, bad judgment
output failures         invalid schema, policy violation, unsafe content
tool failures           timeout, partial success, duplicate side effect
provider failures       rate limit, outage, model deprecation, latency spike

Each category needs detection, user-facing behavior, and an operational response. A missing-evidence case should not produce the same generic apology as a schema parse exception.

Missing evidence is a product state, not an error

For grounded workflows, the correct answer is often "I do not have enough reliable information." Make that state useful:

I could not verify the current cancellation policy for legacy Team plans.
I found the current standard policy, but your plan name does not match it.
I can connect you to support with this context attached.

This is not defeat. It is trust preservation. The worst answer is the confident invented one.

Validate outputs against policy before display

Use a post-generation gate for schema, unsafe content, unsupported claims, disallowed advice, and action authorization:

try:
    answer = AnswerSchema.model_validate_json(raw)
    enforce_answer_policy(answer, customer, evidence)
except (ValidationError, PolicyViolation) as exc:
    record_failure("output_gate", exc, request_id=request.id)
    return fallback_response(customer, reason="unable_to_verify")

The fallback can be a narrower deterministic answer, a retrieval-only result, or human handoff. Degradation should preserve value instead of merely hiding the failure.

Partial tool success is the hard case

Agents create workflows where step one succeeds and step two fails. Make side effects idempotent and expose the real state:

Created draft refund case rc_1049.
Payment provider lookup timed out, so no refund was issued.
You can safely retry; the existing draft will be reused.

Use idempotency keys and durable workflow records. Do not rely on the model to remember what happened across retries. Your system of record must know which tools ran and which compensated.

Provider failure needs a circuit breaker

Provider incidents are normal. Build bounded retries with exponential backoff and jitter, then degrade:

for attempt in range(3):
    try:
        return await call_primary_model(payload, timeout=25)
    except (RateLimitError, TimeoutError, ServiceUnavailable):
        await asyncio.sleep(min(2 ** attempt, 4) + random.random())
return cached_or_compact_fallback(payload)

A fallback model can help, but only if output contracts and safety behavior were evaluated for it. Automatic failover to an untested model is not resilience; it is a surprise deployment during an incident.

Design abuse and adversarial input as failures too

Prompt injection, data exfiltration attempts, jailbreaks, spam, and denial-of-wallet attacks belong in the failure matrix. Detection may be heuristic, but response must be architectural: least-privilege tools, isolated content, output authorization, rate limits, and tenant budgets. Do not expect a stern sentence in the system prompt to defend the application by itself.

Field notes

  • "Sorry, something went wrong" is operational laziness; classify retryable, degraded, and escalated states.
  • Record finish reasons, provider errors, retries, and fallback use per request.
  • Test what happens when the first retry succeeds after the client disconnected.
  • A graceful answer that violates tenant isolation is not graceful; correctness boundaries outrank UX polish.
  • Incident drills should include wrong-answer incidents, not only outages.

Was this lesson helpful?

Sign in to rate