liveBook · Manning

LCEL

As explained in Build AI-Enhanced Web Apps

LangChain Expression Language (LCEL) is a declarative syntax for composing LangChain functions into executable chains and workflows.

LCEL is a declarative syntax for composing LangChain Runnables into executable chains. You describe the workflow, and LangChain optimizes execution; each resulting chain remains a Runnable that can be invoked, batched, or streamed. section 6.5.1 section 6.1.1

Build LCEL workflows from reusable composition primitives:

  • Use RunnableSequence when each step consumes the previous step’s output. section 6.5.1
  • Use RunnableParallel when several Runnables should process the same input concurrently and return keyed results. section 6.5.1
  • Use RunnableLambda to wrap ordinary JavaScript functions and add custom logic to a chain. section 6.5.1

Sequential text-processing chain

A runnable chain can uppercase input, count its vowels, format a prompt, call ChatOpenAI, and parse the response with StringOutputParser. The same workflow can be expressed with pipe composition or RunnableSequence.from([...]). section 6.1.1 section 6.1.1

const chain = new RunnableSequence({ 
first: runnable1, 
last: runnable2, 
});

Use the supplied RunnableSequence pattern to inspect the compact structure of a sequential LCEL chain. section 6.5.1

const chain = new RunnableParallel({ 
   key1: runnable1, 
   key2: runnable2, 
});

Use the supplied RunnableParallel pattern to compare concurrent branches that share one input. section 6.5.1

const someFunc = RunnableLambda.from((input) => {
return input; 
}); 
const chain = someFunc.pipe(runnable1);

Use the supplied RunnableLambda pattern to connect custom JavaScript functions with existing Runnables. section 6.5.1

How Build AI-Enhanced Web Apps covers it

How deep it goes
Defines core primitives and execution behavior, then stops short of loops, conditional logic, and stateful agent architecture.
Examples
Demonstrates uppercase transformation, vowel counting, prompt formatting, ChatOpenAI invocation, and string output parsing.
What it assumes
Assumes JavaScript and LangChain Runnable familiarity while introducing LCEL through existing components and runnable examples.
What you can do after
Build linear chains with JavaScript functions, prompts, language models, parsers, batching, streaming, and Runnable composition.
How it connects
Connects Runnables, RunnableSequence, RunnableParallel, RunnableLambda, prompts, language models, output parsers, and LangGraph.

Also explained in

Compare how 2 books explain LCEL →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.