Mastering RunnableSequence in LangChain.js
Aug 8,2026

Introduction

In the previous articles, we learned about the Runnable Interface and how pipe() allows us to connect different LangChain components.

For example:

const chain = prompt
  .pipe(model)
  .pipe(parser);

This already looks like a sequence:

Input
  ↓
Prompt
  ↓
Model
  ↓
Parser
  ↓
Output

So you might have an obvious question:

If pipe() already chains components, why do we need RunnableSequence?

That's exactly what we'll answer in this article.

RunnableSequence is one of the core building blocks for creating multi-step AI workflows in LangChain.js.

We'll learn:

  • What RunnableSequence is
  • Why we need it
  • How it relates to pipe()
  • How to create a sequence explicitly
  • How data moves through a sequence
  • OpenAI examples
  • Gemini examples
  • Multi-step AI workflows
  • Real-world projects
  • Best practices
  • Common mistakes

Let's get started.


What is RunnableSequence?

RunnableSequence is a Runnable that executes multiple Runnables in a specific order.

For example:

Input
  ↓
Runnable 1
  ↓
Runnable 2
  ↓
Runnable 3
  ↓
Output

The output from one step becomes the input for the next step.

A typical AI workflow might look like:

User Input
    ↓
PromptTemplate
    ↓
Chat Model
    ↓
Output Parser
    ↓
Final Result

Each component performs one job.

RunnableSequence combines them into a single workflow.


Why Do We Need RunnableSequence?

Imagine manually executing every step:

const formattedPrompt =
  await prompt.invoke({
    topic: "Node.js",
  });

const modelResponse =
  await model.invoke(formattedPrompt);

const result =
  await parser.invoke(modelResponse);

This works, but the application becomes responsible for manually connecting every component.

With a sequence:

const chain = RunnableSequence.from([
  prompt,
  model,
  parser,
]);

const result = await chain.invoke({
  topic: "Node.js",
});

Now the entire workflow is represented by one Runnable.


RunnableSequence Architecture

Think about the workflow like a production pipeline:

              RunnableSequence

Input
  │
  ▼
┌───────────────┐
│ Prompt        │
└───────────────┘
  │
  ▼
┌───────────────┐
│ Chat Model    │
└───────────────┘
  │
  ▼
┌───────────────┐
│ Output Parser │
└───────────────┘
  │
  ▼
Output

The important rule is:

The output of one step becomes the input of the next step.


RunnableSequence vs pipe()

This is probably the most important part of this article.

You've already seen:

const chain = prompt
  .pipe(model)
  .pipe(parser);

You can also explicitly create the sequence:

import { RunnableSequence } from "@langchain/core/runnables";

const chain = RunnableSequence.from([
  prompt,
  model,
  parser,
]);

Both represent the same basic workflow:

Prompt
  ↓
Model
  ↓
Parser

So what's the difference?

pipe()

pipe() provides a convenient, fluent way to compose Runnables.

const chain = prompt
  .pipe(model)
  .pipe(parser);

RunnableSequence

RunnableSequence.from() makes the sequence explicit.

const chain = RunnableSequence.from([
  prompt,
  model,
  parser,
]);

For simple chains, pipe() is usually more readable.

RunnableSequence becomes particularly useful when you want to explicitly construct or reason about the ordered steps of a workflow.


Project Setup

Let's build some practical examples.

Create a project:

mkdir runnable-sequence
cd runnable-sequence
npm init -y

Install the required packages:

npm install langchain @langchain/openai @langchain/google-genai dotenv

For our parser example, we'll also use:

npm install @langchain/core

@langchain/core is also used by the other LangChain packages, but installing it explicitly makes the dependency clear for this tutorial.


Project Structure

runnable-sequence/
│
├── index.js
├── .env
└── package.json

Configure API Keys

Create a .env file:

OPENAI_API_KEY=your_openai_api_key
GOOGLE_API_KEY=your_google_api_key

Never commit this file to Git.

Add it to .gitignore:

node_modules/
.env

Import the Required Packages

import "dotenv/config";

import { ChatOpenAI } from "@langchain/openai";

import {
  ChatGoogleGenerativeAI,
} from "@langchain/google-genai";

import {
  PromptTemplate,
} from "@langchain/core/prompts";

import {
  StringOutputParser,
} from "@langchain/core/output_parsers";

import {
  RunnableSequence,
} from "@langchain/core/runnables";

Initialize OpenAI

const openAIModel = new ChatOpenAI({
  model: "gpt-4.1-mini",
});

Initialize Gemini

const geminiModel =
  new ChatGoogleGenerativeAI({
    model: "gemini-2.5-flash",
  });

Create Our First RunnableSequence

Let's start with a simple workflow.

const prompt =
  PromptTemplate.fromTemplate(
    "Explain {topic} in simple words."
  );

const chain = RunnableSequence.from([
  prompt,
  openAIModel,
]);

Now invoke the entire sequence:

const response =
  await chain.invoke({
    topic: "Node.js",
  });

console.log(response.content);

The execution flow is:

{ topic: "Node.js" }
        ↓
PromptTemplate
        ↓
