0Pricing
AI Agents · Lesson

LCEL (LangChain Expression Language)

Compose runnables with the pipe operator '|', use RunnablePassthrough, and stream over the chain.

What Is LCEL?

LangChain Expression Language is the modern way to compose chains. It uses the pipe operator | to chain Runnables.

It replaced the old "Chain" classes (LLMChain, SequentialChain) which are now legacy.

A Basic LCEL Chain

from langchain.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from langchain.schema.output_parser import StrOutputParser

prompt = ChatPromptTemplate.from_template('Translate {text} to French.')
model = ChatOpenAI(model='gpt-4o-mini')
parser = StrOutputParser()

chain = prompt | model | parser
print(chain.invoke({'text': 'Hello, world!'}))

All lessons in this course

  1. LangChain Architecture: Models, Prompts, Chains
  2. Loaders, Splitters and Vector Stores
  3. LCEL (LangChain Expression Language)
  4. Building a RAG Chain End-to-End
← Back to AI Agents