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
- LangChain Architecture: Models, Prompts, Chains
- Loaders, Splitters and Vector Stores
- LCEL (LangChain Expression Language)
- Building a RAG Chain End-to-End