"Explain Node.js in simple words."
        ↓
OpenAI
        ↓
AIMessage

Adding an Output Parser

Usually, we don't want the entire AIMessage object.

We want the generated text.

Let's add StringOutputParser.

const parser =
  new StringOutputParser();

Now create the sequence:

const chain = RunnableSequence.from([
  prompt,
  openAIModel,
  parser,
]);

Invoke it:

const result =
  await chain.invoke({
    topic: "Node.js",
  });

console.log(result);

Now the final result is a string.

Node.js is a JavaScript runtime...

Understanding the Complete Flow

The sequence is:

Input
  │
  │ { topic: "Node.js" }
  ▼
PromptTemplate
  │
  │ "Explain Node.js in simple words."
  ▼
OpenAI
  │
  │ AIMessage
  ▼
StringOutputParser
  │
  │ String
  ▼
Final Output

This is a complete AI pipeline.


RunnableSequence with Gemini

The same sequence can be used with Gemini.

const chain = RunnableSequence.from([
  prompt,
  geminiModel,
  parser,
]);

Invoke:

const result =
  await chain.invoke({
    topic: "React",
  });

console.log(result);

The workflow is:

Input
  ↓
PromptTemplate
  ↓
Gemini
  ↓
StringOutputParser
  ↓
String

Only the model changes.

The rest of the workflow remains the same.


Why Is This Useful?

This is one of the most important benefits of LangChain.

Your application logic doesn't have to be tightly coupled to a specific AI provider.

For example:

Prompt
  ↓
OpenAI
  ↓
Parser

can become:

Prompt
  ↓
Gemini
  ↓
Parser

without redesigning the entire workflow.


A More Practical Example

Let's build an AI explanation generator.

The application receives:

{
  topic: "JavaScript Closures",
  level: "beginner"
}

We want the AI to explain the topic according to the user's level.

Create the prompt:

const prompt =
  PromptTemplate.fromTemplate(`
Explain {topic} for a {level} developer.

Use a simple example.
`);

Create the sequence:

const chain =
  RunnableSequence.from([
    prompt,
    openAIModel,
    parser,
  ]);

Invoke it:

const result =
  await chain.invoke({
    topic: "JavaScript Closures",
    level: "beginner",
  });

console.log(result);

The workflow becomes:

Topic + Level
     ↓
PromptTemplate
     ↓
OpenAI
     ↓
StringOutputParser
     ↓
Explanation

Building a Multi-Step AI Workflow

Now let's make the workflow more interesting.

Suppose we want to:

  1. Receive a topic.
  2. Generate an explanation.
  3. Return the explanation as text.

That's still:

Input
 ↓
Prompt
 ↓
LLM
 ↓
Parser

But imagine extending it later:

Topic
 ↓
Generate Explanation
 ↓
Generate Summary
 ↓
Generate Tags
 ↓
Final Result

This is where sequences become increasingly valuable.

Each step can perform one specific task.


Important Rule: Input and Output Must Match

A RunnableSequence passes data from one step to the next.

For example:

Runnable A
    ↓
returns string
    ↓
Runnable B

Runnable B must be able to accept that string.

If Runnable A returns:

{
  title: "Node.js",
  summary: "..."
}

but Runnable B expects:

"Node.js"

you have a data-shape mismatch.

This is one of the most important things to understand when building longer sequences.


Example of a Data Mismatch

Suppose:

const firstStep = ...;

returns:

{
  topic: "Node.js"
}

Then the next step expects a plain string.

The workflow may fail because the input types don't match.

The general rule is:

Output of Step A
       ↓
must be compatible with
       ↓
Input of Step B

Always think about the data flowing through your sequence.


RunnableSequence with pipe()

The same sequence can often be expressed using pipe():

const chain =
  prompt
    .pipe(openAIModel)
    .pipe(parser);

Or explicitly:

const chain =
  RunnableSequence.from([
    prompt,
    openAIModel,
    parser,
  ]);

The second version makes the ordered list of steps very explicit.


When Should You Use pipe()?

Use pipe() when the workflow is short and straightforward.

For example:

const chain = prompt
  .pipe(model)
  .pipe(parser);

It's concise and easy to read.


When Should You Use RunnableSequence?

Use RunnableSequence when you want to explicitly represent a sequence of processing steps.

For example:

const chain = RunnableSequence.from([
  prompt,
  model,
  parser,
]);

It can also make larger workflows easier to reason about because the steps are clearly represented as an ordered collection.


Real-World Project: AI Blog Generator

Let's build a simple blog-generation workflow.

The input:

{
  topic: "Node.js Streams"
}

The workflow:

Topic
 ↓
Prompt
 ↓
LLM
 ↓
String Parser
 ↓
Blog Content

Code:

const blogPrompt =
  PromptTemplate.fromTemplate(`
Write a technical blog about {topic}.

Requirements:
- Use simple English.
- Explain the concept clearly.
- Include practical examples.
- Use Markdown.
`);

const blogChain =
  RunnableSequence.from([
    blogPrompt,
    openAIModel,
    new StringOutputParser(),
  ]);

const blog =
  await blogChain.invoke({
    topic: "Node.js Streams",
  });

