TL;DR: LangChain is the most popular Python framework for building apps with AI models. It gives you pre-built components — for loading documents, storing conversation history, connecting to databases, and running AI agents — so you're not wiring those things together from scratch every time. Most chatbots, document Q&A tools, and AI agents you encounter were built with it or something inspired by it.
The Problem LangChain Solves
Imagine you're building a tool that lets your crew ask questions about a 200-page project manual. The AI needs to read the document, find the relevant section, and answer based on what's actually in there — not what it was trained on two years ago.
If you try to build that from scratch, you quickly run into a stack of problems. How do you load the PDF? How do you split it into pieces small enough for the AI to process? Where do you store those pieces so the AI can search them quickly? How do you pass the right pieces to the model along with the question? How do you keep the conversation memory so the AI knows what was asked five messages ago?
Every one of those is a solved problem — but you'd have to write the solution yourself, or find a dozen different libraries and glue them together. That's what LangChain replaces. It ships with components for all of it: document loaders, text splitters, vector database connectors, memory systems, and agent tools. You pull in the pieces you need, plug them together, and build the thing.
This is why it became the most-starred AI framework on GitHub within a year of its launch. It didn't invent new AI technology — it just made the existing technology dramatically faster to connect.
Where LangChain Came From
Harrison Chase released LangChain in October 2022, a few weeks before ChatGPT went public and changed everything. The timing was accidental — Chase built it because he was personally frustrated with how much boilerplate he had to write every time he started a new LLM project.
When ChatGPT launched in November 2022 and the world suddenly got interested in building with AI, LangChain was already there. It grew from a GitHub side project to the go-to framework almost overnight. By mid-2023, it was pulling millions of downloads a month and had raised venture capital to build LangSmith, a paid observability layer on top.
The framework has gone through significant changes since those early days. The original "Chain" and "Agent" classes have been largely replaced by LCEL (LangChain Expression Language), a cleaner way to compose components using a pipe operator. If you look at an older LangChain tutorial from 2023 and compare it to the 2026 docs, they look quite different — which trips up a lot of people who find outdated examples on Stack Overflow.
Today LangChain is the backbone of a large chunk of the LLM ecosystem: LangSmith for debugging and evaluation, LangGraph for complex agents, and a community that has built hundreds of third-party integrations with tools like Pinecone, Weaviate, Chroma, and practically every major model provider.
The Four Core Concepts
LangChain has a lot of surface area, but everything you'll actually use day-to-day is built on four ideas. Understand these and the rest clicks into place.
1. Chains — Connecting Steps Together
A Chain is a sequence of steps where the output of one step feeds into the next. The most basic chain is: format a prompt, send it to the model, get the response back. But chains can include database lookups, API calls, document retrieval — any step that produces data the next step needs.
Modern LangChain uses LCEL to write chains. The pipe operator (|) connects components, and data flows left to right — exactly like a Unix pipe in the terminal.
from langchain_anthropic import ChatAnthropic
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
# Three components chained together with |
model = ChatAnthropic(model="claude-sonnet-4-6")
prompt = ChatPromptTemplate.from_template(
"Explain {topic} in two sentences, like you're talking to someone on a job site."
)
parser = StrOutputParser()
# Chain: prompt → model → parse the output as a string
chain = prompt | model | parser
# Run it
result = chain.invoke({"topic": "API rate limits"})
print(result)
# → "An API rate limit is like a daily permit — you can only make so many
# requests in a given time window before the system tells you to slow down.
# Hit the limit and your calls start bouncing until the window resets."
That three-line chain handles the prompt formatting, the model call, and the output parsing. Without LangChain, each of those would be manual code. With more complex chains, the savings multiply fast.
2. Retrievers — Connecting the AI to Your Data
A Retriever is the piece that fetches relevant information from an external source — a database, a PDF, a website, a codebase — and hands it to the LLM. This is the heart of every "chat with your documents" app.
The standard pattern is called RAG: Retrieval-Augmented Generation. The idea: instead of stuffing your entire document into the model's context window, you store it in a searchable database, then retrieve only the relevant sections when a question comes in.
from langchain_community.document_loaders import PyPDFLoader
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings
# Step 1: Load the document
loader = PyPDFLoader("project-manual.pdf")
docs = loader.load()
# Step 2: Split it into searchable chunks
splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
chunks = splitter.split_documents(docs)
# Step 3: Store the chunks in a vector database with embeddings
vectorstore = Chroma.from_documents(chunks, OpenAIEmbeddings())
# Step 4: Create a retriever that finds relevant chunks by question
retriever = vectorstore.as_retriever(search_kwargs={"k": 4})
# Now: ask a question, retriever finds the relevant pages
results = retriever.invoke("What is the load limit for the main beam?")
# → returns the 4 most relevant chunks from your PDF
That's four lines of real work (load, split, store, retrieve) and LangChain handles the mechanics of each. The PDF reading, the chunking strategy, the vector similarity search — all built-in.
3. Memory — Giving the AI a Short-Term Brain
By default, every call to an LLM is stateless. Send a message, get a reply — and the model has already forgotten you exist. That's fine for one-off queries, but it breaks any app where the user expects a conversation.
LangChain's memory components store the conversation history and append it to each new message so the model can reference what was said before. There are different strategies for this depending on how long your conversations get:
LangChain Memory Options
ConversationBufferMemory
→ Keeps the full conversation history verbatim
→ Simple. Gets expensive as conversations get long.
ConversationSummaryMemory
→ Summarizes older messages instead of keeping them all
→ Uses extra LLM calls to summarize, but saves context space
ConversationBufferWindowMemory
→ Only keeps the last N messages (you pick N)
→ Cheap and fast. Forgets older context entirely.
ConversationSummaryBufferMemory
→ Keeps recent messages in full + summarizes older ones
→ Best balance for long conversations
Which memory type you use depends on how long your conversations run and how much context the AI needs to do its job well. A customer support bot where each session is short does fine with a simple buffer. A long-running research assistant probably needs summary memory.
4. Agents — Letting the AI Decide What to Do
An Agent is an LLM that can pick and use tools on its own. Instead of following a fixed chain (do step 1, then step 2, then step 3), an agent looks at the question, decides which tool to reach for, looks at the result, and decides what to do next.
Think of the difference between a worker following a checklist versus a worker who figures out the right steps themselves. Both can get the job done — but the agent handles situations the checklist doesn't cover.
from langchain_anthropic import ChatAnthropic
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
from langchain_community.tools.tavily_search import TavilySearchResults
# Give the agent a tool it can use: web search
tools = [TavilySearchResults(max_results=3)]
model = ChatAnthropic(model="claude-sonnet-4-6")
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful assistant. Use tools when you need current information."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"), # where the agent writes its reasoning
])
# Create the agent
agent = create_tool_calling_agent(model, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# Run it — the agent decides whether to search or answer directly
result = agent_executor.invoke({
"input": "What's the current price of lumber per board foot, and how does it compare to six months ago?"
})
print(result["output"])
The agent will recognize that a question about current prices requires a live web search, call the search tool, read the results, and synthesize an answer — all without you specifying those steps. If the question were "what's the formula for calculating board feet," it would just answer directly without touching the search tool.
LangChain in Practice: A Full RAG App
The most common thing people build with LangChain is a document Q&A system. Here's what the full pipeline looks like when the pieces come together:
from langchain_anthropic import ChatAnthropic
from langchain_community.document_loaders import DirectoryLoader
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_core.output_parsers import StrOutputParser
# --- SETUP (run once) ---
# Load all PDFs from a folder
loader = DirectoryLoader("./project-docs/", glob="**/*.pdf")
docs = loader.load()
# Split into chunks
splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
chunks = splitter.split_documents(docs)
# Store in a local vector database (persists to disk)
vectorstore = Chroma.from_documents(
chunks,
OpenAIEmbeddings(),
persist_directory="./chroma_db"
)
retriever = vectorstore.as_retriever()
# --- THE Q&A CHAIN ---
model = ChatAnthropic(model="claude-sonnet-4-6")
prompt = ChatPromptTemplate.from_template("""
Answer the question based only on the following context.
If the answer isn't in the context, say "I don't see that in the documents."
Context:
{context}
Question: {question}
""")
def format_docs(docs):
return "\n\n".join(doc.page_content for doc in docs)
# Chain: retrieve relevant docs → format → prompt → model → parse
rag_chain = (
{"context": retriever | format_docs, "question": RunnablePassthrough()}
| prompt
| model
| StrOutputParser()
)
# --- USE IT ---
answer = rag_chain.invoke("What is the maximum span for a 2x10 floor joist at 16 inches on center?")
print(answer)
That's a complete, working document Q&A system. It reads any PDFs in your project-docs folder, chunks them, stores them in a searchable database, and answers questions based on what's actually in the files. About 40 lines of code for something that would take days to build from scratch.
LangChain vs DSPy vs Building From Scratch
These three approaches all let you build LLM-powered apps. Here's an honest breakdown of when each one makes sense.
| LangChain | DSPy | From Scratch | |
|---|---|---|---|
| Best for | Connecting LLMs to data, tools, APIs | Auto-optimizing multi-step prompts | Simple single-call apps |
| You write prompts? | Yes — by hand | No — DSPy writes them | Yes — by hand |
| Learning curve | Medium (1–3 days) | Steep (1–2 weeks) | Low (hours) |
| Document Q&A | Excellent — built for it | Possible, less tooling | Hard — build everything |
| AI agents | Very strong — LangGraph too | Growing support | Complex — write it all |
| Prompt drift resistance | Low — prompts are manual | High — prompts auto-optimize | None |
| Community size | Huge — most tutorials use it | Smaller but growing | N/A |
| Model flexibility | All major providers | All major providers | Whatever you code |
| Use together? | Yes — LangChain for retrieval | Yes — DSPy for the prompts | Yes — as the simple base |
The short version: start with LangChain when you need to connect an LLM to real data. Add DSPy later if your multi-step prompts keep drifting or breaking. Build from scratch only when your use case is genuinely too simple to need a framework — which is less common than you'd think.
What AI Gets Wrong About LangChain
If you ask a chatbot "how do I use LangChain to build a RAG app?" and it generates code, there's a reasonable chance that code will be outdated or wrong. This happens more with LangChain than almost any other framework in the Python ecosystem. Here's why, and what to watch for.
The API Changed. A Lot.
LangChain has rewritten its core API multiple times. The original way to build chains used classes like LLMChain and SequentialChain. Those still exist for backwards compatibility but are considered legacy. The new way is LCEL with the pipe operator. An AI trained on 2023 data will give you the old syntax. Code that was correct eighteen months ago is now deprecated.
When an AI generates LangChain code for you, always check: does it use | to compose components? Does it use from langchain_core and from langchain_community? If it's importing from just langchain and using LLMChain(llm=..., prompt=...), you're looking at the old approach.
The Import Paths Split Into Multiple Packages
In early LangChain everything lived in one package: langchain. That package was eventually split into several:
LangChain Package Structure (2025+)
langchain-core → Base interfaces, LCEL, core abstractions
langchain → Pre-built chains, agents, high-level abstractions
langchain-community → Third-party integrations (Chroma, Pinecone, etc.)
langchain-openai → OpenAI-specific classes (ChatOpenAI, etc.)
langchain-anthropic → Anthropic-specific classes (ChatAnthropic, etc.)
langchain-google → Google-specific classes
langgraph → Agent workflow graphs (separate package)
AI tools that haven't kept up will generate code with from langchain.chat_models import ChatOpenAI when the correct import is from langchain_openai import ChatOpenAI. These look similar but one will raise a deprecation warning (or fail entirely in newer versions).
The "This Is Too Complicated" Trap
AI-generated LangChain code often uses more framework than necessary. A simple question-answering task gets turned into a full agent with multiple tools and custom memory — because the model learned from examples that used those features. Most real-world use cases are simpler than the demos.
If your use case is genuinely "read a document, answer a question," the RAG chain approach above is about 40 lines. If an AI generates 200 lines with callback handlers, custom memory classes, and a LangGraph state machine, it's almost certainly over-engineered for what you need.
It Conflates LangChain and LangSmith
LangSmith is a paid tracing and evaluation platform from LangChain's company. It's useful for debugging production apps but completely optional. Some AI-generated code includes LangSmith setup as if it's required. You don't need a LangSmith API key to use LangChain. If you see LANGCHAIN_TRACING_V2=true in environment variable setup, that's LangSmith — skip it unless you specifically want the observability features.
What People Actually Build With LangChain
LangChain's community has settled on a handful of patterns that show up over and over. These are worth knowing because they're what most job postings mean when they say "experience with LangChain."
Document Q&A (RAG)
The pattern described above — load documents, chunk them, store them in a vector database, retrieve relevant chunks when a question comes in, pass them to the LLM. This is LangChain's primary use case and the one with the best tooling. Works for PDFs, Word docs, web pages, Notion pages, Confluence docs, code files — there are document loaders for all of them.
Conversational Chatbots With Memory
Chatbots where the AI needs to remember what was said earlier in the conversation. LangChain's memory system stores the history and formats it correctly for each model's expected input structure. LangGraph has largely taken over for more complex conversational agents that need to branch or loop.
AI Agents With Tool Calling
Agents that can use web search, run Python code, query databases, call APIs, or interact with external services. The agent decides which tools to use based on the task. LangChain has integrations with Tavily (web search), Wolfram Alpha (math), SQL databases, and dozens of other tools. MCP servers are an increasingly popular way to extend agents with custom tools without writing integration code by hand.
Data Extraction and Structuring
Running large batches of unstructured text — emails, contracts, meeting transcripts, support tickets — through an LLM to pull out structured data. LangChain's output parsers handle converting model responses into Python objects, dictionaries, or JSON schemas reliably.
Multi-Modal Pipelines
Pipelines that mix text and images — routing customer photos to the right department, generating product descriptions from images, analyzing screenshots. LangChain's model integrations handle the multi-modal inputs; you build the pipeline around them the same way you would for text.
The Honest Trade-offs
LangChain is popular enough that it's sometimes used when it shouldn't be. It's worth being clear about where the friction comes from.
The Abstraction Can Hide What's Actually Happening
LangChain wraps a lot of operations. When something breaks, the error messages are sometimes cryptic because the failure happens three layers down inside a LangChain abstraction. Debugging a broken retrieval chain requires understanding what LangChain is doing behind the scenes — which defeats part of the point of using the framework in the first place.
The practical fix: use LangSmith tracing locally during development (it's free for small volumes) or add verbose logging. Seeing exactly what prompts get sent to the model, what the retriever returns, and what each step produces makes debugging dramatically faster.
Keeping Up With API Changes Takes Time
LangChain's API has evolved rapidly and will likely keep evolving. If you build something today and come back to it in six months, there's a real chance some imports have moved or a class has been renamed. This is normal for a fast-moving open-source project, but it means LangChain apps need more maintenance than, say, a script that directly calls the Anthropic SDK.
It Can Be Overkill for Simple Apps
If your app sends a message to the model and shows the response, you don't need LangChain. The Anthropic SDK or OpenAI SDK is two lines of code. LangChain adds a dependency tree, an abstraction layer, and a learning curve for no real gain when the use case is that simple.
The signal that you actually need LangChain: you're connecting the LLM to something (a database, a file, an API, a conversation history) and that connection requires more than ten lines of code to handle correctly. If you're writing custom document loading and chunking, custom retrieval logic, or custom tool-calling plumbing — LangChain is almost certainly worth it.
The Ecosystem Has Real Competition Now
LlamaIndex (now called LlamaIndex Cloud) covers much of the same ground as LangChain for RAG use cases, with arguably better tooling for structured document ingestion. Some teams prefer writing raw SDK calls with a thin custom layer on top. LangChain is the most popular choice but it's not the only reasonable one.
Should You Use LangChain?
A simple gut-check for vibe coders deciding whether to reach for LangChain:
Use LangChain if:
✓ You're building a chatbot that reads documents or uses tools
✓ You want a retrieval-augmented generation (RAG) app
✓ Your app needs to remember conversation history across messages
✓ You want an AI agent that can search the web, run code, or call APIs
✓ You're comfortable with Python and want the fastest path to something working
✓ You want access to a huge library of pre-built integrations
Skip LangChain if:
✗ You're building a simple chatbot with no external data
✗ You just need to call the model API once and show the result
✗ You're not yet comfortable with Python
✗ You need your app to be extremely lightweight with minimal dependencies
✗ Your pipeline is so custom that no pre-built LangChain component fits
The honest default recommendation: if you're building anything more complex than a basic chatbot, try LangChain first. Its community, documentation, and integrations ecosystem mean you're unlikely to hit a wall that someone hasn't already solved. Learn the LCEL syntax (not the legacy chain classes), check that any AI-generated code uses current imports, and you'll be productive within a day.
A good prompting foundation still matters — LangChain handles the plumbing, but you still write the system prompts that tell the model what to do. The framework doesn't make bad prompts good; it makes good prompts easier to connect to the world.
Frequently Asked Questions
What is LangChain?
LangChain is an open-source Python (and JavaScript) framework for building applications with large language models. It provides pre-built components for loading documents, searching databases, calling tools, storing conversation history, and running AI agents — the connective tissue that most AI apps need but would take days to build from scratch.
What is LangChain used for?
Primarily three things: document Q&A systems (load PDFs, answer questions about them), conversational chatbots with memory (the AI remembers earlier messages), and AI agents (the AI picks and uses tools to complete tasks). Most AI tutorials that show "build a chatbot" or "chat with your docs" are using LangChain under the hood.
Do I need to know Python to use LangChain?
For the Python version, yes. LangChain is a Python library and you'll be writing Python code. If you're coming from web development, LangChain.js is the JavaScript equivalent and works with Node.js. If you're new to Python, spend a few hours on the basics first — Python functions, classes, and pip installs — then LangChain's examples will make sense immediately.
Is LangChain free?
The framework is completely free and open-source. You install it with pip and it costs nothing. The costs come from the AI models you connect to it — Claude, GPT-4, Gemini all charge per token. LangSmith, a paid tracing and evaluation service from the same company, is optional and not required to use LangChain itself.
What is the difference between LangChain and LangGraph?
LangChain is the core framework with components for chains, retrieval, memory, and basic agents. LangGraph is a separate library from the same team for building complex agents with conditional branching, loops, and error recovery — think of it as a state machine for your agent. Most simple projects only need LangChain. When your agent needs to retry steps, check conditions, or run parallel branches, that's when LangGraph adds value.
What is the difference between LangChain and DSPy?
LangChain is a toolkit for connecting LLMs to external data and tools — you write the prompt text yourself. DSPy is an optimizer: you describe the logic of each pipeline step and DSPy finds the best prompt wording using example data. LangChain handles the wiring; DSPy handles making the prompts as good as possible. Many production teams use both together.
Is LangChain still worth learning in 2026?
Yes. It's still the most widely used LLM framework with the biggest community, the most tutorials, and the most third-party integrations. Job postings that mention "LLM experience" often specifically list LangChain. The API changed significantly in 2023–2024 (learn LCEL, not the legacy chain classes), but the fundamentals — chains, retrievers, memory, agents — haven't gone anywhere.
What is LCEL in LangChain?
LCEL stands for LangChain Expression Language. It's the modern way to compose LangChain components using a pipe operator (|), where data flows left to right from one component to the next. A simple chain looks like prompt | model | output_parser. Most tutorials written after mid-2023 use LCEL. If you see older code using LLMChain or SequentialChain, that's the legacy API — functional but not recommended for new code.
What to Learn Next
LangChain connects LLMs to the world. These articles cover the surrounding concepts that make your LangChain apps better.