RunnableParallel
Sequential chains run steps in a line — step 2 waits for step 1. RunnableParallel runs two branches on the same input and returns a dict: result['purpose'], result['example']. Both branches take {tag} and answer different questions about the HTML tag.
Split and merge
Same {"tag": "a"} goes to purpose_chain and example_chain. When both finish, invoke returns {"purpose": "…", "example": "…"}.
One input splits into parallel branches, then merges:
branch 1
purpose_chainbranch 2
example_chainCompared to sequential chains
Simple Sequential Chains when step 2 needs step 1's string. RunnableParallel when both branches only need the original input.
Sequential (one after another)
chain = pick_chain
| explain_prompt
| model | parser
# step 2 waits for step 1Use when step 2 needs step 1 output
RunnableParallel
chain = RunnableParallel(
purpose=purpose_chain,
example=example_chain,
)
# both run on same inputUse when branches are independent
The dict result
Each keyword in RunnableParallel(purpose=…, example=…) becomes a key in the output. Read values with result["purpose"].
One invoke, one dict back
result = chain.invoke({"tag": "a"})
result["purpose"]
# "The <a> tag creates a hyperlink…"
result["example"]
# '<a href="/home">Home</a>'RunnableParallel.A plain dict works the same way — {"purpose": purpose_chain, "example": example_chain}.
What each branch does
purpose_chain— input{tag}, output one-sentence purpose.example_chain— same input, output one line of HTML. System message blocks DOCTYPE, fences, and full pages.
The demo script
runnable_parallel_demo.py runs the chain for a and img.
Download the code
runnable_parallel_demo.py
purpose + example in parallel
langchain-course folder. Needs venv, .env, and packages from Project Setup.Run it
Activate the venv from Project Setup, then:
python runnable_parallel_demo.pyexample should be one line like <a href="/home">Home</a> — not a full HTML page. The system prompt enforces that.When to pick parallel
- Both branches need the same input but not each other's output — purpose + example here.
- You want several answers in one dict from a single
invoke. - Official reference: Parallel runnables.
What's Next
Next: RunnablePassthrough — keep input keys while adding new ones.