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