Course contentsShow
← AI Engineering
Lesson 508 of 1,88613. LLM Orchestration FrameworksFree lesson

RunnablePassthrough and RunnableParallel

Managing data flow in chains with pass-through operations and executing multiple branches in parallel.

RunnablePassthrough and RunnableParallel

What You'll Learn

You'll learn how to pass data through chains unchanged and execute multiple operations simultaneously using LangChain's building blocks.

The Core Idea

When building chains with LCEL, you often need to:

  1. Pass data forward unchanged (like passing ingredients through a recipe step without modification)
  2. Do multiple things at once (like chopping vegetables while boiling water)

RunnablePassthrough lets you forward input directly to the next step. Think of it as a "transparent pipe" — data flows through without transformation. This is crucial when you need the original input alongside processed results.

RunnableParallel executes multiple runnables simultaneously with the same input, returning a dictionary of all results. It's like delegating tasks to different team members who work independently and report back.

How They Work Together

from langchain_core.runnables import RunnablePassthrough, RunnableParallel

# Pass input through unchanged
chain = RunnablePassthrough() | some_processing_step

# Execute multiple operations in parallel
parallel_chain = RunnableParallel(
    original=RunnablePassthrough(),
    processed=some_llm_chain,
    metadata=some_metadata_extractor
)

The parallel chain receives one input but produces a dictionary with three keys: original (unchanged input), processed (LLM output), and metadata (extracted metadata).

Common Use Case

Often you'll combine both: pass original context through while also processing it, then merge results downstream:

chain = RunnableParallel(
    context=RunnablePassthrough(),
    answer=prompt | llm
)

This pattern is essential for RAG, where you need both the original context AND the generated answer.

Key Takeaway: RunnablePassthrough preserves data flow, while RunnableParallel enables concurrent operations — together they give you fine-grained control over how data moves through your chains.