
Agent Error Handling: How Agents Recover From Tool and LLM Failures
Agent error handling turns brittle LLM loops into resilient systems. Learn how guardrails, retries, and checkpoints catch tool failures and malformed outputs.
An AI agent is a program that uses a language model to plan steps, call external tools, and decide what to do next. The moment it leaves a clean chat window, it meets the real world: an API times out, a database returns null, the model invents a function name that does not exist. Without a recovery layer, the agent stops on the first hiccup, leaving the user with a half-finished task and no explanation of what went wrong.
Error handling and recovery is the safety net that keeps the loop alive. It does three things: detect that something failed, decide what kind of failure it is, and pick a response that fits — retry, fall back to a different tool, repair the input, or hand control to a person.
Most production agents distinguish between transient errors (a network blip, a rate limit) and structural errors (a tool that does not exist, a permission denied). Transient errors get an automatic retry, often with a delay that grows on each attempt. Structural errors need a different path entirely, because retrying will only burn tokens. Good systems also watch for “soft” failures — outputs that look fine but are wrong, like an empty list returned when the user asked for a customer record.
The recovery side is where designs differ most. Some agents loop back to the planner with the error message and let the model rewrite its approach. Others use predefined fallback chains: try the primary API, then a cached version, then ask the user. Mature setups combine both, with limits on how many retries are allowed before the agent gives up loudly instead of silently spinning.
The most common place this shows up today is inside AI coding assistants and customer-facing chat agents. A coding agent runs a shell command, the test suite fails with a stack trace, and the recovery logic catches the non-zero exit code, feeds the error back to the model, and asks it to fix the offending file before trying again. A support agent calls the order-lookup tool, gets a 503 response, waits two seconds, retries, and on a second failure tells the customer it will follow up by email rather than inventing an answer.
Teams building these agents usually start simple: a try/catch around every tool call, an error message returned to the model, and a hard cap on retries. Over time they add timeouts, per-tool fallback paths, and a log line for every failure so they can debug patterns later. The goal is not zero errors. The goal is that every error has a path that does not end in a fabricated reply.
Treat every tool call as a function that can throw, even ones you control. Wrap them, log the error verbatim, and feed a short structured message back to the model — not the raw stack trace. The model handles “DatabaseError: connection refused” better than 40 lines of Python traceback, and your token bill will thank you.
Start with how resilient agents recover from tool and LLM failures — it maps the detection, retry, and recovery patterns that keep one bad step from poisoning the rest of the run. Read the failure-mode and idempotency prerequisites right after: it is where the real constraints live — retries duplicate side effects unless you design against it, and a crash erases progress unless something outside the agent remembers.
When you are ready to build, the retry, fallback, and self-correction loops guide turns the theory into a spec: retry budgets, checkpointers, and validators. For where the tooling is heading, the 2026 durable-execution framework roundup tracks how LangGraph, Temporal, and Pydantic AI converged on state persistence as the real fix. Close with the ethics of graceful degradation — recovery that nobody can see is not resilience, it is a different kind of failure.

Three neighbouring concerns get folded into “error handling” when they are really separate jobs.
| Scenario | Use | Avoid |
|---|---|---|
| Long-running agent that touches multiple external APIs | ✅ | |
| Single-turn chatbot with no tool calls | ❌ | |
| Customer-facing agent where wrong answers are worse than no answer | ✅ | |
| Throwaway prototype on your laptop for a one-off task | ❌ | |
| Coding agent that runs tests, builds, or shell commands | ✅ | |
| Internal demo where you watch every step manually | ❌ |
Q: Is self-correction the same thing as a retry? A: Not quite — a self-correction loop is a retry that hands the model a specific error message instead of repeating the same call, so it can fix what actually went wrong rather than hoping for a different roll. The retry, fallback, and self-correction guide treats the two as one contract: retry first, self-correct when the failure is about output shape.
Q: Why does my agent duplicate a side effect after a retry succeeds? A: Because the retry re-ran the whole step, including the part that already worked — an email already sent, a charge already placed. The idempotency and durable execution prerequisites explain why a retry needs an idempotency key before it needs a backoff schedule.
Q: Does adopting a durable execution framework replace my retry logic? A: It replaces where the retry logic lives, not the need for it — engines like Temporal and LangGraph persist state between steps so a crash resumes instead of restarting, but you still define what counts as a retryable failure. How 2026 frameworks are solving agent resilience covers the composition patterns.
Q: Is graceful degradation always the safer choice over a hard failure? A: Only when it is paired with a visible record of what was skipped — an agent that quietly substitutes a fallback and logs nothing has just moved the failure somewhere nobody is looking. The ethics of graceful degradation works through where recovery quietly becomes concealment.
Part of agent reliability and operations · closest neighbour: agent cost optimization. New to this from a software background? Start with the story: Agent Reliability for Engineers: What SRE Habits Map and Break.
Most agent demos work on the happy path. What separates a resilient agent from a fragile one is how it behaves the moment a tool returns an error or the model hallucinates a malformed plan.
Concepts covered

Agent error handling turns brittle LLM loops into resilient systems. Learn how guardrails, retries, and checkpoints catch tool failures and malformed outputs.

Reliable AI agents need three foundations: a failure-mode taxonomy, idempotent action boundaries, and durable execution that survives mid-workflow crashes.
These guides walk through the practical machinery — retry policies with exponential backoff, fallback model routing, self-correction loops, and durable execution — so your agent survives the real world instead of just your demo.
Tools & techniques

A specification-first guide to retry with backoff, durable execution via LangGraph and Temporal, and Pydantic AI self-correction in production AI agents.
Resilience is moving from ad-hoc try/except blocks into first-class framework primitives. Watch how durable workflow engines and structured-output libraries are changing how production agents are built.
Models & benchmarks
Updated May 2026

Three frameworks converged on durable execution in 2026. LangGraph, Temporal, and Pydantic AI are redrawing how production agents survive crashes and retries.
An agent that silently recovers can also silently deceive. The harder question is when graceful degradation crosses into hiding failures from the people who depend on the output.
Risks & metrics

Graceful degradation lets AI agents fail without crashing. That sounds humane. It also lets failure hide. A look at the ethics of silent agent errors.