Course Content
LangChain Mastery
7 sections · 109 lessons
What is the difference between LLMChain and SequentialChain?
What you need to know
In the 2023 API, everything was a Chain subclass with input_keys and output_keys. These two were the most common.
LLMChain | SequentialChain | |
|---|---|---|
| Role | one prompt → one call | runs several chains in order |
| LLM calls | one | one per sub-chain |
| Config | llm, prompt, output_key | chains, input_variables, output_variables |
| Output | {"text": ...} or the output_key | a dict of the chosen output variables |
| LCEL replacement | prompt | llm | parser | chain_a | chain_b, or RunnablePassthrough.assign |
| Import today | langchain_classic.chains | langchain_classic.chains |
The key mapping, then and now
SequentialChain matched keys by name: if c1 had output_key="summary" and c2's prompt used {summary}, the value flowed across. LCEL does the same thing explicitly:
1# legacy2seq = SequentialChain(chains=[summary_chain, tweet_chain],3 input_variables=["article"],4 output_variables=["summary", "tweet"])56# current7pipeline = (RunnablePassthrough.assign(summary=summary_prompt | llm | StrOutputParser())8 | RunnablePassthrough.assign(tweet=tweet_prompt | llm | StrOutputParser()))Both return a dict with article, summary and tweet.
Why LCEL replaced them
- Streaming: legacy chains returned the full answer at the end; LCEL streams through every step.
- Parallelism: a dict of Runnables runs at the same time;
SequentialChaincould only run in order. - Consistency: every step is a Runnable with the same methods, instead of each chain class having its own rules.
- Tracing: each step is a separate, named node.
A real-life example
A media company in Mumbai had a 2023 content pipeline: an LLMChain summarised a news article, and a SequentialChain fed the summary into chains that wrote a tweet and a push notification. After moving to LangChain 1.x, the import from langchain.chains import SequentialChain failed. The team first installed langchain-classic as a stop-gap to keep publishing, then rewrote the pipeline in LCEL. Because the tweet and the notification only needed the summary, they ran those two in parallel with RunnableParallel, and time per article fell from about 9 seconds to 6.
Follow-up questions to expect
- "What was
SimpleSequentialChain?" — A restrictedSequentialChainwhere each chain has exactly one input and one output, passed straight on with no key names. - "Will old code still run?" — Yes, with
langchain-classicinstalled and imports changed tolangchain_classic.chains, but plan to migrate before 2.0. - "What did
LLMChain.runreturn?" — A string, whileinvokereturned a dict;runis also deprecated.