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 49 of 120
Structured Agent Answers Response_format.
⏱ 2 min read ▶ Video at 54:06 🎓 Free
▶ starts at 54:06 Agents usually end with a friendly sentence. But if another program uses the answer, it needs data. The response format option makes an agent finish with a structured object, after using its tools.
From the video: Structured Agent Answers Agents end with text Programs need data response_format We describe the answer we want as a Pydantic model, a stock report with the title, the number of copies, and whether it's available. We pass it as response format. Run it. The agent uses the stock tool, then returns a stock report object, under the key structured response.
agent_format.py python Copy
from pydantic import BaseModel
from langchain.agents import create_agent
from shop_tools import check_stock
class StockReport ( BaseModel ):
title: str
copies: int
available: bool
agent = create_agent( "google_genai:gemini-flash-lite-latest" ,
tools = [check_stock], response_format = StockReport)
out = agent.invoke({ "messages" : [{ "role" : "user" , "content" : "Check Circe for me." }]})
report = out[ "structured_response" ]
print ( type (report). __name__ , report) Output
StockReport title='Circe' copies=0 available=False Also uses shop_tools.py from langchain.tools import tool
BOOKS = {
"The Hobbit" : { "stock" : 7 , "price" : 8.99 , "author" : "J.R.R. Tolkien" },
"Dune" : { "stock" : 3 , "price" : 9.99 , "author" : "Frank Herbert" },
"Circe" : { "stock" : 0 , "price" : 10.99 , "author" : "Madeline Miller" },
}
@tool
def check_stock (title: str ) -> int :
"""Copies of a book in stock at Riverside Books."""
return BOOKS .get(title, {}).get( "stock" , 0 )
@tool
def get_price (title: str ) -> float :
"""Price of a book in pounds."""
return BOOKS .get(title, {}).get( "price" , 0.0 )
@tool
def get_author (title: str ) -> str :
"""Author of a book."""
return BOOKS .get(title, {}).get( "author" , "unknown" ) Use response format when the agent's answer feeds another system, like a dashboard, a database, or another agent. The agent still reasons and uses tools freely, but its final answer has a guaranteed shape. You get the flexibility of an agent, and the reliability of structured output.
key value Feeds a system dashboards, databases Tools still used freely Final answer guaranteed shape Key structured_response
Prefer to watch? The full LangChain course is free All lessons in one video with animations, real code and chapters.
Watch free Response format makes an agent finish with a structured object, found under structured response. Next, middleware, the way to customise what happens inside an agent.
Key takeaways response_format=Model Tools, then data out['structured_response']