How-to guides
Here you'll find answers to βHow do Iβ¦.?β types of questions. These guides are goal-oriented and concrete; they're meant to help you complete a specific task. For conceptual explanations see Conceptual Guides. For end-to-end walkthroughs see Tutorials. For comprehensive descriptions of every class and function see API Reference.
Installationβ
Key featuresβ
This highlights functionality that is core to using LangChain.
- How to: return structured data from an LLM
- How to: use a chat model to call tools
- How to: stream runnables
- How to: debug your LLM apps
LangChain Expression Language (LCEL)β
LangChain Expression Language is a way to create arbitrary custom chains. It is built on the Runnable
protocol.
LCEL cheatsheet: For a quick overview of how to use the main LCEL primitives.
- How to: chain runnables
- How to: stream runnables
- How to: invoke runnables in parallel
- How to: attach runtime arguments to a runnable
- How to: run custom functions
- How to: pass through arguments from one step to the next
- How to: add values to a chain's state
- How to: add message history
- How to: route execution within a chain
- How to: add fallbacks
Componentsβ
These are the core building blocks you can use when building applications.
Prompt templatesβ
Prompt Templates are responsible for formatting user input into a format that can be passed to a language model.
- How to: use few shot examples
- How to: use few shot examples in chat models
- How to: partially format prompt templates
- How to: compose prompts together
Example selectorsβ
Example Selectors are responsible for selecting the correct few shot examples to pass to the prompt.
- How to: use example selectors
- How to: select examples by length
- How to: select examples by semantic similarity
Chat modelsβ
Chat Models are newer forms of language models that take messages in and output a message.
- How to: do function/tool calling
- How to: get models to return structured output
- How to: cache model responses
- How to: create a custom chat model class
- How to: get log probabilities
- How to: stream a response back
- How to: track token usage
LLMsβ
What LangChain calls LLMs are older forms of language models that take a string in and output a string.
- How to: cache model responses
- How to: create a custom LLM class
- How to: stream a response back
- How to: track token usage
Output parsersβ
Output Parsers are responsible for taking the output of an LLM and parsing into more structured format.
- How to: use output parsers to parse an LLM response into structured format
- How to: parse JSON output
- How to: parse XML output
- How to: try to fix errors in output parsing
Document loadersβ
Document Loaders are responsible for loading documents from a variety of sources.
- How to: load CSV data
- How to: load data from a directory
- How to: load PDF files
- How to: write a custom document loader
- How to: load HTML data
- How to: load Markdown data
Text splittersβ
Text Splitters take a document and split into chunks that can be used for retrieval.
Embedding modelsβ
Embedding Models take a piece of text and create a numerical representation of it.
Vector storesβ
Vector stores are databases that can efficiently store and retrieve embeddings.
Retrieversβ
Retrievers are responsible for taking a query and returning relevant documents.
- How to: use a vector store to retrieve data
- How to: generate multiple queries to retrieve data for
- How to: use contextual compression to compress the data retrieved
- How to: write a custom retriever class
- How to: combine the results from multiple retrievers
- How to: generate multiple embeddings per document
- How to: retrieve the whole document for a chunk
- How to: generate metadata filters
- How to: create a time-weighted retriever
- How to: reduce retrieval latency
Indexingβ
Indexing is the process of keeping your vectorstore in-sync with the underlying data source.
Toolsβ
LangChain Tools contain a description of the tool (to pass to the language model) as well as the implementation of the function to call.
- How to: create custom tools
- How to: use built-in tools and built-in toolkits
- How to: use a chat model to call tools
- How to: add ad-hoc tool calling capability to LLMs and Chat Models
Agentsβ
For in depth how-to guides for agents, please check out LangGraph documentation.
- How to: use legacy LangChain Agents (AgentExecutor)
- How to: migrate from legacy LangChain agents to LangGraph
Callbacksβ
Callbacks allow you to hook into the various stages of your LLM application's execution.
- How to: pass in callbacks at runtime
- How to: attach callbacks to a module
- How to: pass callbacks into a module constructor
- How to: create custom callback handlers
- How to: make callbacks run in the background
Customβ
All of LangChain components can easily be extended to support your own versions.
- How to: create a custom chat model class
- How to: create a custom LLM class
- How to: write a custom retriever class
- How to: write a custom document loader
- How to: define a custom tool
- How to: create custom callback handlers
Generative UIβ
- How to: build an LLM generated UI
- How to: stream agentic data to the client
- How to: stream structured output to the client
Multimodalβ
- How to: pass multimodal data directly to models
- How to: use multimodal prompts
- How to: call tools with multimodal data
Use casesβ
These guides cover use-case specific details.
Q&A with RAGβ
Retrieval Augmented Generation (RAG) is a way to connect LLMs to external sources of data. For a high-level tutorial on RAG, check out this guide.
- How to: add chat history
- How to: stream
- How to: return sources
- How to: return citations
- How to: do per-user retrieval
Extractionβ
Extraction is when you use LLMs to extract structured information from unstructured text. For a high level tutorial on extraction, check out this guide.
- How to: use reference examples
- How to: handle long text
- How to: do extraction without using function calling
Chatbotsβ
Chatbots involve using an LLM to have a conversation. For a high-level tutorial on building chatbots, check out this guide.
Query analysisβ
Query Analysis is the task of using an LLM to generate a query to send to a retriever. For a high-level tutorial on query analysis, check out this guide.
- How to: add examples to the prompt
- How to: handle cases where no queries are generated
- How to: handle multiple queries
- How to: handle multiple retrievers
- How to: construct filters
- How to: deal with high cardinality categorical variables
Q&A over SQL + CSVβ
You can use LLMs to do question answering over tabular data. For a high-level tutorial, check out this guide.
- How to: use prompting to improve results
- How to: do query validation
- How to: deal with large databases
Q&A over graph databasesβ
You can use an LLM to do question answering over graph databases. For a high-level tutorial, check out this guide.
- How to: map values to a database
- How to: add a semantic layer over the database
- How to: improve results with prompting
- How to: construct knowledge graphs
LangGraph.jsβ
LangGraph.js is an extension of LangChain aimed at building robust and stateful multi-actor applications with LLMs by modeling steps as edges and nodes in a graph.
LangGraph.js documentation is currently hosted on a separate site. You can peruse LangGraph.js how-to guides here.
LangSmithβ
LangSmith allows you to closely trace, monitor and evaluate your LLM application. It seamlessly integrates with LangChain and LangGraph.js, and you can use it to inspect and debug individual steps of your chains as you build.
LangSmith documentation is hosted on a separate site. You can peruse LangSmith how-to guides here.
Evaluationβ
Evaluating performance is a vital part of building LLM-powered applications. LangSmith helps with every step of the process from creating a dataset to defining metrics to running evaluators.
To learn more, check out the LangSmith evaluation how-to guides.