> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview of LCEL

> Introduction to LangChain Expression Language, a concise declarative DSL using pipe-style chains to compose reusable LLM pipelines, Runnables, retrievers, transformers, and parsers.

Welcome back. This lesson introduces the LangChain Expression Language (LCEL) — a concise, declarative way to compose LangChain pipelines. LCEL makes it easy to build modular, production-ready applications by expressing chains with a familiar pipe-style syntax rather than constructing them imperatively.

What is LCEL?

* LCEL is a domain-specific language (DSL) designed for composing LLM-centric pipelines declaratively.
* It models LangChain components (prompts, LLMs, retrievers, output parsers, custom functions, etc.) as composable Runnables with well-defined inputs and outputs.
* Using a pipe operator, LCEL chains components so the output of one step becomes the input to the next, enabling readable, maintainable, and testable workflows.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/Xqjckn2TzkOV2Gz2/images/LangChain/Introduction-to-LCEL/Overview-of-LCEL/langchain-expression-language-user-to-model.jpg?fit=max&auto=format&n=Xqjckn2TzkOV2Gz2&q=85&s=6da7ede1d975327b2294ed5bb2072064" alt="The image illustrates the concept of &#x22;LangChain Expression Language,&#x22; showing a flow from &#x22;User&#x22; to &#x22;Language Model&#x22; through a &#x22;Chain&#x22; process." width="1920" height="1080" data-path="images/LangChain/Introduction-to-LCEL/Overview-of-LCEL/langchain-expression-language-user-to-model.jpg" />
</Frame>

LCEL draws a clear analogy to Unix pipelines: if you’re used to chaining shell commands with `|`, LCEL uses the same mental model to connect LangChain components.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/Xqjckn2TzkOV2Gz2/images/LangChain/Introduction-to-LCEL/Overview-of-LCEL/langchain-expression-language-terminal-windows.jpg?fit=max&auto=format&n=Xqjckn2TzkOV2Gz2&q=85&s=4fbefebde9b8577cca51b69245e5cc26" alt="The image shows two terminal windows labeled &#x22;Terminal&#x22; with &#x22;Command&#x22; and &#x22;Output&#x22; text, and an arrow connecting them under the title &#x22;What is LangChain Expression Language?&#x22;." width="1920" height="1080" data-path="images/LangChain/Introduction-to-LCEL/Overview-of-LCEL/langchain-expression-language-terminal-windows.jpg" />
</Frame>

Example shell pipeline:

```bash theme={null}
cat file.txt | grep "error" | wc -l
```

This command finds lines containing "error" in `file.txt` and counts them. The pipe operator makes the composition concise and expressive.

LCEL applies the same pattern to LLM workflows: connect prompts, transformations, retrievers, LLMs, and parsers into a single pipeline that flows from input to final output.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/Xqjckn2TzkOV2Gz2/images/LangChain/Introduction-to-LCEL/Overview-of-LCEL/langchain-expression-language-diagram.jpg?fit=max&auto=format&n=Xqjckn2TzkOV2Gz2&q=85&s=d1bbae4d75d4a5184e13029114f9f1a4" alt="The image is a diagram explaining the LangChain Expression Language, showing its components like prompts and output parsers in the context of a large language model (LLM) workflow." width="1920" height="1080" data-path="images/LangChain/Introduction-to-LCEL/Overview-of-LCEL/langchain-expression-language-diagram.jpg" />
</Frame>

Core concept: Runnable

* The Runnable interface is the common abstraction that enables composability. Any component that implements Runnable can be piped into LCEL chains.
* Runnable specifies how a component accepts input, executes, and returns output — allowing components to fit into pipelines predictably.

LCEL’s design goals:

* Declarative composition: define what you want to run, not how to wire objects together imperatively.
* Readability: pipelines read left-to-right like data flow.
* Reusability: chains are values you can store, reuse, or nest.
* Extensibility: custom Runnables (functions, retrievers, formatters) plug directly into pipelines.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/Xqjckn2TzkOV2Gz2/images/LangChain/Introduction-to-LCEL/Overview-of-LCEL/langchain-expression-language-diagram-2.jpg?fit=max&auto=format&n=Xqjckn2TzkOV2Gz2&q=85&s=9fbd9fea9a6a3bb1ef6c821f32a9f53e" alt="The image is a diagram explaining LangChain Expression Language, featuring a dark terminal window labeled &#x22;Runnable&#x22; and &#x22;Output&#x22; surrounded by colorful circles containing gear and box icons." width="1920" height="1080" data-path="images/LangChain/Introduction-to-LCEL/Overview-of-LCEL/langchain-expression-language-diagram-2.jpg" />
</Frame>

Quick comparison — shell vs LCEL (Python pseudocode):

* Unix pipe example (shell)

```bash theme={null}
cat file.txt | grep "error" | wc -l
```

* Equivalent LCEL-style composition (Python pseudocode)

```python theme={null}
chain = prompt | llm | output_parser
result = chain.invoke({"question": "Tell me about the Godfather movie"})
```

How a typical LCEL pipeline flows:

1. A prompt or input-producing Runnable emits a string or structured payload.
2. Optional transformers or enrichment functions modify or augment the payload (e.g., add context).
3. A retriever fetches external knowledge (documents, embeddings, KBs) and enriches the prompt.
4. The enriched prompt is passed to the LLM Runnable, which returns raw model output.
5. An output parser or post-processor transforms the raw output into structured data or final results.

Because chains are first-class values, you can nest them:

* Compose smaller chains into larger workflows.
* Build hierarchical or meta-chains for complex systems.

Common LCEL components and use cases:

| Component Type | Typical Role                                  | Example                         |
| -------------- | --------------------------------------------- | ------------------------------- |
| Prompt         | Produce or format model input                 | `PromptTemplate`                |
| Transformer    | Enrich/modify payload before/after model call | custom function                 |
| Retriever      | Fetch external data to augment prompt         | `VectorStoreRetriever`          |
| LLM            | Generate text or structured output            | `OpenAI`, `Anthropic`           |
| Output Parser  | Parse model output into structured data       | `RegexParser`, `PydanticParser` |

<Callout icon="lightbulb" color="#1CB2FE">
  LCEL is increasingly the canonical way to express LangChain workflows. For a detailed comparison between imperative chain construction (e.g., `LLMChain`) and LCEL, see the [official LangChain documentation](https://langchain.readthedocs.io/en/latest/) for API examples, best practices, and custom Runnable implementations.
</Callout>

Where to use LCEL

* Building QA systems that combine retrievers, LLMs, and post-processors.
* Orchestrating complex pipelines with conditional logic and nested chains.
* Rapid prototyping of LLM-powered microservices and production systems.

What’s next in this lesson

* Practical demos and hands-on labs that demonstrate creating Runnables, building LCEL pipelines, and composing chains of chains.
* Examples will cover retriever-augmented generation, output parsing with structured types, and deploying LCEL workflows in production.

If you’re ready to build modular, composable LLM applications, LCEL is a foundational concept to master.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/langchain/module/754457c5-1386-422b-98ad-3342dfc6aab3/lesson/59a17ad6-cdd8-42a5-868b-d7b47163d130" />
</CardGroup>
