When a model provider is down, an agent with one model is a stopped agent. A fallback model is the spare: a second model, from a different provider, that the agent switches to when the first one fails. LangChain’s model interface is built for this, letting you use one interface across providers and switch models with minimal code changes. The switch needs a trigger and a plan: which errors count as an outage, which model takes over, and what happens to the run in progress. Test the switch before you need it, because an untested fallback is a hope, not a plan.
What you need
- A primary model and a fallback model from a different provider, both with working credentials
- A list of errors that count as an outage, such as repeated 5xx responses or timeouts
- A test task that runs the same way on both models
Step 1: Wire the fallback model alongside the primary
Configure the agent with both models behind the same interface, so the switch is a change of model, not a rewrite of the agent. Keep the fallback’s credentials tested and current.
Step 2: Define the outage trigger and the switch
Write down which errors trigger the switch, such as three failed calls in a row or a provider timeout, and what happens to the run in progress: restart the step on the fallback, or resume from the last good state.
Step 3: Test the switch by blocking the primary
Run the test task with the primary model blocked and confirm the agent switches to the fallback and finishes the task. If the run fails instead, the trigger or the wiring is wrong.
Worked example: synthetic model fallback check
The table below is a synthetic example. It shows the expected result of the model fallback; no outage happened.
| Check | Expected | Result |
|---|---|---|
| Primary blocked, task runs | Yes | Pass |
| Fallback model finishes the task | Yes | Pass |
| Run resumes from last good state | Yes | Pass |
| Owner is told about the switch | Yes | Pass |
Expected result (UNTESTED). with the primary blocked, the agent switches to the fallback, finishes the task, and tells the owner. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- A fallback model may answer differently, so check its output quality on the test task, not just that it runs.
- Two providers means two bills and two sets of credentials to keep current.
- A switch that fires on a single transient error will flap between models.
- The fallback must have the same tools, or the switch will fail on the first tool call.