console.log(blog);

The final output is a normal string containing the generated blog.


Real-World Project: Interview Question Generator

Let's create another example.

Input:

{
  technology: "React",
  count: 5
}

Prompt:

const interviewPrompt =
  PromptTemplate.fromTemplate(`
Generate {count} interview questions
for a {technology} developer.

Return the questions in a numbered list.
`);

Sequence:

const interviewChain =
  RunnableSequence.from([
    interviewPrompt,
    geminiModel,
    new StringOutputParser(),
  ]);

Invoke:

const questions =
  await interviewChain.invoke({
    technology: "React",
    count: 5,
  });

console.log(questions);

OpenAI and Gemini with the Same Workflow

One of the most useful patterns is keeping the workflow independent from the provider.

You can create a function:

function createBlogChain(model) {
  return RunnableSequence.from([
    blogPrompt,
    model,
    new StringOutputParser(),
  ]);
}

Now create an OpenAI chain:

const openAIChain =
  createBlogChain(openAIModel);

And a Gemini chain:

const geminiChain =
  createBlogChain(geminiModel);

The workflow remains identical.

Only the model changes.


Why This Pattern Is Useful

This approach makes your application easier to extend.

Today:

Prompt
 ↓
OpenAI
 ↓
Parser

Tomorrow:

Prompt
 ↓
Gemini
 ↓
Parser

You don't need to rewrite the entire chain.


RunnableSequence vs Manual Functions

You could implement the same workflow manually:

async function generateBlog(topic) {
  const prompt =
    `Write a blog about ${topic}`;

  const response =
    await openAIModel.invoke(prompt);

  return response.content;
}

This works.

But as the workflow becomes larger:

Prompt
 ↓
Model
 ↓
Parser
 ↓
Another Model
 ↓
Formatter
 ↓
Database

manual orchestration becomes increasingly difficult.

Runnable composition gives you a consistent way to represent these steps.


RunnableSequence and RAG

You might not be building RAG applications yet, but this concept will become important later.

A simplified RAG workflow might look like:

User Question
      ↓
Retriever
      ↓
Relevant Documents
      ↓
Prompt
      ↓
LLM
      ↓
Output Parser
      ↓
Answer

Many of these components can participate in Runnable-based workflows.

That's one reason understanding RunnableSequence now will make RAG much easier later.


Best Practices

1. Keep steps focused

Each Runnable should ideally perform one clear task.

Good:

Prompt
 ↓
Model
 ↓
Parser

Avoid creating one giant component that does everything.


2. Think about data shapes

Always ask:

What does this step return?

and:

What does the next step expect?

This prevents many runtime errors.


3. Use pipe() for simple sequences

For short workflows:

prompt
  .pipe(model)
  .pipe(parser);

is often the cleanest option.


4. Use explicit sequences when clarity helps

RunnableSequence.from([
  prompt,
  model,
  parser,
]);

This can make the workflow easier to understand when there are multiple steps.


5. Keep provider-specific logic isolated

Don't mix OpenAI-specific logic into every part of your application.

Instead:

Application
     ↓
Chain
     ↓
Model

This makes switching providers easier.


Common Mistakes

Mistake 1: Assuming RunnableSequence is the same as multiple invoke() calls

This:

await prompt.invoke(...);
await model.invoke(...);
await parser.invoke(...);

is manual orchestration.

A sequence represents those steps as a single composed Runnable.


Mistake 2: Ignoring output types

If one step returns an object and the next expects a string, the sequence can fail.

Always understand the data flowing between steps.


Mistake 3: Creating unnecessarily long sequences

Not every workflow needs ten steps.

Start simple:

Prompt
 ↓
Model
 ↓
Parser

Add steps only when they provide real value.


Mistake 4: Thinking RunnableSequence is only for LLMs

RunnableSequence can compose different Runnable-compatible components, not just language models.

That's what makes it useful for larger AI workflows.


What's Next?

We've now learned how to execute Runnables and how to compose them sequentially.

But what if we don't want to wait for one task to finish before starting another?

For example:

Question
   │
   ├──────► OpenAI
   │
   └──────► Gemini

Both models can work on the same question independently.

That's where RunnableParallel comes in.

In the next article, we'll learn:

Mastering RunnableParallel in LangChain.js: Run Multiple AI Workflows Concurrently (OpenAI + Gemini)

We'll see how to run independent Runnables concurrently and combine their results into a single output.


Final Thoughts

RunnableSequence is one of the fundamental building blocks for composing multi-step workflows in LangChain.js.

Instead of manually coordinating every operation, you can represent a workflow as a sequence:

Input
 ↓
Prompt
 ↓
Model
 ↓
Parser
 ↓
Output

The most important concept to remember is simple:

The output of one Runnable becomes the input of the next Runnable.

You've already seen this behavior with pipe(). RunnableSequence makes the ordered composition explicit.

Once you understand this pattern, you'll start recognizing it everywhere in LangChain—from simple prompt chains to more advanced RAG pipelines and AI agents.

And that's exactly what makes the Runnable architecture so powerful.

Happy Coding! 🚀