Skip to content

Runnables and LCEL

A Runnable is a unit of work with standard methods such as invoke, batch, and stream. LangChain Expression Language (LCEL) composes Runnables with |.

from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_template("Summarize ticket: {ticket}")
chain = prompt | model | StrOutputParser()
summary = chain.invoke({"ticket": "Checkout returns HTTP 503."})

The output of each step becomes the input of the next. A dictionary inside a sequence creates parallel branches; a RunnableSequence runs steps in order.

Composition can hide a wide retry boundary. If prompt | model | send_email is retried as one unit, the email step may run twice. Apply timeout, retry, and tracing configuration to the smallest risky component.

invoke and ainvoke · RunnableConfig · Retries and backoff