Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsHow toFoundationalDocumentsMemoryAgentsCallbacksModulesSecurityGuidesMoreModulesChainsOn this pageChainsUsing an LLM in isolation is fine for simple applications, but more complex applications require chaining LLMs - either with each other or with other components.LangChain provides two high-level frameworks for "chaining" components. The legacy approach is to use the Chain interface. The updated approach is to use the LangChain Expression Language (LCEL). When building new applications we recommend using LCEL for chain composition. But there are a number of useful, built-in Chain's that we continue to support, so we document both frameworks here. As we'll touch on below, Chain's can also themselves be used in LCEL, so the two are not mutually exclusive.LCEL‚ÄãThe most visible part of LCEL is that it provides an intuitive and readable syntax for composition. But more importantly, it also provides first-class support for:streaming,async calls,batching,parallelization,retries,fallbacks,tracing,and more.As a simple and common example, we can see what it's like to combine a prompt, model and output parser:from langchain.chat_models import ChatAnthropicfrom langchain.prompts import ChatPromptTemplatefrom langchain.schema import StrOutputParsermodel = ChatAnthropic()prompt = ChatPromptTemplate.from_messages([    ("system", "You're a very knowledgeable historian who provides accurate and eloquent answers to historical questions."),    ("human", "{question}"),])runnable = prompt | model | StrOutputParser()for chunk in runnable.stream({"question": "How did Mansa Musa accumulate his wealth?"}):    print(chunk, end="", flush=True)     Mansa Musa was the emperor of the Mali Empire
Using an LLM in isolation is fine for simple applications, but more complex applications require chaining LLMs - either with each other or with other components.
Using an LLM in isolation is fine for simple applications, but more complex applications require chaining LLMs - either with each other or with other components. ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsHow toFoundationalDocumentsMemoryAgentsCallbacksModulesSecurityGuidesMoreModulesChainsOn this pageChainsUsing an LLM in isolation is fine for simple applications, but more complex applications require chaining LLMs - either with each other or with other components.LangChain provides two high-level frameworks for "chaining" components. The legacy approach is to use the Chain interface. The updated approach is to use the LangChain Expression Language (LCEL). When building new applications we recommend using LCEL for chain composition. But there are a number of useful, built-in Chain's that we continue to support, so we document both frameworks here. As we'll touch on below, Chain's can also themselves be used in LCEL, so the two are not mutually exclusive.LCEL‚ÄãThe most visible part of LCEL is that it provides an intuitive and readable syntax for composition. But more importantly, it also provides first-class support for:streaming,async calls,batching,parallelization,retries,fallbacks,tracing,and more.As a simple and common example, we can see what it's like to combine a prompt, model and output parser:from langchain.chat_models import ChatAnthropicfrom langchain.prompts import ChatPromptTemplatefrom langchain.schema import StrOutputParsermodel = ChatAnthropic()prompt = ChatPromptTemplate.from_messages([    ("system", "You're a very knowledgeable historian who provides accurate and eloquent answers to historical questions."),    ("human", "{question}"),])runnable = prompt | model | StrOutputParser()for chunk in runnable.stream({"question": "How did Mansa Musa accumulate his wealth?"}):    print(chunk, end="", flush=True)     Mansa Musa was the emperor of the Mali Empire