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 35 of 120
When Output Goes Wrong Validation.
⏱ 2 min read ▶ Video at 37:49 🎓 Free
▶ starts at 37:49 Even with structured output, things can go wrong. The model might produce a value outside your limits, or the provider might return something malformed. Your app should handle that calmly.
From the video: When Output Goes Wrong Things still go wrong Values out of range Handle it calmly Here we simulate a bad reply, a J SON string with six stars, outside the allowed range. Pydantic's model validate J SON checks it, and raises a validation error. Run it. The error says exactly which field failed and why, so we can retry, or fall back to a default.
validate.py python Copy
from pydantic import BaseModel, Field, ValidationError
class ReviewTag ( BaseModel ):
stars: int = Field( ge = 1 , le = 5 )
mentions_delivery: bool
bad_reply = '{"stars": 6, "mentions_delivery": false}'
try :
ReviewTag.model_validate_json(bad_reply)
except ValidationError as e:
err = e.errors()[ 0 ]
print ( "field:" , err[ "loc" ][ 0 ], "| problem:" , err[ "msg" ]) Output
field: stars | problem: Input should be less than or equal to 5 With structured output has a helpful option, include raw. Instead of just the object, it returns a dictionary, with the raw message, the parsed object, and any parsing error. Run it. Parsed holds our object, and parsing error is none, because this reply was fine. When it isn't, you still have the raw reply to inspect.
include_raw.py python Copy
from pydantic import BaseModel, Field
from langchain.chat_models import init_chat_model
class ReviewTag ( BaseModel ):
stars: int = Field( ge = 1 , le = 5 )
mentions_delivery: bool
model = init_chat_model( "google_genai:gemini-flash-lite-latest" , temperature = 0 )
tagger = model.with_structured_output(ReviewTag, include_raw = True )
result = tagger.invoke( "Great book, quick delivery!" )
print ( sorted (result.keys()))
print ( "parsed:" , result[ "parsed" ])
print ( "error:" , result[ "parsing_error" ]) Output
['parsed', 'parsing_error', 'raw']
parsed: stars=5 mentions_delivery=True
error: None Prefer to watch? The full LangChain course is free All lessons in one video with animations, real code and chapters.
Watch free Validation errors tell you exactly what's wrong. Include raw keeps the original reply, so you can retry, fall back, or debug. Next, a quiz on structured output.
Key takeaways ValidationError include_raw=True Retry or fall back