The framework for building context-aware reasoning applications. Learn Chains, Agents, and LCEL.
LangChain provides the building blocks to glue LLMs to other data sources.
(Click to reveal)
Sequences of calls.
Example:
Input -> Prompt -> LLM -> Output Parser.
This ensures modularity and reusability.
(Click to reveal)
A declarative way to chain components using the `|` pipe operator.chain = prompt | model | parser
(Click to reveal)
Interfaces that return documents given an unstructured query.
Crucial for RAG (Retrieval Augmented Generation) pipelines.
(Click to reveal)
Unlike chains (hardcoded sequences), Agents use an LLM to decide what actions to take and in what order.
In modern LangChain, we compose components using the pipe | operator. Click the nodes to see the code.
prompt = ChatPromptTemplate...
model = ChatOpenAI()
parser = StrOutputParser()
Click on the pipeline components to see the Python code behind them.
Templates convert user input into a formatted prompt for the model.
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([
("system", "You are a comedian."),
("user", "Tell me a joke about {topic}")
])
The core LLM. LangChain supports OpenAI, Anthropic, HuggingFace, and many others through a unified interface.
from langchain_openai import ChatOpenAI
model = ChatOpenAI(
model="gpt-4o",
temperature=0.7
)
Parsers transform the raw `AIMessage` output from the model into a string, JSON, or other structured data.
from langchain_core.output_parsers import StrOutputParser
parser = StrOutputParser()
# The full chain syntax:
chain = prompt | model | parser
LangChain standardizes inputs and outputs across different model providers.
Manage variables and formatting. Supports `SystemMessage`, `HumanMessage`, and `AIMessage` roles.
From `StrOutputParser` (text only) to `JsonOutputParser` (enforce structured data) and `PydanticOutputParser` (validate data types).
Test your LangChain proficiency.
1. What operator does LCEL use to compose components?
2. Which component is responsible for enforcing structured JSON output?
3. What is the difference between a Chain and an Agent?