Skip to content
mentoor

Topic 1 of 5 · 5 min read

Fallback models and providers

Goal: Design a fallback chain for a feature and name the eval that must cover the fallback path.

A fallback is a second model or provider that takes over when the first fails, and it only helps if you have already tested your feature on it. An untested fallback is a guess that you will first run during an outage.

Check yourself · 1 of 3

Which failure should normally trigger a switch to the fallback model?

Choose one answer

Why it matters

Every hosted model API has bad hours: rate limits, overloaded errors, regional incidents, a deprecated model name. If your feature has one model behind it, each of those becomes your outage. A fallback turns an outage into a quality dip.

How to design the chain

  1. Decide what triggers a fallback. Network errors, 5xx responses, 429 rate limits and timeouts are good triggers. A 400 for a malformed request is not: the second model will reject it too. A content-policy refusal is a product decision, not a reliability event.
  2. Pick the order by what you lose. Same model on a second host (for example an open-weight model served by two vendors, or Claude through a cloud marketplace) keeps behaviour nearly identical. A different family (Claude, then GPT, then Gemini) gives independence from one vendor's incident but changes tone, format and tool-call habits. A smaller model from the same family is cheap and fast but weaker.
  3. Keep prompts portable. Put model-specific tricks behind a per-model template. Ask for structured output with a schema, and validate it in your code, so a different model's formatting quirks fail loudly.
  4. Test the fallback path. Run your eval set against every model in the chain and record the score. Also run it in CI with the primary forced to fail, so you know the switch itself works.
  5. Tell people and tell yourself. Tag each response with the model that served it, log fallback rate, and alert when it rises. If the answer is visibly weaker, say so in the UI.
model_list:
  - model_name: support-chat
    litellm_params: { model: anthropic/claude-sonnet-latest, timeout: 30 }
  - model_name: support-chat-backup
    litellm_params: { model: openai/gpt-4o-mini, timeout: 30 }
router_settings:
  fallbacks: [{ "support-chat": ["support-chat-backup"] }]

Before and after

Weak: the team adds a fallback model name to the config and ships. During the next incident the backup returns JSON wrapped in prose, the parser throws, and users see the same error as before.

Fixed: the backup was in the eval suite, the prompt asks for schema-constrained output, the parser handles both, and a dashboard shows 4 percent of calls served by the backup that day.

What goes wrong

  • Fallback to a model that has the same dependency, such as two apps hosted in the same cloud region.
  • Silent quality drop. Users get worse answers and nobody notices because success rate looks fine.
  • Retrying the same dead model first for minutes before falling back, so users wait through every timeout. Fall back after a small number of fast attempts.
  • Stale fallback. The backup model is deprecated or its key expired because it was never exercised.

Examples

A chain for a support-chat feature

Primary: Claude Sonnet. First fallback: GPT-4o mini through a different vendor, after two failed attempts under 10 seconds. Last resort: a static message with a link to the help centre. The eval suite scores all three, and the release is blocked if the backup falls below the agreed minimum on the refund-policy questions.

The backup that broke the parser

A router falls back from one model to another that wraps JSON in a markdown fence. The code calls JSON.parse on the raw text and throws. The fix is a schema-constrained output mode, or a parser that strips fences, plus a test that feeds the backup's real output to it.

Key points

  • Fall back on transient failures such as 5xx, 429 and timeouts, not on malformed requests that every model will reject.
  • The same model on a second host changes behaviour least; a different family adds vendor independence but changes format and tone.
  • Keep prompts portable and validate structured output in your own code so a backup model's quirks fail loudly.
  • Run the eval set on every model in the chain and test the switch itself with the primary forced to fail.
  • Log which model served each response and alert on fallback rate, because success rate alone hides a quality drop.

Common mistakes

  • Adding a fallback model name to the config without ever running it against the eval set.
  • Falling back on errors that no other model can fix, such as an oversized prompt or invalid request.
  • Using two providers that share one underlying cloud region or one API key quota.
  • Hiding the switch: no model tag in logs, no alert on fallback rate.

Check yourself · 2 of 3

Why must the eval set run against the fallback model too?

Choose one answer

Check yourself · 3 of 3

Success rate looks healthy during an outage, yet support tickets about bad answers rise. What was most likely missing?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic