Mastering RunnablePassthrough in LangChain.js
Aug 8,2026

Introduction

In the previous article, we learned about RunnableLambda.

RunnableLambda allows us to bring our own JavaScript logic into a LangChain workflow.

For example:

const prepareInput = new RunnableLambda({
  func: (data) => ({
    topic: data.topic.trim(),
  }),
});

This is useful when we need to transform or process data.

But there is another common situation.

Sometimes we don't want to transform the input at all.

We simply want to pass the original input to another Runnable.

For example:

User Input
    │
    ├──────────────→ Original Input
    │
    └──────────────→ AI Processing

Or perhaps we want to keep the original question while also generating an answer:

{
  question: "What is Node.js?",
  answer: "Node.js is..."
}

This is where RunnablePassthrough becomes useful.

In this article, you'll learn:

  • What RunnablePassthrough is

  • Why we need it

  • How it works

  • RunnablePassthrough with RunnableParallel

  • RunnablePassthrough with RunnableSequence

  • Preserving original input

  • Combining original and generated data

  • RunnablePassthrough.assign()

  • OpenAI examples

  • Gemini examples

  • Real-world use cases

  • Difference between RunnablePassthrough and RunnableLambda

  • Difference between RunnablePassthrough and RunnableParallel

  • Best practices

  • Common mistakes

Let's get started.


What is RunnablePassthrough?

RunnablePassthrough is a Runnable that simply returns the input it receives.

In other words:

Input

↓

RunnablePassthrough

↓

Same Input

For example:

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

const passthrough =
  new RunnablePassthrough();

const result =
  await passthrough.invoke(
    "Hello LangChain"
  );

console.log(result);

Output:

Hello LangChain

Nothing was changed.

The input was simply passed through.


Why Do We Need RunnablePassthrough?

At first, RunnablePassthrough might seem unnecessary.

You might ask:

Why do we need a Runnable that does nothing?

The answer becomes clear when we start combining Runnables.

Consider this workflow:

Input
  │
  ├──→ Original Input
  │
  └──→ AI Model

We want both results.

Without RunnablePassthrough, we would need to manually preserve the original input.

With RunnablePassthrough, we can tell LangChain:

"Keep this input exactly as it is."


Simple Example

Let's start with a very simple example.

const passthrough =
  new RunnablePassthrough();

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

console.log(result);

Output:

{
  topic: "Node.js",
  level: "beginner"
}

The object remains unchanged.


RunnablePassthrough with a String

It works with strings too.

const result =
  await passthrough.invoke(
    "Node.js"
  );

console.log(result);

Output:

Node.js

RunnablePassthrough with Numbers

It can also pass primitive values.

const result =
  await passthrough.invoke(100);

console.log(result);

Output:

100

The important idea is:

RunnablePassthrough preserves whatever input it receives.


RunnablePassthrough with RunnableParallel

This is where RunnablePassthrough becomes much more useful.

Suppose we have:

const parallel =
  RunnableParallel.from({
    original: new RunnablePassthrough(),

    uppercase: new RunnableLambda({
      func: (text) =>
        text.toUpperCase(),
    }),
  });

Now invoke:

const result =
  await parallel.invoke(
    "Node.js"
  );

console.log(result);

Output:

{
  original: "Node.js",
  uppercase: "NODE.JS"
}

Understanding the Flow

The same input goes into both branches:

                    ┌──→ Passthrough ──→ "Node.js"
                    │
"Node.js" ──────────┤
                    │
                    └──→ Uppercase ────→ "NODE.JS"

The final result is:

{
  original: "Node.js",
  uppercase: "NODE.JS"
}

This is one of the most common patterns for RunnablePassthrough.


Why Is This Useful?

Imagine an AI application where you need:

  • The original question

  • The AI answer

You don't want the original question to disappear after sending it to the model.

Instead, you want:

{
  question: "...",
  answer: "..."
}

RunnablePassthrough helps you preserve that original value.


OpenAI Example

Let's build a practical example using OpenAI.

First, install the packages:

npm install @langchain/core @langchain/openai dotenv

Create the model:

import "dotenv/config";

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

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

Create a prompt:

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

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

Add a parser:

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

const parser =
  new StringOutputParser();

Now create an answer chain:

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

Now combine it with RunnablePassthrough.

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

const chain =
  RunnableParallel.from({
    question:
      new RunnablePassthrough(),

    answer: answerChain,
  });

Invoke:

const result =
  await chain.invoke({
    question:
      "What is Node.js?",
  });

console.log(result);

The output will have this structure:

{
  question: {
    question: "What is Node.js?"
  },

  answer: "Node.js is a JavaScript runtime..."
}

Notice something important.

Because the entire input is an object:

{
  question: "What is Node.js?"
}

RunnablePassthrough returns that entire object.

If we want only the question string, we need to structure the workflow accordingly.


Passing the Original String

A simpler version is to pass the question directly as a string.

Change the prompt:

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

Create a small preparation step:

const answerChain =
  new RunnableLambda({
    func: (topic) => ({
      topic,
    }),
  })
  .pipe(prompt)
  .pipe(model)
  .pipe(parser);

Then:

const chain =
  RunnableParallel.from({
    topic:
      new RunnablePassthrough(),

    answer: answerChain,
  });

Invoke:

const result =
  await chain.invoke(
    "Node.js"
  );

console.log(result);

Output:

{
  topic: "Node.js",
  answer: "Node.js is a JavaScript runtime..."
}

Now we have exactly what we wanted:

Original Input
     │
     ├──→ topic
     │
     └──→ answerChain

Gemini Example

The same pattern works with Gemini.

Initialize Gemini:

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

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

Create the answer chain:

const answerChain =
  new RunnableLambda({
    func: (topic) => ({
      topic,
    }),
  })
  .pipe(prompt)
  .pipe(geminiModel)
  .pipe(parser);

Then:

const chain =
  RunnableParallel.from({
    topic:
      new RunnablePassthrough(),

    answer: answerChain,
  });

Invoke:

const result =
  await chain.invoke(
    "React"
  );

console.log(result);

Output:

{
  topic: "React",
  answer: "React is a JavaScript library..."
}

Again, the workflow stays the same.

Only the model changes.


RunnablePassthrough with Objects

Let's look at a more realistic example.

Suppose the application receives:

const input = {
  topic: "Node.js",
  level: "beginner",
};

We want to preserve the original input while generating an explanation.

const chain =
  RunnableParallel.from({
    original:
      new RunnablePassthrough(),

    explanation:
      explanationChain,
  });

Invoke:

const result =
  await chain.invoke(input);

Output:

{
  original: {
    topic: "Node.js",
    level: "beginner"
  },

  explanation: "Node.js is..."
}

This is useful when later parts of your application need access to both the original request and the generated result.


RunnablePassthrough.assign()

Another useful feature is:

RunnablePassthrough.assign()

This allows you to preserve an object while adding new fields to it.

Think about it like this:

Original Object

↓

Add New Field

↓

Updated Object

For example:

const chain =
  RunnablePassthrough.assign({
    name: new RunnableLambda({
      func: (data) =>
        data.firstName +
        " " +
        data.lastName,
    }),
  });

Input:

{
  firstName: "John",
  lastName: "Doe"
}

Output:

{
  firstName: "John",
  lastName: "Doe",
  name: "John Doe"
}

The original fields are preserved.

The new field is added.


Understanding assign()

This distinction is important.

RunnablePassthrough

Returns the input:

Input

↓

Same Input

RunnablePassthrough.assign()

Preserves an object and adds new keys:

Original Object

↓

Add Fields

↓

Original + New Fields

Example with AI

Suppose we have:

const input = {
  topic: "Node.js",
};

We want to add an AI-generated summary.

We can use:

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

Then:

const chain =
  RunnablePassthrough.assign({
    summary:
      summaryChain,
  });

Invoke:

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

Conceptually, the result becomes:

{
  topic: "Node.js",
  summary: "Node.js is..."
}

This pattern is extremely useful for enriching existing data.


RunnablePassthrough.assign() with Multiple Fields

You can add multiple fields.

const chain =
  RunnablePassthrough.assign({
    summary: summaryChain,

    keywords: keywordChain,

    questions: questionChain,
  });

Input:

{
  topic: "React"
}

Output:

{
  topic: "React",
  summary: "...",
  keywords: "...",
  questions: "..."
}

This creates an enriched object.


A Practical AI Example

Let's imagine we're building an article analyzer.

Input:

{
  title: "Understanding Node.js Streams",
  content: "..."
}

We want to add:

  • Summary

  • Keywords

  • Difficulty

The workflow can look like:

Article Object
      │
      ▼
RunnablePassthrough.assign()
      │
      ├──→ summary
      │
      ├──→ keywords
      │
      └──→ difficulty
      │
      ▼
Enriched Article Object

The original article data is preserved.

AI-generated information is added.


RunnablePassthrough vs RunnableLambda

These two are easy to confuse.

RunnablePassthrough

Does not transform the input.

const passthrough =
  new RunnablePassthrough();

Input:

"Node.js"

Output:

"Node.js"

RunnableLambda

Transforms or processes the input.

const uppercase =
  new RunnableLambda({
    func: (text) =>
      text.toUpperCase(),
  });

Input:

"Node.js"

Output:

"NODE.JS"

RunnablePassthrough vs RunnableParallel

These are also different concepts.

RunnablePassthrough

One input goes through unchanged:

Input
  ↓
Passthrough
  ↓
Same Input

RunnableParallel

One input is sent to multiple branches:

             ┌──→ Branch A
             │
Input ───────┼──→ Branch B
             │
             └──→ Branch C

However, RunnablePassthrough is commonly used inside RunnableParallel to preserve the original input while other branches process it.


RunnablePassthrough + RunnableParallel

This combination is very common.

Consider:

const chain =
  RunnableParallel.from({
    original:
      new RunnablePassthrough(),

    processed:
      processingChain,
  });

The workflow:

                   ┌──→ Original
                   │
Input ─────────────┤
                   │
                   └──→ Processed

Output:

{
  original: "...",
  processed: "..."
}

RunnablePassthrough + RunnableSequence

Because RunnablePassthrough is a Runnable, it can also appear inside a sequence.

For example:

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

The final Runnable simply passes the result forward.

While this example is not particularly useful by itself, it demonstrates an important principle:

RunnablePassthrough can participate anywhere a Runnable is expected.


Real-World Example: Question and Answer

One common pattern is keeping the user's question together with the generated answer.

User Question
      │
      ├──────────────→ Original Question
      │
      └──────────────→ AI Model
                           │
                           ▼
                         Answer

Final result:

{
  question: "What is React?",
  answer: "React is a JavaScript library..."
}

This is useful for:

  • Chat history

  • Logging

  • Analytics

  • UI rendering

  • Saving conversations

  • Evaluation


Real-World Example: RAG Applications

RunnablePassthrough becomes particularly useful in Retrieval-Augmented Generation (RAG).

A simplified RAG workflow looks like:

User Question
      │
      ├──────────────→ Question
      │
      └──→ Retriever
              │
              ▼
          Documents
              │
              ▼
            Prompt
              │
              ▼
             LLM

The prompt may need both:

  • The original question

  • Retrieved documents

Conceptually:

{
  question: originalQuestion,
  context: retrievedDocuments
}

RunnablePassthrough can preserve the original question while another branch retrieves the context.

This pattern will become especially useful when we cover RAG later in the series.


Real-World Example: Document Processing

Imagine an application that receives:

{
  documentId: "DOC-101",
  content: "..."
}

You want to:

  • Preserve the document ID.

  • Generate a summary.

  • Extract keywords.

The workflow:

                    ┌──→ documentId
                    │
Document ───────────┼──→ Summary
                    │
                    └──→ Keywords

You can preserve the original data while adding AI-generated fields.


Real-World Example: AI Evaluation

Suppose you're evaluating an AI response.

You have:

{
  question: "Explain closures",
  answer: "..."
}

You can preserve the original response while running multiple evaluation branches:

                  ┌──→ Correctness
                  │
Input ────────────┼──→ Relevance
                  │
                  └──→ Quality

The original input can be retained alongside the evaluation results.


Complete OpenAI Example

Let's put the concepts together.

import "dotenv/config";

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

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

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

import {
  RunnableLambda,
  RunnableParallel,
  RunnablePassthrough,
} from "@langchain/core/runnables";

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

const parser =
  new StringOutputParser();

const prepareTopic =
  new RunnableLambda({
    func: (topic) => ({
      topic: topic.trim(),
    }),
  });

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

const answerChain =
  prepareTopic
    .pipe(prompt)
    .pipe(model)
    .pipe(parser);

const chain =
  RunnableParallel.from({
    topic:
      new RunnablePassthrough(),

    answer: answerChain,
  });

const result =
  await chain.invoke(
    "  Node.js Streams  "
  );

console.log(result);

The workflow:

                     ┌──→ Original Topic
                     │
"Node.js Streams" ───┤
                     │
                     └──→ Prepare
                           ↓
                         Prompt
                           ↓
                         OpenAI
                           ↓
                         Parser
                           ↓
                         Answer

Final result:

