Understanding LangChain Legacy Chains (LLMChain, SequentialChain, and More)
When I first started tinkering with LangChain last year, I quickly ran into a wall. Most tutorials and examples online had already migrated…
Understanding LangChain Legacy Chains (LLMChain, SequentialChain, and More)
Photo Lang chain
When I first started tinkering with **LangChain last year, I quickly ran into a wall. Most tutorials and examples online had already migrated to the new LangChain Expression Language (LCEL)**, but many of the projects I needed to maintain were written using an older syntax.
As it turns out, prior to August 2023 **LangChain used a different way of composing pipelines of large‑language‑model ([LLM](https://medium.com/nextgenllm/introduction-to-ai-agents-from-perception-reason-action-to-llm-powered-systems-f736e025537a)**) calls.
Those older patterns are still referred to as legacy chains, and not all of them have been replaced by LCEL variants.
I decided to dig into the legacy syntax, not because I love nostalgia, but because real‑world codebases rarely upgrade overnight.
Understanding how the older syntax works makes it easier to maintain existing systems and to migrate them to LCEL when the time is right.
This article is a human‑centred walkthrough of what the legacy syntax is, why it still matters, and how to work with it today.
Why Care About Legacy Syntax about Lang Chain?

Langchain
Short answer: because legacy code doesn’t disappear just because a new API exists. LangChain’s developers introduced LCEL to provide a more flexible and declarative way of building chains, but many examples on GitHub and in older tutorials still rely on the original classes.
Some legacy chains also remain the only implementation of certain features. Until LCEL covers every use case, legacy syntax is a practical reality for engineers maintaining production systems.
What Is a Chain?
Before diving into legacy versus LCEL, it helps to understand what LangChain calls a chain.
A chain is simply a sequence or pipeline of steps. Each step can be a call to an **LLM**, a tool, a retriever or a preprocessing operation.
The output of one step becomes the input to the next. In code, this idea is encoded as a class that takes a prompt, an LLM and perhaps other components, and then exposes a method to run the entire pipeline.
What Makes a Chain “Legacy”?
Legacy chains are built by subclassing LangChain’s original Chain classes rather than using LCEL.
They don’t use the expression language and instead rely on Python classes with bespoke logic.
Many of these classes are being deprecated, so keeping track of LangChain release notes and documentation is essential.
That said, some features still only exist in their legacy form, so it’s worth knowing how they work.
A Tour of Popular Legacy Chains
While there are dozens of chain types, a few appear in most legacy examples. Here is a brief overview:
- LLMChain — the simplest chain: it passes a query or prompt to an LLM and returns the response.
- SequentialChain — connects multiple chains in sequence so that the output of one feeds into the next.
- LLMRouterChain — uses a router LLM to decide which child chain should handle a given prompt.
- RetrievalQA — attaches a vector‑database retriever to an LLM to build a retrieval‑augmented generation (RAG) pipeline.
- ConversationChain — stores past messages in memory so you can have a multi‑turn conversation with a model.
- ConversationalRetrievalChain — combines conversation memory with RAG, enabling chat on top of custom data.
These patterns solve common problems — passing user queries to a model, chaining multiple models together, routing tasks to specialised chains, retrieving context from external sources, and handling conversational state. Understanding them helps you read and maintain older codebases.
Example: Building an LLMChain by Hand
To see how the legacy syntax looks in practice, let’s build the simplest chain — an LLMChain.
This chain takes a user query, wraps it in a prompt, and feeds it to an LLM.
Here’s a fully self‑contained example written using the pre‑LCEL API:
from langchain_openai import ChatOpenAI
from langchain.chains import LLMChain
from langchain_core.prompts import ChatPromptTemplate
# Connect to ChatGPT via the OpenAI wrapper
chatgpt = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0)
# Define a prompt template that accepts a variable named {query}
prompt_txt = "{query}"
prompt_template = ChatPromptTemplate.from_template(prompt_txt)
# Create a chain by binding the LLM and the prompt template
llmchain = LLMChain(llm=chatgpt, prompt=prompt_template)
# Invoke the chain with a dictionary of input variables
response = llmchain.invoke({"query": "Explain Generative AI in one line"})
print(response["text"])
This script connects to ChatGPT (via the ChatOpenAI wrapper), defines a simple prompt template with a single variable, binds it to an LLMChain, and invokes the chain with a query.
The response is a dictionary whose "text" field contains the answer generated by the model.
Although LCEL would let you write this more declaratively, the legacy approach is explicit and easy to follow.
Final Thoughts:
Photo Lang chain
LangChain’s legacy syntax may feel dated compared to LCEL, but it’s still alive in many codebases.
As long as there are production systems that depend on legacy chains or features not yet migrated, engineers need to understand how these classes work.
The basic concepts a chain as a pipeline of steps, and specific chain classes for routing, retrieval and conversation remain central to the framework, even if the implementation details evolve.
By learning how to read and write legacy chains, you gain the confidence to maintain existing applications and the context to appreciate the improvements brought by LCEL.
메타데이터
- post_id
- cfe4b43ea45f
- slug
- understanding-langchain-legacy-chains-llmchain-sequentialchain-and-more-cfe4b43ea45f
- url
- https://medium.com/nextgenllm/understanding-langchain-legacy-chains-llmchain-sequentialchain-and-more-cfe4b43ea45f
- canonical_url
- https://medium.com/nextgenllm/understanding-langchain-legacy-chains-llmchain-sequentialchain-and-more-cfe4b43ea45f
- author_url
- https://medium.com/@premvishnoi
- status
- ok
- fetched_at
- 2026-06-10 22:22:12