Wire the output of one chain into the input of the next — the composition pattern behind any genuinely multi-step LLM pipeline.
1Multi-Step Reasoning Needs Composition
Some tasks genuinely benefit from being broken into stages — extract structured data first, then reason over it, rather than asking a single prompt to do both at once. Sequential chaining is the mechanism that makes that decomposition practical: each stage stays simple and independently testable, while the pipeline as a whole handles the full task.
2The Loop Is the Entire Mechanism
There's no hidden magic in sequential chaining — it's a plain for loop threading one variable through each step. That simplicity is a feature: because it's just Python control flow, it's trivial to reason about, debug (print the intermediate value between steps), and extend with additional chains.
3Step-by-Step Breakdown
A single chain handles one step. Real reasoning is often multi-step: extract a keyword, THEN write about it. LangChain's SimpleSequentialChain wires multiple chains together so the output of one becomes the input to the next, automatically.
The mechanism is a simple loop: start with the initial input, then for each chain in sequence, run it and let its output become the next chain's input. Whatever comes out of the last chain is the final result.
Build SimpleSequentialChain Yourself. extract_chain pulls out a keyword; tweet_chain writes about whatever keyword it's given. Finish SimpleSequentialChain.invoke(): run each chain on the current value, in order, and feed each result forward as the next chain's input.
In a SimpleSequentialChain with 3 chains, what is passed as the input to the third chain?
- →The output of the second chain — each chain's output becomes the next chain's input, not the original initial_input.
- →The original initial_input, unchanged, passed to every chain in the sequence.
You've now built two different chain composition styles. Modern LangChain expresses this same idea more elegantly with LCEL — the pipe operator. Next lesson builds that operator overload yourself.
Level Up 🚀
Advanced cheat sheets, SEO tricks, and interview prep for this topic.
Browser Support
Fully supported.
Fully supported.
Fully supported.
Fully supported.
Accessibility (A11y)
1Log Each Intermediate Step's Output During Debugging
When a sequential chain produces an unexpected final result, log or expose each intermediate step's output (not just the final one) so developers debugging via logs or assistive tooling can pinpoint exactly which stage introduced the problem.
print(f'Step {i} output: {current}')SEO Implications
- 1
Target 'LangChain SimpleSequentialChain example' as a distinct search
Developers specifically search for the sequential composition pattern once a single chain isn't enough for their multi-step task.
Best Practices
Keep Each Chain in a Sequence Focused on One Sub-Task
A sequential chain's value comes from each step being simple and independently testable — resist the temptation to cram multiple concerns into one chain within the sequence, which defeats the purpose of decomposing the task.
Frequent Bugs
A chain in the middle of a sequence expects a differently-shaped input than the previous chain's output actually produces.
Explicitly test each chain in isolation with representative inputs before composing them into a sequence, and verify each chain's output shape matches what the next chain in line expects.
Real-World Examples
Extract-Then-Draft Pipeline
A content pipeline extracts a topic keyword from raw research notes with one chain, then drafts social copy about that keyword with a second chain — exactly the two-stage pipeline you just built, now applied to a real content workflow.
pipeline = SimpleSequentialChain(chains=[extract_chain, draft_chain])