Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Learn/LangChain Mastery/Part 8 · 7. Tools & Agents
Lesson 58 of 68

Fallbacks & Error Handling

When the agent breaks. Retries, corrections, and graceful exits.

Derpx0610 Jan · 1 min read
LangChain Mastery
Designing Tool SchemasFunction Calling in LangChainTool Selection & ValidationReAct AgentsPlan-and-Solve AgentsFallbacks & Error HandlingLangGraph: Stateful AgentsHuman-in-the-Loop
Contents
1. Agents Are Fragile2. Validation Errors (The Self-Correction)3. Tool Fallbacks (The Backup Plan)4. LLM Fallbacks (Model Degradation)5. Summary
0% read · 1 min leftBack to top ↑
Course outline & contents0%
LangChain Mastery
Designing Tool SchemasFunction Calling in LangChainTool Selection & ValidationReAct AgentsPlan-and-Solve AgentsFallbacks & Error HandlingLangGraph: Stateful AgentsHuman-in-the-Loop
Contents
1. Agents Are Fragile2. Validation Errors (The Self-Correction)3. Tool Fallbacks (The Backup Plan)4. LLM Fallbacks (Model Degradation)5. Summary

1. Agents Are Fragile

Chains are deterministic logic. Agents are probabilistic logic. Probabilities fail.

  • Tool Error: API is down.
  • Parse Error: Agent output malformed JSON.
  • Loop Error: Agent decides to search for "A" forever.

If you don't build Fallbacks, your agent is a prototype, not a product.

2. Validation Errors (The Self-Correction)

We discussed this in Tool Selection. If delete_user fails, feed the error back. This converts a Crash into an Observation.

Agent: "Action: Delete(User 5)" System: "Error: User 5 not found." Agent: "Thought: Ah, I made a mistake. I will search for the user first."

This is the cheapest form of resilience.

3. Tool Fallbacks (The Backup Plan)

If SearchGoogle API times out, the agent shouldn't die. It should automatically switch to SearchBing or SearchDuckDuckGo.

tool_fallback.py
primary_tool = SearchGoogle()
backup_tool = SearchBing()

final_tool = primary_tool.with_fallbacks([backup_tool])

# If primary raises Exception, backup runs instantly.
# The Agent doesn't even know it failed.

4. LLM Fallbacks (Model Degradation)

If GPT-4 is overloaded (Rate Limit Error), automatically fallback to GPT-3.5 or Claude. The answer might be dumber, but a dumb answer is better than a 500 Server Error.

5. Summary

Elegance is handling failure without the user noticing. Your agent should be like a cat: It always lands on its feet.

Key Intuition: "The plan A never survives contact with reality."

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonPlan-and-Solve AgentsNext lesson →LangGraph: Stateful Agents