Chains 101: Understanding LLMChain and Sequential Chains

Posted on Thu 30 July 2026 in GenAI

If you've poked around LangChain for more than ten minutes, you've hit the word "chain." It's everywhere — and for good reason. Chains are how you turn a raw language model into something that actually does a job.

What a chain is

A chain is a unit of logic that takes an input, does something with it, and returns an output. That "something" usually involves an LLM, but it can also include memory lookups, document retrievals, API calls, or other chains. At its core, a chain is just a pipeline with a clear contract: input in, output out.

LangChain gives you a bunch of built-in chain types. Two of them are worth knowing cold before you touch anything else: LLMChain and SequentialChain.

LLMChain

LLMChain is the baseline. It wires together three things:

  • A prompt template — defines the structure of what you send to the model
  • An LLM — the model that processes the prompt
  • An output parser (optional) — parses the raw text response into something usable
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain_openai import OpenAI

llm = OpenAI(temperature=0.7)

prompt = PromptTemplate(
    input_variables=["topic"],
    template="Explain {topic} in two sentences, like I'm 15."
)

chain = LLMChain(llm=llm, prompt=prompt)
result = chain.run(topic="gradient descent")
print(result)

When you call chain.run(topic="gradient descent"), LangChain fills in the template, sends it to the LLM, and hands you back the response. That's the whole thing. Simple, but it sets the pattern for everything more complex.

The PromptTemplate is where most of the real work happens. You define input_variables — the slots that get filled at runtime — and write the template string around them. The LLM never sees {topic}, it sees the fully-rendered prompt.

Why PromptTemplate matters

You could skip the template and just format strings yourself. But PromptTemplate enforces that the variables you claim exist actually get passed in. If you declare input_variables=["topic"] and forget to pass topic at runtime, you get an explicit error instead of a silent bad output. That matters more as chains get complicated.

SequentialChain

One LLM call is often enough. But a lot of tasks need multiple steps — and the output of step one feeds into step two.

That's what SequentialChain is for. It runs a list of chains in order and threads outputs from earlier steps into the inputs of later ones.

from langchain.chains import LLMChain, SequentialChain
from langchain.prompts import PromptTemplate
from langchain_openai import OpenAI

llm = OpenAI(temperature=0.7)

# Step 1: generate a product name
name_prompt = PromptTemplate(
    input_variables=["product_description"],
    template="Create a short, catchy product name for: {product_description}"
)
name_chain = LLMChain(llm=llm, prompt=name_prompt, output_key="product_name")

# Step 2: write a tagline for that name
tagline_prompt = PromptTemplate(
    input_variables=["product_name"],
    template="Write a one-line marketing tagline for a product called '{product_name}'."
)
tagline_chain = LLMChain(llm=llm, prompt=tagline_prompt, output_key="tagline")

# Wire them together
pipeline = SequentialChain(
    chains=[name_chain, tagline_chain],
    input_variables=["product_description"],
    output_variables=["product_name", "tagline"],
    verbose=True
)

result = pipeline({
    "product_description": "a water bottle that tracks hydration via a smartphone app"
})

print(result["product_name"])
print(result["tagline"])

The key detail: output_key. Every LLMChain in a sequential pipeline needs one, so the next chain in line knows what variable name to pull from. SequentialChain stitches them together automatically — product_description goes into chain one, product_name (the output) becomes the input to chain two.

SimpleSequentialChain vs SequentialChain

LangChain has a simpler version called SimpleSequentialChain. It's fine when each step produces exactly one output and passes it to the next step. There's no naming involved — the output of step N is just the input to step N+1.

SequentialChain is what you want when steps produce multiple outputs, or when later steps need inputs from earlier steps that aren't just the immediate predecessor. The output_key / input_variables system gives you that flexibility.

A quick mental model

Think of it this way: LLMChain is one function call. SequentialChain is a composed pipeline of function calls where outputs flow through as named variables. Once you have that picture, the rest of LangChain's chain ecosystem — RouterChain, TransformChain, retrieval chains — is just variations on the same idea.

Get comfortable with these two first. They cover a surprising number of real use cases on their own.