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
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
| Situation | Fallback |
|---|---|
| User-facing, latency critical | Aggressive fallback to smaller models |
| High stakes, such as medical or legal | No weaker model; defer to a human expert |
| Both models fail | Pre-approved template or cached answer |
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.
- 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.