A model outage, rate limit or invalid output should not take the whole feature down. Route down a tier instead: a cheaper model, a cached answer, or a deterministic path.

Fallback tiers and output validation

Fallbacks & Graceful DegradationDiagram with these labels, in reading order: validate output; on failure; User Request; Primary Model; (e.g. Claude Opus); Secondary Model; (e.g. GPT-4o-mini); Fallback Template; or Cached Answer; Output Validation; (schema/guardrail).validate outputon failureon failureUser RequestPrimary Model(e.g. Claude Opus)Secondary Model(e.g. GPT-4o-mini)Fallback Templateor Cached AnswerOutput Validation(schema/guardrail)
Fallback Mechanism for AI Models

The primary model, for example Claude Opus, handles most requests. If it goes down or returns invalid output, the system routes the request to a secondary model such as Sonnet or GPT-4o-mini. Secondary models are cheaper and quicker, at some cost in quality. If both fail, a last-resort tier answers with a deterministic template or a cached answer that was approved in advance.

Gateways such as LiteLLM, OpenRouter and Portkey route requests between the tiers. Each output is checked against a schema or set of guardrails, and a failed check sends the request to the next tier.

  • Take the primary model's output.
  • Validate it against the schema.
  • Fall back to the secondary model if validation or the call fails.
  • Use a cached answer or template as the last resort.
  • Choose the tier by user context and stakes.

What the last tier looks like depends on the task. A classifier can fall back to a keyword rule. A chat feature can say it cannot answer right now and offer to hand the conversation to a human.

A fallback answer is lower quality than the primary's

Serving stale cache when a database is down is the closest software analogue. The difference is that a fallback model returns lower-quality output, where a cache returns older data of the same quality. Stale data might be fine for a news site. A weaker model answering a medical question could misinform the user. Define in advance how much degradation each feature can tolerate.

Surfacing the raw error is the simplest alternative. It makes every provider hiccup a failure in your product and makes users question its reliability. A tiered system gives them some response and bounds the worst case.

Choosing the fallback by stakes

SituationFallback
User-facing, latency criticalAggressive fallback to smaller models
High stakes, such as medical or legalNo weaker model; defer to a human expert
Both models failPre-approved template or cached answer
Quality against availability Lower-tier models can give less accurate results. Check that each fallback is acceptable for the use case before enabling it.

Example scenario: 75% errors at peak hours

Suppose a feature fails with a 75% error rate during peak hours. A likely cause is rate limits or unavailability on the primary model, with fallbacks missing, misconfigured or not triggered.

Fallbacks & Graceful DegradationDiagram with these labels, in reading order: Model Outage Detected; Check Rate Limits; Evaluate Output Quality; Fallback to Cheaper Model; Return Cached Answer; Implement Deterministic; Path.Model Outage DetectedCheck Rate LimitsEvaluate Output QualityFallback to Cheaper ModelReturn Cached AnswerImplement DeterministicPath
Debugging fallback strategies
  • Check the error logs for the times and types of errors.
  • Compare the request rate with the primary model's rate limits.
  • Confirm the fallback paths are configured and working.

The fix is a fallback path that switches automatically to a cheaper model or cached response when the primary fails. The cost is lower output quality. Monitor the error rate and how often each fallback tier is used.

Back to the knowledge baseRequest an assessment