LangChain Expression Language (LCEL): A Practical Guide to the Pipe Operator

By Carlos Montiel | Enterprise AI Specialist
Leer en español →
Published: 2026-07-28 | By: Carlos Montiel | Reading time: ~4 minutes

Before LCEL, chaining steps in LangChain meant nesting classes and configurations. With the pipe operator, a chain reads left to right, literally the way you think about it.

What LCEL solves

LCEL is an abstraction of interesting Python concepts into a format that enables a minimalist code layer for building chains of LangChain components. Chains are built by connecting Runnables with the pipe operator `|`, creating a clear left-to-right data flow — the `|` operator composes two Runnables into a RunnableSequence, which is itself also a Runnable, allowing chains of chains to be composed with no conceptual nesting limit.

Streaming built in from the design stage

LCEL supports incremental streaming to enable a faster time-to-first-token from language models, improving perceived responsiveness. LCEL integrates streaming natively and was designed from the start with this in mind — it isn't a layer bolted on afterward, it's part of the base architecture of how a chain works.

Fallbacks and retries without touching each step

Using `.with_fallbacks()` gives you real resilience: if the primary model fails, a backup model automatically takes over. Retry and fallback behavior (`.with_retry()`, `.with_fallbacks()`) and LangSmith tracing apply to the composed chain automatically, without having to touch how the individual steps are written — you add resilience by wrapping the chain, not by rewriting its internal logic.

Code example

from langchain_core.prompts import ChatPromptTemplate from langchain_openai import ChatOpenAI from langchain_core.output_parsers import StrOutputParser prompt = ChatPromptTemplate.from_template("Summarize this in one sentence: {text}") model = ChatOpenAI(model="gpt-4o-mini") parser = StrOutputParser() chain = prompt | model | parser # Sync print(chain.invoke({"text": "..."})) # Streaming for chunk in chain.stream({"text": "..."}): print(chunk, end="", flush=True) # With fallback to a backup model resilient_chain = chain.with_fallbacks([chain_with_backup_model])

Sync and async execution with no rewrites

LCEL simplifies building complex chains of operations, enabling both synchronous and asynchronous execution while supporting advanced features like streaming, retries, and fallbacks — the same chain defined with `.invoke()` works with `.ainvoke()` for the async equivalent, with no need for two separate implementations.

Carlos Montiel
Enterprise AI Solutions Architect
Specialist in LLMs, Agents, and Orchestration
guatemalia.com/en/#contact · info@guatemalia.com

Need to implement AI at your company?

Carlos Montiel is an enterprise AI solutions architect. He implements LLMs, Agents, RAG, and orchestrators for companies across Guatemala and Latin America. Reach out for a consultation.

Contact Carlos Montiel

info@guatemalia.com