Most LLM fallback code handles one kind of failure: the provider returns an error, so you try another model. The failures that hurt our users more were a different kind: a model that returns 200 OK with an answer you can't use. This post covers how we found that out, what we compared, and the fallback design we use now.
The situation
I'm the founder of CV by JD. People chat with an assistant that rewrites their resume for a specific job description. Each chat turn returns one structured response: the assistant's reply, a flag saying whether the resume changed (has_updates), the full rewritten resume (output_resume_markdown), and a few other fields.
For every turn we keep an ordered list of four models, roughly from cheapest to most capable. If one fails, the next one tries. I'll call this list the ladder and each model on it a tier:
User's message
│
▼
Tier 1: fast, cheap model ── handles almost every request
│ failed?
▼
Tier 2: another fast model
│ failed?
▼
Tier 3: a larger model
│ failed?
▼
Tier 4: the most capable (and most expensive) model
│ failed?
▼
A fixed "please try again" reply. The user's resume is left untouched.
This post is about one question: what exactly counts as "failed"?
The stakes are personal. People use a tool like this when an application matters to them, often close to a deadline. A failed turn wastes their time. A bad turn can be worse: it can replace a resume they were happy with by something broken.
How we got here
Our first fallback was the standard pattern:
try {
return await callModel(primary, messages);
} catch {
return await callModel(backup, messages);
}
On top of that, the provider's client library (SDK) retried failed requests on its own. It covered outages, timeouts and rate limits, and for a while that seemed like enough.
The problem
Then we started seeing turns that had clearly gone wrong even though the request itself had succeeded. So we started reading the responses that didn't throw. A few patterns kept showing up:
-
The empty update. The reply said "I've updated your resume", the
has_updatesflag wastrue, and the resume field was empty. To the user, their resume had vanished. - The missing field. A required field was simply absent, so the app couldn't render the turn.
- The leaked prompt. Now and then, a reply repeated parts of our system prompt back to the user.
- The no-op. On later messages in a conversation, one model often returned the previous resume unchanged, said it had made updates, and repeated its last reply.
None of these threw an exception, so none of them reached the catch. Our fallback never ran for the failures users actually saw.
There was a second, quieter problem. With SDK retries on, a slow first model meant the SDK retried, then our code moved to the backup, and the backup's SDK retried too. One user message could turn into several requests, and the latency was hard to explain from the logs.
What we researched
We went through failed and bad turns in our logs and sorted them by cause. Two things stood out.
First, most of the bad-but-successful responses fell into a small number of patterns that could be detected cheaply and with certainty. We didn't need another model to spot an empty resume or a missing field. A few lines of code could do it.
Second, errors weren't all the same. A rate limit, a timeout, an authentication error, a truncated response and unparseable JSON each call for a different fix, so we wanted every failure labelled with its cause.
The options we found
| Option | Catches errors | Catches bad answers | Notes |
|---|---|---|---|
| SDK retries only | Yes | No | Simple, but retries the same model with the same problem |
| The gateway's own fallback list | Yes | No | OpenRouter (a service that gives you one API for many models) can try another model when a request errors, but it can't judge whether a successful answer is usable |
| A second model that judges every answer | Yes | Yes | Catches subtle problems, but adds cost and latency to every turn, for failures that plain code can spot |
| Our own ladder that validates every answer in code and escalates on failure | Yes | Yes | More code to own, but we decide what "usable" means |
What we chose, and why
We built our own ladder. Two options catch bad answers, and ours is the one that doesn't add an extra model call to every turn. (Separately, we do use a second model to check that a rewrite doesn't invent facts. That's a different job, covered in the first post in this series.) We wired it up as a small graph in LangGraph, a library for describing multi-step LLM workflows as steps (nodes) and the paths between them (edges). The flow looks like this:
1. Call the current tier's model
│
2. Check the answer in code ──── usable? ──▶ send it to the user
│ not usable (or the call errored)
▼
3. Any tiers left? ── yes ──▶ move to the next tier, with a note on
│ what went wrong, and go back to step 1
│ no
▼
4. Send a fixed, safe reply. The user's resume stays as it was.
Here's what happens to one turn, step by step.
1. Call the model. The first tier returns a response. If the request throws, we record the error and treat the response as empty.
2. Validate the answer. Code checks that every required field is present, that the resume isn't empty when has_updates is true, and that the reply doesn't repeat distinctive parts of our system prompt. An error and a bad answer are handled the same way: both count as "no usable response", so we try the next tier.
3. Escalate with a reason. If the response isn't usable, we move to the next tier and pass along a note about what went wrong. For the empty update, it looks like this:
Previous response set has_updates=true but output_resume_markdown was empty. When has_updates is true you MUST include the full updated resume.
So the next model knows which mistake to avoid. Between tiers we pause briefly, a little longer each time, so we don't pile more load onto a provider that's already struggling.
4. Stop safely if every tier fails. The last step isn't another model. It's a fixed, valid response that asks the user to share their resume and the job description again, tells them no credits were used, and sets has_updates to false. The app then keeps whatever resume the user already had. This is the rule we care about most: a failure must never replace a working resume with a broken one.
A few details made this reliable:
- One owner for retries. Every model is created with SDK retries turned off, and the graph decides when to try again. That removed the stacked retries and made latency predictable.
-
Named failure reasons. Every failed attempt is tagged as
rate_limit,overload,timeout,auth_error,invalid_schema,malformed_response,parse_error,missing_fieldsorunknown. The order of the checks matters. A naive check sees "json" in "Unexpected end of JSON input" and calls it a parse error. It actually means the response was cut off, so we test for that before testing for parse errors. - A log line and an alert for every escalation, naming the failed tier, the next tier and the reason. After any model change, the escalation rate is one of the first numbers we look at.
-
Settings per tier. Later tiers are more expensive, so we send them a shorter slice of the conversation history to keep cost under control. Quirks such as "this model doesn't accept a temperature setting" live in each tier's configuration, not in
ifstatements around the code.
A failure the ladder couldn't catch
The no-op from earlier, where the model returns the old resume and claims it made changes, passes every validation check. The output is complete and well-formed. It's just not useful.
We handled that one separately. When a turn claims an update but the resume is identical to the previous one, we retry once. If it happens again, we reply honestly that no changes were needed. Generic validation catches generic failures. Some failures need a check written for that specific bug.
What you can take from this
- Treat an unusable answer exactly like an error. Send both down the same path.
- Validate with code wherever you can. Missing fields and empty content don't need a model to detect.
- Tell the next model why the last one failed. It's one extra message, and it stops the next model repeating the same mistake.
- Let one layer own retries. Otherwise they multiply in ways your logs won't explain.
- Name your failure reasons, and check the specific ones before the general ones.
- Make the last fallback a fixed, safe response that never touches the user's data.
How do you decide when a model's answer is bad enough to escalate? I'm especially curious how people validate free-text output, where there's no schema to check against.
Top comments (1)
The no-op is the one I would spend the most time on, because it is the only one of your four an independent check cannot see.
The other three have a tell in the response itself: empty field, missing field, prompt text. The no-op has none. A model that returns the previous resume and says it updated it is byte-identical to a model that correctly decided nothing needed changing. So the check cannot read the answer. It has to be pinned to something only a real run could produce — a diff against the stored version, set against the turn's own claim. Then has_updates true with a zero diff is a hard failure, has_updates false with a non-zero diff is a different hard failure, and you never have to form a view about quality.
Two things from the payments side.
Where the commit point sits relative to the validation. In payments the response is never the authority; you read the resource afterwards, because a 200 can precede a failed settlement. The equivalent here is that the model's output does not reach the user's resume until it has passed the gate. If validation runs after persistence, your empty-update case is a data loss you then retry over, which is worse than the failure you started with. Stage, validate, commit.
And the metric the ladder changes. Cost per call makes tier 1 look cheapest. What you want is cost per accepted turn, charged with the tiers a rejected turn burned on the way down. A tier rejected 40 percent of the time is paying for itself plus a slice of everything below it, and that is the number that says whether it belongs on the ladder at all. Your labelled causes already give you the breakdown to compute it.