Skip to main content

[ ![🦜️🔗 Langchain](/img/brand/wordmark.png) ![🦜️🔗
Langchain](/img/brand/wordmark-dark.png) ](/) [ Docs
](/docs/get_started/introduction) [ Use cases ](/docs/use_cases) [
Integrations ](/docs/integrations/platforms/) [ Guides
](/docs/guides/debugging) [ API  ](https://api.python.langchain.com)

More

  * [ People ](/docs/people/)
  * [ Versioning ](/docs/packages)
  * [ Changelog ](/docs/changelog)
  * [ Contributing ](/docs/contributing)
  * [ Templates ](/docs/templates/)
  * [ Cookbooks  ](https://github.com/langchain-ai/langchain/blob/master/cookbook/README.md)
  * [ Tutorials ](/docs/additional_resources/tutorials)
  * [ YouTube ](/docs/additional_resources/youtube)

🦜️🔗

  * [ LangSmith  ](https://smith.langchain.com)
  * [ LangSmith Docs  ](https://docs.smith.langchain.com/)
  * [ LangServe GitHub  ](https://github.com/langchain-ai/langserve)
  * [ Templates GitHub  ](https://github.com/langchain-ai/langchain/tree/master/templates)
  * [ Templates Hub  ](https://templates.langchain.com)
  * [ LangChain Hub  ](https://smith.langchain.com/hub)
  * [ JS/TS Docs  ](https://js.langchain.com)

[ 💬  ](https://chat.langchain.com) [ ](https://github.com/langchain-
ai/langchain)

Search

  * [ Get started ](/docs/get_started)

    * [ Introduction ](/docs/get_started/introduction)
    * [ Installation ](/docs/get_started/installation)
    * [ Quickstart ](/docs/get_started/quickstart)
    * [ Security ](/docs/security)
  * [ LangChain Expression Language ](/docs/expression_language/)

    * [ Get started ](/docs/expression_language/get_started)
    * [ Why use LCEL ](/docs/expression_language/why)
    * [ Interface ](/docs/expression_language/interface)
    * [ Streaming ](/docs/expression_language/streaming)
    * [ How to ](/docs/expression_language/how_to/)

    * [ Cookbook ](/docs/expression_language/cookbook/)

    * [ LangChain Expression Language (LCEL) ](/docs/expression_language/)
  * [ Modules ](/docs/modules/)

    * [ Model I/O ](/docs/modules/model_io/)

    * [ Retrieval ](/docs/modules/data_connection/)

    * [ Agents ](/docs/modules/agents/)

    * [ Chains ](/docs/modules/chains)
    * [ More ](/docs/modules/memory/)

  * [ LangServe ](/docs/langserve)
  * [ LangSmith ](/docs/langsmith/)

  * [ LangGraph ](/docs/langgraph)

  * [ ](/)
  * [ LangChain Expression Language  ](/docs/expression_language/)
  * Why use LCEL 

On this page

#  Why use LCEL

tip

We recommend reading the LCEL [ Get started
](/docs/expression_language/get_started) section first.

LCEL makes it easy to build complex chains from basic components. It does this
by providing: 1. **A unified interface** : Every LCEL object implements the `
Runnable ` interface, which defines a common set of invocation methods ( `
invoke ` , ` batch ` , ` stream ` , ` ainvoke ` , …). This makes it possible
for chains of LCEL objects to also automatically support these invocations.
That is, every chain of LCEL objects is itself an LCEL object. 2.
**Composition primitives** : LCEL provides a number of primitives that make it
easy to compose chains, parallelize components, add fallbacks, dynamically
configure chain internal, and more.

To better understand the value of LCEL, it’s helpful to see it in action and
think about how we might recreate similar functionality without it. In this
walkthrough we’ll do just that with our [ basic example
](/docs/expression_language/get_started#basic_example) from the get started
section. We’ll take our simple prompt + model chain, which under the hood
already defines a lot of functionality, and see what it would take to recreate
all of it.

    
    
    %pip install --upgrade --quiet  langchain-core langchain-openai langchain-anthropic  
    

##  Invoke  ​

In the simplest case, we just want to pass in a topic string and get back a
joke string:

####  Without LCEL  ​

    
    
    from typing import List  
      
    import openai  
      
      
    prompt_template = "Tell me a short joke about {topic}"