LangChain Mastery

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.

LLMChainSequentialChain
Roleone prompt → one callruns several chains in order
LLM callsoneone per sub-chain
Configllm, prompt, output_keychains, input_variables, output_variables
Output{"text": ...} or the output_keya dict of the chosen output variables
LCEL replacementprompt | llm | parserchain_a | chain_b, or RunnablePassthrough.assign
Import todaylangchain_classic.chainslangchain_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:

Python
# legacyseq = SequentialChain(chains=[summary_chain, tweet_chain],                      input_variables=["article"],                      output_variables=["summary", "tweet"])# currentpipeline = (RunnablePassthrough.assign(summary=summary_prompt | llm | StrOutputParser())            | 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; SequentialChain could 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 restricted SequentialChain where each chain has exactly one input and one output, passed straight on with no key names.
  • "Will old code still run?" — Yes, with langchain-classic installed and imports changed to langchain_classic.chains, but plan to migrate before 2.0.
  • "What did LLMChain.run return?" — A string, while invoke returned a dict; run is also deprecated.