LangChain — LLM Application Framework
Framework for building applications powered by large language models. Composable components for prompts, chains, agents, RAG, and memory — unified via the Runnable interface and LCEL (LangChain Expression Language).
Installation
uv add langchain langchain-core langchain-community
uv add langchain-openai # OpenAI models
uv add langchain-anthropic # Anthropic Claude models
uv add langchain-chroma # ChromaDB vector store
uv add langchain-text-splitters # document chunking
uv add langgraph # graph-based agent orchestration
uv add langsmith # observability and tracing
uv add langgraph-checkpoint-sqlite # local graph persistence
uv add langgraph-checkpoint-postgres # production persistence
When to Use What
| Component | Best for |
|---|---|
ChatPromptTemplate |
Structuring LLM input with variables and roles |
LCEL chains (\|) |
Linear pipelines: prompt → model → parser |
StrOutputParser |
Extracting plain text from model responses |
| RAG retrieval chain | Grounding answers in custom documents |
| Agents + Tools | Dynamic multi-step reasoning, API calls |
ConversationBufferMemory |
Short conversation history |
LangGraph StateGraph |
Complex agents with loops, branching, human-in-the-loop |
Section Map
| File | Topics |
|---|---|
| 01 Models, Prompts & Parsers | Chat models, prompt templates, output parsers, streaming |
| 02 LCEL & Chains | Runnable interface, pipe operator, parallel, branching, fallbacks |
| 03 RAG & Retrieval | Document loaders, text splitters, embeddings, vector stores, retrievers |
| 04 Agents & Tools | Tool creation, agent types, ReAct, tool calling, structured output |
| 05 Memory & State | Conversation memory, summary memory, vector memory, message history |
| 06 LangGraph & Production | StateGraph, nodes/edges, checkpointing, LangSmith, deployment |
| 07 Security, Evaluation & Operations | Tool safety, prompt injection controls, evaluation datasets, caching, CI gates |
| 08 Practical Playbooks | Ready scenarios: Q&A bot, RAG docs bot, agent with 2 tools |
Quick Start
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful assistant."),
("human", "{question}"),
])
model = ChatOpenAI(model="gpt-4o-mini", temperature=0)
parser = StrOutputParser()
chain = prompt | model | parser
response = chain.invoke({"question": "What is LangChain?"})
print(response)
Core Ecosystem
| Package | Purpose |
|---|---|
langchain-core |
Base abstractions: Runnables, prompts, parsers, messages |
langchain |
Higher-level chains, agents, retrieval logic |
langchain-community |
Third-party integrations (vector stores, loaders) |
langchain-openai |
OpenAI chat models and embeddings |
langchain-anthropic |
Anthropic Claude models |
langgraph |
Graph-based agent orchestration with state |
langsmith |
Tracing, evaluation, monitoring |
Quick Rules
- Use LCEL — pipe operator
|replaces all legacy chain classes. - Every component is a Runnable —
.invoke(),.stream(),.batch()everywhere. - Separate prompt from model — compose via LCEL, not string formatting.
- Use structured output —
model.with_structured_output(Schema)for typed responses. - RAG over fine-tuning — ground answers in documents before training custom models.
- LangGraph for agents — use
StateGraphwhen you need loops, branching, or persistence. - Trace everything — enable LangSmith in production for debugging and cost tracking.
- Protect tools and prompts — apply allowlists, schema validation, and injection defenses.
- Run evals in CI — use LangSmith datasets and evaluator gates for regression control.
Start Here (Beginner Learning Path)
If you are new to LangChain, follow this exact order:
- Read
01-models-prompts-parsers.mdand run the first chain. - Read
02-lcel-chains.mdto learn composition (|, parallel, branch). - Read
03-rag-retrieval.mdand build a small local RAG on 10-50 docs. - Read
04-agents-tools.mdonly after chains and RAG are clear. - Read
05-memory-state.mdto add chat continuity. - Read
06-langgraph-production.mdwhen you need loops, approvals, persistence. - Read
07-security-evaluation-operations.mdbefore shipping to users.
What Is "Enough" to Start Real Work
You can start building useful internal assistants when you can:
- compose
prompt | model | parser; - retrieve top-k documents and cite sources;
- define 1-3 safe tools with
args_schema; - add retries, timeouts, and tracing;
- run at least one evaluation dataset before release.