LCEL & ChainsLesson 3

Simple Sequential Chains

Sequential Chains kept both tag and explanation for step 2 — that needed RunnablePassthrough.assign. Here step 2 only gets the string from step 1. Pick a tag from a feature name (links a), then explain it. No assign — just more pipes.

Previous output only

Step 1 takes {"feature": "links"} and returns a tag string like "a". Step 2 never sees feature — only that string, passed into {tag}.

A straight line — step 2 never sees the original input:

input

{ feature: "links" }

step 1

pick_chain

string

"a"

step 2

explain

output

explanation

Step 1 returns a plain string ("a"). LangChain passes it to step 2 as {tag} because that is the only variable in the prompt.
Step 2 gets whatever step 1 returned — not the original input dict.

Compared to Sequential Chains

Need the original dict plus a new key? Use assign, as in the previous lesson. Step 2 only needs the last string? Pipe the chains — no extra wiring.

Sequential Chains

# Step 2 needs tag AND explanation
RunnablePassthrough.assign(
    explanation=explain_chain
)
| tip_prompt | model | parser

Keeps original input + adds new keys

Simple Sequential

# Step 2 only needs step 1 output
chain = pick_chain
    | explain_prompt
    | model
    | parser

Previous output flows straight through

Use simple sequential when the next step only needs the last result — not the original input dict.

The chain line

The full chain is one line:

chain = pick_chain | explain_prompt | model | parser

What happens inside one invoke call

you callchain.invoke({"feature": "links"})
pick_chain runs"a"
explain_prompt receives{"tag": "a"}
final output"The <a> tag creates a hyperlink…"
One variable in the prompt ({tag}) — LangChain maps the incoming string to it.

What each step does

  • pick_chain — input {"feature": "links"}, output tag string "a".
  • explain_prompt | model | parser — input that string as {tag}, output the explanation.

The demo script

simple_sequential_chains_demo.py runs the chain for links and images.

simple_sequential_chains_demo.py
"""simple_sequential_chains_demo.py"""
… imports, model, parser …
pick_chain = pick_prompt | model | parser
chain = pick_chain | explain_prompt | model | parser
explanation = chain.invoke({"feature": feature})

Download the code

simple_sequential_chains_demo.py

pick_chain → explain

Download .py
Save into your langchain-course folder. Needs venv, .env, and packages from Project Setup.

Run it

Activate the venv from Project Setup, then:

python simple_sequential_chains_demo.py
PowerShell — (.venv) active
(.venv) PS C:\projects\langchain-course> python simple_sequential_chains_demo.py
Feature: links
Explanation: The <a> tag creates a hyperlink to another page or resource.
Feature: images
Explanation: The <img> tag embeds an image into the page.
One invoke — two model calls under the hood.

When to pick this pattern

  • Step 2 only needs the text step 1 produced — pick tag, then explain, like in this demo.
  • You do not need to keep keys from the original input dict for the second prompt.
  • Official reference: Sequence runnables.

What's Next

Next: Multi-LLM Workflows — use a different model on each step.