Articles → LANGCHAIN → Sequential Chaining In Langchain
Sequential Chaining In Langchain
Purpose
Example
from langchain_core.prompts import PromptTemplate
from langchain_openai import ChatOpenAI
# LLM
llm = ChatOpenAI(
api_key="your_api_key",
model="gpt-4.1-mini",
temperature=0.7
)
# Prompt 1
prompt1 = PromptTemplate.from_template(
"Generate a blog topic about {idea}"
)
# Prompt 2
prompt2 = PromptTemplate.from_template(
"Write an outline for this topic: {topic}"
)
# Chain 1
chain1 = prompt1 | llm
# Chain 2
chain2 = prompt2 | llm
# Combine chains manually
topic_result = chain1.invoke({
"idea": "Artificial Intelligence"
})
topic = topic_result.content
outline_result = chain2.invoke({
"topic": topic
})
print(outline_result.content)
Output
| Posted By - | Karan Gupta |
| |
| Posted On - | Thursday, May 14, 2026 |