!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}(),document.documentElement.setAttribute("data-announcement-bar-initially-dismissed",function(){try{return"true"===localStorage.getItem("docusaurus.announcement.dismiss")}catch(t){}return!1}())

[Skip to main content](#__docusaurus_skipToContent_fallback)

LangChain v0.2 is coming soon! Preview the new docs [here](/v0.2/docs/introduction/).

[

![🦜️🔗 Langchain](/v0.1/img/brand/wordmark.png)![🦜️🔗 Langchain](/v0.1/img/brand/wordmark-dark.png)

](/v0.1/)[Docs](/v0.1/docs/get_started/introduction/)[Use cases](/v0.1/docs/use_cases/)[Integrations](/v0.1/docs/integrations/platforms/)[API Reference](https://api.js.langchain.com)

[More](#)

*   [People](/v0.1/docs/people/)
*   [Community](/v0.1/docs/community/)
*   [Tutorials](/v0.1/docs/additional_resources/tutorials/)
*   [Contributing](/v0.1/docs/contributing/)

[v0.1](#)

*   [v0.2](https://js.langchain.com/v0.2/docs/introduction)
*   [v0.1](/v0.1/docs/get_started/introduction/)

[🦜🔗](#)

*   [LangSmith](https://smith.langchain.com)
*   [LangSmith Docs](https://docs.smith.langchain.com)
*   [LangChain Hub](https://smith.langchain.com/hub)
*   [LangServe](https://github.com/langchain-ai/langserve)
*   [Python Docs](https://python.langchain.com/)

[Chat](https://chatjs.langchain.com)[](https://github.com/langchain-ai/langchainjs)

Search

*   [Get started](/v0.1/docs/get_started/)
    
    *   [Introduction](/v0.1/docs/get_started/introduction/)
    *   [Installation](/v0.1/docs/get_started/installation/)
    *   [Quickstart](/v0.1/docs/get_started/quickstart/)
*   [LangChain Expression Language](/v0.1/docs/expression_language/)
    
    *   [Get started](/v0.1/docs/expression_language/get_started/)
    *   [Why use LCEL?](/v0.1/docs/expression_language/why/)
    *   [Interface](/v0.1/docs/expression_language/interface/)
    *   [Streaming](/v0.1/docs/expression_language/streaming/)
    *   [How to](/v0.1/docs/expression_language/how_to/routing/)
        
    *   [Cookbook](/v0.1/docs/expression_language/cookbook/)
        
    *   [LangChain Expression Language (LCEL)](/v0.1/docs/expression_language/)
*   [Modules](/v0.1/docs/modules/)
    
    *   [Model I/O](/v0.1/docs/modules/model_io/)
        
    *   [Retrieval](/v0.1/docs/modules/data_connection/)
        
    *   [Chains](/v0.1/docs/modules/chains/)
    *   [Agents](/v0.1/docs/modules/agents/)
        
    *   [More](/v0.1/docs/modules/memory/)
        
*   [Security](/v0.1/docs/security/)
*   [Guides](/v0.1/docs/guides/)
    
*   [Ecosystem](/v0.1/docs/ecosystem/)
    
*   [LangGraph](/v0.1/docs/langgraph/)
*   * * *
    

*   [](/v0.1/)
*   [Modules](/v0.1/docs/modules/)
*   Chains

Chains
======

Chains refer to sequences of calls - whether to an LLM, a tool, or a data preprocessing step. The primary supported way to do this is with [LCEL](/v0.1/docs/expression_language/).

LCEL is great for constructing your own chains, but it’s also nice to have chains that you can use off-the-shelf. There are two types of off-the-shelf chains that LangChain supports:

*   Chains that are built with LCEL. In this case, LangChain offers a higher-level constructor method. However, all that is being done under the hood is constructing a chain with LCEL.
*   \[Legacy\] Chains constructed by subclassing from a legacy Chain class. These chains do not use LCEL under the hood but are rather standalone classes.

We are working creating methods that create LCEL versions of all chains. We are doing this for a few reasons.

1.  Chains constructed in this way are nice because if you want to modify the internals of a chain you can simply modify the LCEL.
2.  These chains natively support streaming, async, and batch out of the box.
3.  These chains automatically get observability at each step.

This page contains two lists. First, a list of all LCEL chain constructors. Second, a list of all legacy Chains.

LCEL Chains[​](#lcel-chains "Direct link to LCEL Chains")
---------------------------------------------------------

Below is a table of all LCEL chain constructors. In addition, we report on:

#### Chain Constructor[​](#chain-constructor "Direct link to Chain Constructor")

The constructor function for this chain. These are all methods that return LCEL runnables. We also link to the API documentation.

#### Function Calling[​](#function-calling "Direct link to Function Calling")

Whether this requires OpenAI function calling.

#### Other Tools[​](#other-tools "Direct link to Other Tools")

What other tools (if any) are used in this chain.

#### When to Use[​](#when-to-use "Direct link to When to Use")

Our commentary on when to use this chain.

Chain Constructor

Function Calling

Other Tools

When to Use

[createStuffDocumentsChain](https://api.js.langchain.com/functions/langchain_chains_combine_documents.createStuffDocumentsChain.html)

This chain takes a list of documents and formats them all into a prompt, then passes that prompt to an LLM. It passes ALL documents, so you should make sure it fits within the context window the LLM you are using.

[createOpenAIFnRunnable](https://api.js.langchain.com/functions/langchain_chains_openai_functions.createOpenAIFnRunnable.html)

✅

If you want to use OpenAI function calling to OPTIONALLY structure an output response. You may pass in multiple functions for the chain to call, but it does not have to call it.

[createStructuredOutputRunnable](https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html)

✅

If you want to use OpenAI function calling to FORCE the LLM to respond with a certain function. You may only pass in one function, and the chain will ALWAYS return this response.

[createHistoryAwareRetriever](https://api.js.langchain.com/functions/langchain_chains_history_aware_retriever.createHistoryAwareRetriever.html)

Retriever

This chain takes in conversation history and then uses that to generate a search query which is passed to the underlying retriever.

[createRetrievalChain](https://api.js.langchain.com/functions/langchain_chains_retrieval.createRetrievalChain.html)

Retriever

This chain takes in a user inquiry, which is then passed to the retriever to fetch relevant documents. Those documents (and original inputs) are then passed to an LLM to generate a response

Legacy Chains[​](#legacy-chains "Direct link to Legacy Chains")
---------------------------------------------------------------

Below we report on the legacy chain types that exist. We will maintain support for these until we are able to create a LCEL alternative. We cover:

#### Chain[​](#chain "Direct link to Chain")

Name of the chain, or name of the constructor method. If constructor method, this will return a Chain subclass.

#### Function Calling[​](#function-calling-1 "Direct link to Function Calling")

Whether this requires OpenAI Function Calling.

#### Other Tools[​](#other-tools-1 "Direct link to Other Tools")

Other tools used in the chain.

#### When to Use[​](#when-to-use-1 "Direct link to When to Use")

Our commentary on when to use.

Chain

Function Calling

Other Tools

When to Use

[createOpenAPIChain](https://api.js.langchain.com/functions/langchain_chains.createOpenAPIChain.html)

OpenAPI Spec

Similar to APIChain, this chain is designed to interact with APIs. The main difference is this is optimized for ease of use with OpenAPI endpoints.

[ConversationalRetrievalQAChain](https://api.js.langchain.com/classes/langchain_chains.ConversationalRetrievalQAChain.html)

Retriever

This chain can be used to have **conversations** with a document. It takes in a question and (optional) previous conversation history. If there is previous conversation history, it uses an LLM to rewrite the conversation into a query to send to a retriever (otherwise it just uses the newest user input). It then fetches those documents and passes them (along with the conversation) to an LLM to respond.

[StuffDocumentsChain](https://api.js.langchain.com/classes/langchain_chains.StuffDocumentsChain.html)

This chain takes a list of documents and formats them all into a prompt, then passes that prompt to an LLM. It passes ALL documents, so you should make sure it fits within the context window the LLM you are using.

[MapReduceDocumentsChain](https://api.js.langchain.com/classes/langchain_chains.MapReduceDocumentsChain.html)

This chain first passes each document through an LLM, then reduces them using the ReduceDocumentsChain. Useful in the same situations as ReduceDocumentsChain, but does an initial LLM call before trying to reduce the documents.

[RefineDocumentsChain](https://api.js.langchain.com/classes/langchain_chains.RefineDocumentsChain.html)

This chain collapses documents by generating an initial answer based on the first document and then looping over the remaining documents to _refine_ its answer. This operates sequentially, so it cannot be parallelized. It is useful in similar situatations as MapReduceDocuments Chain, but for cases where you want to build up an answer by refining the previous answer (rather than parallelizing calls).

[ConstitutionalChain](https://api.js.langchain.com/classes/langchain_chains.ConstitutionalChain.html)

This chain answers, then attempts to refine its answer based on constitutional principles that are provided. Use this when you want to enforce that a chain's answer follows some principles.

[LLMChain](https://api.js.langchain.com/classes/langchain_chains.LLMChain.html)

This chain simply combines a prompt with an LLM and an output parser. The recommended way to do this is just to use LCEL.

[GraphCypherQAChain](https://api.js.langchain.com/classes/langchain_chains_graph_qa_cypher.GraphCypherQAChain.html)

A graph that works with Cypher query language

This chain constructs an Cypher query from natural language, executes that query against the graph, and then passes the results back to an LLM to respond.

[createExtractionChain](https://api.js.langchain.com/functions/langchain_chains.createExtractionChain.html)

✅

Uses OpenAI Function calling to extract information from text.

[createExtractionChainFromZod](https://api.js.langchain.com/functions/langchain_chains.createExtractionChainFromZod.html)

✅

Uses OpenAI Function calling and a Zod schema to extract information from text.

[SqlDatabaseChain](https://api.js.langchain.com/classes/langchain_chains_sql_db.SqlDatabaseChain.html)

Answers questions by generating and running SQL queries for a provided database.

[LLMRouterChain](https://api.js.langchain.com/classes/langchain_chains.LLMRouterChain.html)

This chain uses an LLM to route between potential options.

[MultiPromptChain](https://api.js.langchain.com/classes/langchain_chains.MultiPromptChain.html)

This chain routes input between multiple prompts. Use this when you have multiple potential prompts you could use to respond and want to route to just one.

[MultiRetrievalQAChain](https://api.js.langchain.com/classes/langchain_chains.MultiRetrievalQAChain.html)

Retriever

This chain uses an LLM to route input questions to the appropriate retriever for question answering.

[loadQAChain](https://api.js.langchain.com/functions/langchain_chains.loadQAChain.html)

Retriever

Does question answering over documents you pass in, and cites it sources. Use this over RetrievalQAChain when you want to pass in the documents directly (rather than rely on a passed retriever to get them).

[APIChain](https://api.js.langchain.com/classes/langchain_chains.APIChain.html)

Requests Wrapper

This chain uses an LLM to convert a query into an API request, then executes that request, gets back a response, and then passes that request to an LLM to respond. Prefer `createOpenAPIChain` if you have a spec available.

* * *

#### Help us out by providing feedback on this documentation page:

[

Previous

Neo4j

](/v0.1/docs/modules/data_connection/experimental/graph_databases/neo4j/)[

Next

Agents

](/v0.1/docs/modules/agents/)

Community

*   [Discord](https://discord.gg/cU2adEyC7w)
*   [Twitter](https://twitter.com/LangChainAI)

GitHub

*   [Python](https://github.com/langchain-ai/langchain)
*   [JS/TS](https://github.com/langchain-ai/langchainjs)

More

*   [Homepage](https://langchain.com)
*   [Blog](https://blog.langchain.dev)

Copyright © 2024 LangChain, Inc.