Looking for the JS/TS version? Check out LangChain.js.
To help you ship LangChain apps to production faster, check out LangSmith. LangSmith is a unified developer platform for building, testing, and monitoring LLM applications.
pip install langchain-classic
Legacy chains, langchain-community re-exports, indexing API, deprecated functionality, and more.
In most cases, you should be using the main langchain package.
For full documentation, see the API reference. For conceptual guides, tutorials, and examples on using LangChain, see the LangChain Docs.
See our Releases and Versioning policies.
As an open-source project in a rapidly developing field, we are extremely open to contributions, whether it be in the form of a new feature, improved infrastructure, or better documentation.
For detailed information on how to contribute, see the Contributing Guide.
A utility to experiment with and compare the performance of different models.
An instance of a runnable stored in the LangChain Hub.
A function description for ChatOpenAI.
A runnable that routes to the selected function.
Interface for caching results from embedding models.
Retriever that wraps a base retriever and compresses the results.
Output parser for a list of lines.
Given a query, use an LLM to write a set of queries.
Retriever that ensembles the multiple retrievers.
Enumerator of the types of search to perform.
Retriever that supports multiple embeddings per parent document.
Retrieve small chunks then retrieve their parent documents.
Retriever that merges the results of multiple retrievers.
Time Weighted Vector Store Retriever.
Given a query, use an LLM to re-phrase it.
Document compressor that uses CrossEncoder for reranking.
Embeddings Filter.
Filter that drops documents that aren't relevant to the query.
Document compressor that uses Zero-Shot Listwise Document Reranking.
Document compressor that uses a pipeline of Transformers.
Parse outputs that could return a null string of some sort.
LLM Chain Extractor.
Self Query Retriever.
Raised when the input format is invalid.
A dictionary of the results of a single test run.
Your architecture raised an error.
Input for a chat model.
A simple progress bar for the console.
Extract items to evaluate from the run object.
Extract items to evaluate from the run object.
Extract items to evaluate from the run object from a chain.
Map an input to the tool.
Map an example, or row in the dataset, to the inputs of an evaluation.
Evaluate Run and optional examples.
Configuration for a given run evaluator.
Configuration for a run evaluator that only requires a single key.
Configuration for a run evaluation.
Configuration for a reference-free criteria evaluator.
Configuration for a labeled (with references) criteria evaluator.
Configuration for an embedding distance evaluator.
Configuration for a string distance evaluator.
Configuration for a QA evaluator.
Configuration for a context-based QA evaluator.
Configuration for a context-based QA evaluator.
Configuration for a json validity evaluator.
Configuration for a json equality evaluator.
Configuration for an exact match string evaluator.
Configuration for a regex match string evaluator.
Configuration for a score string evaluator.
Configuration for a labeled score string evaluator.
Wraps a store with key and value encoders/decoders.
BaseStore interface that works on the local file system.
Simple Memory.
Conversation chat memory with token limit and vectordb backing.
Memory wrapper that is read-only and cannot be changed.
Combining multiple memories' data together.
Base class for prompt selectors.
Prompt collection that goes through conditionals.
Chain where the outputs of one chain feed directly into next.
Simple chain where the outputs of one step feed directly into next.
Pass input through a moderation endpoint.
Chain that transforms the chain output.
Abstract base class for creating structured sequences of calls to components.
Class for a constitutional principle.
Parser for output of router chain in the multi-prompt chain.
Multi Retrieval QA Chain.
A route to a destination chain.
Chain that outputs the name of a destination chain and the inputs to it.
Use a single chain to route an input to one of multiple candidate chains.
Chain that uses embeddings to route between options.
An answer to the question, with sources.
Chain for making a simple request to an API endpoint.
Class representing a single statement.
A question and its answer as a list of facts.
Generate hypothetical document for query, and then embed that.
Interface for loading the combine documents chain.
Interface for the combine_docs method.
Interface for the combine_docs method.
Base interface for chains combining documents.
A typed dictionary containing information about elements in the viewport.
A crawler for web pages.
Input type for ConversationalRetrievalChain.
Chain for chatting with an index.
Chain for chatting with a vector database.
Interface for loading the combine documents chain.
Chain for interacting with Elasticsearch Database.
Input for a SQL Chain.
Input for a SQL Chain.
Question-answering with sources over an index.
Question-answering with sources over a vector database.
Interface for loading the combine documents chain.
Output parser that checks if the output is finished.
Chain that generates questions from uncertain spans.
Flare chain.
A date in ISO 8601 format (YYYY-MM-DD).
A datetime in ISO 8601 format (YYYY-MM-DDTHH:MM:SS).
Transform a query string into an intermediate representation.
Output parser that parses a structured query.
Information about a data source attribute.
Raise an ImportError if APIChain is used without langchain_community.
Wrapper around a VectorStore for easy access.
Logic for creating indexes.
Table used to keep track of when a key was last updated.
A SQL Alchemy based implementation of the record manager.
Callback handler that returns an async iterator.
Callback handler that returns an async iterator.
Callback handler for streaming in agents.
Tracer that logs via the input Logger.
Base Single Action Agent class.
Base Multi Action Agent class.
Base class for parsing agent output into agent action/finish.
Base class for parsing agent output into agent actions/finish.
Agent powered by Runnables.
Agent powered by Runnables.
Tool that just returns the query.
Agent that is using tools.
Iterator for AgentExecutor.
Tool that is run when invalid tool name is encountered by agent.
Chat prompt template for the agent scratchpad.
Information about a VectorStore.
Toolkit for interacting with a VectorStore.
Toolkit for routing between Vector Stores.
Output parser for the conversational agent.
Output parser for the conversational agent.
AgentFinish with run and thread metadata.
AgentAction with info needed to submit custom tool output to existing run.
Run an OpenAI Assistant.
Output parser for the structured chat agent.
Output parser with retries for the structured chat agent.
MRKL Output parser for the chat agent.
Configuration for a chain to use in MRKL system.
Output parser for the chat agent.
Output parser for the ReAct agent.
Tool agent action.
Parses a message into agent actions/finish.
Parses self-ask style LLM calls.
Parses tool invocations and final answers in JSON format.
Parses ReAct-style LLM calls that have a single tool input in json format.
Parses a message into agent actions/finish.
Parses tool invocations and final answers from XML-formatted agent output.
Parses ReAct-style LLM calls that have a single tool input.
Parses a message into agent action/finish.
Memory used to save agent output AND intermediate steps.
The types of the evaluators.
A base class for evaluators that use an LLM.
String evaluator interface.
Compare the output of two models (or two outputs of the same model).
Interface for evaluating agent trajectories.
A Criteria to evaluate.
A parser for the output of the CriteriaEvalChain.
LLM Chain for evaluating runs against criteria.
Criteria evaluation chain that requires references.
Compute a regex match between the prediction and the reference.
Embedding Distance Metric.
Embedding distance evaluation chain.
Use embedding distances to score semantic difference between two predictions.
An evaluator that calculates the edit distance between JSON strings.
An evaluator that validates a JSON prediction against a JSON schema reference.
Evaluate whether the prediction is valid JSON.
Json Equality Evaluator.
A parser for the output of the ScoreStringEvalChain.
A chain for scoring on a scale of 1-10 the output of a model.
A chain for scoring the output of a model on a scale of 1-10.
A parser for the output of the PairwiseStringEvalChain.
Pairwise String Evaluation Chain.
Labeled Pairwise String Evaluation Chain.
Compute an exact match between the prediction and the reference.
A named tuple containing the score and reasoning for a trajectory.
Trajectory output parser.
A chain for evaluating ReAct style agents.
Distance metric to use.
Compute string distances between the prediction and the reference.
Compute string edit distances between two predictions.
LLM Chain for evaluating question answering.
LLM Chain for evaluating QA w/o GT based on context.
LLM Chain for evaluating QA using chain of thought reasoning.
LLM Chain for generating examples for question answering.
Schema for a response from a structured output parser.
Parse the output of an LLM call to a structured output.
Parse the output of an LLM call into a Dictionary using a regex.
Parse an output using Pandas DataFrame format.
Combine multiple output parsers into one.
Input for the retry chain of the OutputFixingParser.
Wrap a parser and try to fix parsing errors.
Parse YAML output using a Pydantic model.
Parse the output of an LLM call using a regex.
Parse the output of an LLM call to a datetime.
Parse the output of an LLM call to a boolean.
Parse an output that is one of a set of values.
Retry chain input for RetryOutputParser.
Retry chain input for RetryWithErrorOutputParser.
Wrap a parser and try to fix parsing errors.
Wrap a parser and try to fix parsing errors.
Abstract base class for memory in Chains.
Document compressor that uses Cohere Rerank API.
Vector Store Retriever Memory.
Conversation chat memory with token limit.
Use to keep track of the last k turns of a conversation.
Mixin for summarizer.
Continually summarizes the conversation history.
Buffer with summarizer for storing conversation memory.
Abstract base class for chat memory.
Abstract base class for Entity store.
In-memory Entity store.
Upstash Redis backed Entity store.
Redis-backed Entity store.
SQLite-backed Entity store with safe query construction.
Entity extractor & summarizer memory.
A basic memory implementation that simply stores the conversation history.
A basic memory implementation that simply stores the conversation history.
Chain to run queries against LLMs.
Map-reduce chain.
Chain for applying constitutional principles.
Base class for question-answering chains.
Chain for question-answering against an index.
Chain for question-answering against a vector database.
A multi-route chain that uses an LLM router chain to choose amongst prompts.
A router chain that uses an LLM chain to perform routing.
Chain for question-answering with self-verification.
Chain that combines documents by stuffing into context.
Combine documents by doing a first pass and then refining on more documents.
Combine documents by recursively reducing them.
Chain that splits documents, then analyzes it in pieces.
Combining documents by mapping a chain over them, then combining results.
Combining documents by mapping a chain over them, then reranking results.
Implement an LLM driven browser.
Chain for question-answering with self-verification.
Chain for having a conversation based on retrieved documents.
Chain that interprets a prompt and executes python code to do math.
Chain to have a conversation and load context from memory.
Base class for question-answer generation chains.
Question answering chain with sources over documents.
Question answering with sources over documents.
An enum for agent types.
Base class for single action agents.
Agent that calls the language model and deciding the action.
Agent driven by OpenAIs function powered API.
Agent that uses XML tags.
An agent that holds a conversation in addition to using tools.
An agent designed to hold a conversation in addition to using tools.
Structured Chat Agent.
Agent for the self-ask-with-search paper.
[Deprecated] Chain that does self-ask with search.
Agent for the MRKL chain.
Chain that implements the MRKL system.
Chat Agent.
Agent for the ReAct chain.
Class to assist with exploration of a document store.
Agent for the ReAct TextWorld chain.
[Deprecated] Chain that implements the ReAct paper.
An Agent driven by OpenAIs function powered API.
Get the appropriate function output parser given the user functions.
Parse an AI message potentially containing tool_calls.
DocumentFilter that uses an LLM chain to extract the relevant parts of documents.