LangChain Tutorial 120 lessons · 2:16:24+ of video
LangChain Home Getting Started
What Is LangChain How LLM Apps Work Setting Up Models and Messages
Your First Model Call Messages Conversations Settings, Streaming, Batches
Model Settings Streaming Batch Calls Tokens and Providers
Tokens and Usage Switching Providers Basics Quiz Prompt Templates
Prompt Templates Chat Prompt Templates MessagesPlaceholder Examples, Chains, Parsers
Few-Shot Prompts Chains with the Pipe Output Parsers Runnables
Runnables RunnableLambda RunnableParallel Passthrough, Routing, Fallbacks
RunnablePassthrough Routing Fallbacks and Retries Inside Chains and Practice
Seeing Inside a Chain Practice: Review Summariser Chains Quiz Structured Output
Why Structured Output Pydantic Models with_structured_output Shapes, Labels, Extraction
Lists and Nested Data Classification Extraction Structured Output in Practice
Batch Extraction When Output Goes Wrong Structured Output Quiz Tools
What Are Tools The tool Decorator Tool Schemas Tool Calls by Hand
Binding Tools Reading Tool Calls Running Tools Yourself Agents
The Agent Loop create_agent Several Tools Prompts, Streaming, Memory
Agent System Prompts Streaming Agent Steps Agent Memory Structured Answers and Middleware
Structured Agent Answers Middleware Built-in Middleware Context and Errors
Dynamic Prompts Tool Errors Runtime Context Agent Practice and Approval
Practice: Bookshop Agent Human Approval Agents Quiz RAG Foundations
What Is RAG Documents Loading Files Chunks and Embeddings
Splitting Text Chunk Size and Overlap Embeddings Similarity and Vector Stores
Similarity Vector Stores Search with Scores Retrievers
Retrievers Metadata Filters MMR Search Your First RAG Chain
Your First RAG Chain The RAG Prompt Saying I Don't Know Better RAG
Citing Sources Conversational RAG RAG as a Tool RAG in Practice
Saving a Vector Store Checking RAG Quality RAG Pitfalls FAQ Bot and Async
Practice: Bookshop FAQ Bot RAG Quiz Async Calls Cache, Limits and Timeouts
Caching Model Calls Rate Limiting Timeouts Cost, Logging and Tracing
Tracking Cost Callbacks for Logging Tracing with LangSmith Evaluation
Evaluating Answers Test Sets Comparing Prompts Safety
Prompt Injection Guardrails PII Redaction Reliability
Model Fallbacks Limiting Agent Calls Production Quiz Serving and the Project Plan
Serving with FastAPI Streaming over HTTP Project: Support Bot Plan Project: Building the Bot
Project: Knowledge Base Project: Tools Project: The Agent Project: Memory, Guardrails, Tests
Project: Memory Project: Guardrails Project: Testing Project Review and Good Habits
Project: Review Choosing Models Prompt Habits Images and Long Documents
Multimodal Input Long Documents Map-Reduce Summaries Rewriting and Extraction
Translation and Rewriting Data from Tables Applied Quiz The Bigger Picture
LangChain vs LangGraph The Ecosystem Cheat Sheet: Core Wrapping Up
Cheat Sheet: Agents and RAG Common Mistakes What to Learn Next LangChain · Lesson 94 of 120
Model Fallbacks A backup model.
⏱ 2 min read ▶ Video at 1:46:50 🎓 Free
▶ starts at 1:46:50 Even the best model providers have outages. If your only model is down, so is your app. A fallback is a backup model, tried automatically when the main one fails.
From the video: Model Fallbacks Providers have outages One model, one point of failure A backup model Our primary model has a name that doesn't exist, to pretend it's down. With fallbacks wraps it with a list of backups. When the primary fails, the next one is tried. Run it. The primary fails, the backup answers, and the response metadata shows which model actually replied.
fallbacks.py python Copy
from langchain.chat_models import init_chat_model
primary = init_chat_model( "google_genai:gemini-retired-model" ) # pretend it's down
backup = init_chat_model( "google_genai:gemini-flash-lite-latest" )
model = primary.with_fallbacks([backup])
reply = model.invoke( "Say OK." )
print (reply.text.strip())
print ( "answered by:" , reply.response_metadata[ "model_name" ]) Output
OK.
answered by: gemini-3.5-flash-lite The best backup is often a different provider, so one outage can't take down both. Make sure your prompt works well on the backup too. Fallbacks work on any runnable, so you can give a whole chain a backup chain. For agents, there's model fallback middleware.
key value Different provider survives outages Test the prompt on the backup too Any runnable chains too Agents ModelFallbackMiddleware
Prefer to watch? The full LangChain course is free All lessons in one video with animations, real code and chapters.
Watch free With fallbacks tries backup models when the main one fails, so your app keeps running. Next, stopping agents that run away.
Key takeaways .with_fallbacks([backup]) Different provider Test both