{
  topic: "Node.js Streams",

  answer:
    "Node.js streams allow..."
}

Complete Gemini Example

The same architecture works with Gemini.

Replace the model:

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

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

The rest of the workflow can remain the same.

const answerChain =
  prepareTopic
    .pipe(prompt)
    .pipe(model)
    .pipe(parser);

const chain =
  RunnableParallel.from({
    topic:
      new RunnablePassthrough(),

    answer: answerChain,
  });

const result =
  await chain.invoke(
    "React Hooks"
  );

console.log(result);

This is another example of why the Runnable architecture is so useful.

The workflow is independent of the model provider.


Best Practices

1. Use Passthrough when you genuinely need the original value

Don't add it just because it exists.

Use it when preserving the input has a purpose.


2. Use assign() when enriching objects

If you have an object and want to add computed or AI-generated fields:

RunnablePassthrough.assign({
  summary: summaryChain,
});

is often a clean pattern.


3. Use meaningful property names

Prefer:

{
  question: new RunnablePassthrough(),
  answer: answerChain,
}

instead of:

{
  a: new RunnablePassthrough(),
  b: answerChain,
}

4. Keep the data shape predictable

Know what each Runnable receives and returns.

This becomes especially important in larger workflows.


5. Combine Passthrough with Parallel thoughtfully

This is one of its strongest use cases:

Input
 ├──→ Original
 └──→ Processing

Common Beginner Mistakes

Mistake 1: Expecting RunnablePassthrough to transform data

It doesn't.

new RunnablePassthrough()

simply returns the input.

If you need transformation, use RunnableLambda.


Mistake 2: Confusing assign() with normal Passthrough

This:

new RunnablePassthrough()

returns the input.

Whereas:

RunnablePassthrough.assign({
  summary: summaryChain,
})

preserves an object and adds a new field.


Mistake 3: Passing an object when you expected a property

Suppose:

const input = {
  question: "What is Node.js?"
};

A normal RunnablePassthrough receives the entire object.

It does not automatically extract:

"What is Node.js?"

If you need a specific property, explicitly transform the input.

For example:

const getQuestion =
  new RunnableLambda({
    func: (data) =>
      data.question,
  });

Mistake 4: Using Passthrough unnecessarily

If you don't need the original input later, there may be no reason to preserve it.

Keep workflows simple.


The Bigger Picture

At this point, we've learned several Runnable building blocks.

RunnableSequence

For sequential workflows:

A
↓
B
↓
C

RunnableParallel

For independent workflows:

    ┌→ A
Input
    ├→ B
    └→ C

RunnableLambda

For custom JavaScript logic:

Input
 ↓
Custom Function
 ↓
Output

RunnablePassthrough

For preserving input:

Input
 ↓
Same Input

And these components can be combined.

For example:

                 ┌──→ Original Input
                 │
Input
 ↓
Sequence
 ↓
Parallel
 ├──→ OpenAI
 ├──→ Gemini
 └──→ Custom Logic

This is the foundation for building more sophisticated LangChain workflows.


What's Next?

So far, our workflows have followed a predictable path.

But real applications often need conditional logic.

For example:

User Input
    ↓
Is it a technical question?
    │
    ├── Yes → Technical AI Chain
    │
    └── No  → General AI Chain

Or:

Score
  ↓
Is score > 80?
  │
  ├── Yes → Advanced Response
  │
  └── No  → Beginner Response

We don't always want every input to follow the same path.

This is where RunnableBranch becomes useful.

In the next article, we'll learn:

Mastering RunnableBranch in LangChain.js: Build Conditional AI Workflows (OpenAI + Gemini)


Final Thoughts

RunnablePassthrough is a small but extremely useful component in the LangChain Runnable ecosystem.

Its primary job is simple:

Take the input and pass it forward unchanged.

That might sound trivial, but it becomes powerful when combined with other Runnables.

For example:

Input
  │
  ├──→ Original Input
  │
  └──→ AI Processing

or:

Input Object
      ↓
RunnablePassthrough.assign()
      ↓
Original Fields + New Fields

The most important distinction to remember is:

RunnablePassthrough
        ↓
Preserve

while:

RunnableLambda
        ↓
Transform

Once you understand this difference, you'll be able to design cleaner LangChain workflows where original data, transformed data, and AI-generated data can coexist without unnecessary manual data handling.

And when we move into RAG, conditional workflows, and more advanced AI pipelines, RunnablePassthrough will become even more useful.

Happy Coding! 🚀