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.
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 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.
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.
A named tuple containing the score and reasoning for a trajectory.
Trajectory output parser.
A chain for evaluating ReAct style agents.
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.
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.
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.
Distance metric to use.
Compute string distances between the prediction and the reference.
Compute string edit distances between two predictions.
Evaluate whether the prediction is valid JSON.
Json Equality Evaluator.
An evaluator that calculates the edit distance between JSON strings.
An evaluator that validates a JSON prediction against a JSON schema reference.
Base class for prompt selectors.
Prompt collection that goes through conditionals.
Abstract base class for creating structured sequences of calls to components.
Chain that transforms the chain output.
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.
A typed dictionary containing information about elements in the viewport.
A crawler for web pages.
Class for a constitutional principle.
Class representing a single statement.
A question and its answer as a list of facts.
An answer to the question, with sources.
Raise an ImportError if APIChain is used without langchain_community.
Interface for the combine_docs method.
Interface for the combine_docs method.
Base interface for chains combining documents.
Generate hypothetical document for query, and then embed that.
Output parser that checks if the output is finished.
Chain that generates questions from uncertain spans.
Flare chain.
Interface for loading the combine documents chain.
Input type for ConversationalRetrievalChain.
Chain for chatting with an index.
Chain for chatting with a vector database.
Information about a data source attribute.
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.
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.
Parser for output of router chain in the multi-prompt chain.
Chain that uses embeddings to route between options.
Question-answering with sources over a vector database.
Interface for loading the combine documents chain.
Question-answering with sources over an index.
Interface for loading the combine documents chain.
Chain for interacting with Elasticsearch Database.
Input for a SQL Chain.
Input for a SQL Chain.
Chat prompt template for the agent scratchpad.
Tool that is run when invalid tool name is encountered by agent.
Iterator for AgentExecutor.
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.
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.
Memory used to save agent output AND intermediate steps.
MRKL Output parser for the chat agent.
Configuration for a chain to use in MRKL system.
Output parser for the conversational agent.
Output parser for the chat agent.
Output parser for the conversational agent.
Information about a VectorStore.
Toolkit for interacting with a VectorStore.
Toolkit for routing between Vector Stores.
Parses ReAct-style LLM calls that have a single tool input.
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 action/finish.
Parses a message into agent actions/finish.
Parses tool invocations and final answers from XML-formatted agent output.
Output parser for the ReAct agent.
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.
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.
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.
A simple progress bar for the console.
Wraps a store with key and value encoders/decoders.
BaseStore interface that works on the local file system.
Output parser for a list of lines.
Given a query, use an LLM to write a set of queries.
Retriever that merges the results of multiple retrievers.
Time Weighted Vector Store Retriever.
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.
Given a query, use an LLM to re-phrase it.
Retriever that wraps a base retriever and compresses the results.
Self Query Retriever.
Document compressor that uses CrossEncoder for reranking.
Filter that drops documents that aren't relevant to the query.
Parse outputs that could return a null string of some sort.
LLM Chain Extractor.
Document compressor that uses Zero-Shot Listwise Document Reranking.
Document compressor that uses a pipeline of Transformers.
Embeddings Filter.
Callback handler that returns an async iterator.
Callback handler for streaming in agents.
Callback handler that returns an async iterator.
Tracer that logs via the input Logger.
A function description for ChatOpenAI.
A runnable that routes to the selected function.
Interface for caching results from embedding models.
Memory wrapper that is read-only and cannot be changed.
Conversation chat memory with token limit and vectordb backing.
Simple Memory.
Combining multiple memories' data together.
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.
Parse an output using Pandas DataFrame format.
Parse YAML output using a Pydantic model.
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.
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 to a datetime.
Parse the output of an LLM call into a Dictionary using a regex.
Combine multiple output parsers into one.
Input for the retry chain of the OutputFixingParser.
Wrap a parser and try to fix parsing errors.
Parse the output of an LLM call using a regex.
Parse the output of an LLM call to a boolean.
Abstract base class for memory in Chains.
Map-reduce chain.
Chain to run queries against LLMs.
Implement an LLM driven browser.
Chain for applying constitutional principles.
Chain that interprets a prompt and executes python code to do math.
Chain for making a simple request to an API endpoint.
Combine documents by doing a first pass and then refining on more documents.
Combine documents by recursively reducing them.
Combining documents by mapping a chain over them, then reranking results.
Chain that combines documents by stuffing into context.
Chain that splits documents, then analyzes it in pieces.
Combining documents by mapping a chain over them, then combining results.
Base class for question-answer generation chains.
Chain for question-answering with self-verification.
Chain for having a conversation based on retrieved documents.
A router chain that uses an LLM chain to perform routing.
A multi-route chain that uses an LLM router chain to choose amongst prompts.
Chain for question-answering with self-verification.
Base class for question-answering chains.
Chain for question-answering against an index.
Chain for question-answering against a vector database.
Question answering chain with sources over documents.
Question answering with sources over documents.
Chain to have a conversation and load context from memory.
Base class for single action agents.
Agent that calls the language model and deciding the action.
An enum for agent types.
Structured Chat Agent.
An Agent driven by OpenAIs function powered API.
Agent for the MRKL chain.
Chain that implements the MRKL system.
An agent that holds a conversation in addition to using tools.
Chat Agent.
Agent that uses XML tags.
Agent driven by OpenAIs function powered API.
An agent designed to hold a conversation in addition to using tools.
Agent for the self-ask-with-search paper.
[Deprecated] Chain that does self-ask with search.
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.
Document compressor that uses Cohere Rerank API.
An instance of a runnable stored in the LangChain Hub.
Mixin for summarizer.
Continually summarizes the conversation history.
A basic memory implementation that simply stores the conversation history.
A basic memory implementation that simply stores the conversation history.
Vector Store Retriever Memory.
Use to keep track of the last k turns of a conversation.
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.
Buffer with summarizer for storing conversation memory.
Abstract base class for chat memory.
Conversation chat memory with token limit.
Get the appropriate function output parser given the user functions.
Parse an AI message potentially containing tool_calls.
Use a single chain to route an input to one of multiple retrieval qa chains.