Why not one giant prompt?#
Imagine asking:
Read these 200 student feedback comments, find the main problems, rank them,
suggest solutions with costs, write a report for the director and draft an
email to all trainers.
One prompt doing six jobs usually gives a shallow result: some comments ignored, generic solutions, a rushed email. And if one part is wrong, everything after it is wrong too.
Prompt chaining#
Prompt chaining splits the work into a sequence of smaller prompts. Each prompt has one clear job, and its output is passed into the next prompt.
Step 1: Extract → Step 2: Group → Step 3: Analyse → Step 4: Write
Prompt chaining = एक बड़े काम को छोटे-छोटे कदमों में बाँटना, जहाँ एक कदम का नतीजा अगले कदम का input बनता है।
जैसे खाना बनाना: पहले सब्ज़ी काटो → फिर मसाला भूनो → फिर पकाओ → फिर परोसो। अगर सब एक साथ करने की कोशिश करें तो गड़बड़ होगी।
फायदा: हर कदम के बाद आप नतीजा जाँच और सुधार सकते हैं, इसलिए आखिरी नतीजा बहुत बेहतर और भरोसेमंद होता है।
Example: feedback report chain#
Prompt 1 - Extract
Below are student feedback comments. For each comment, extract the main
issue in under 8 words. Return a numbered list.
<comments>
...200 comments...
</comments>
Prompt 2 - Group (paste the list from step 1)
Group these issues into 5-7 themes. For each theme give: theme name,
number of comments, and 2 example issues. Return a table.
<issues>
...output of prompt 1...
</issues>
Prompt 3 - Analyse
For each theme below, suggest one practical solution for a small
institute, estimated cost (low/medium/high) and time to implement.
<themes>
...output of prompt 2...
</themes>
Prompt 4 - Write
Using the analysis below, write a one-page report for the director with:
Summary (3 lines), Top 3 issues, Recommended actions table, Next steps.
<analysis>
...output of prompt 3...
</analysis>
After each step you review the output - fix a wrong grouping in step 2 before it affects the report.
Benefits#
| Benefit | Why |
|---|---|
| Higher quality | Each step gets the model's full attention |
| Easy to debug | You can see exactly which step went wrong |
| Reusable | The same "Extract" step works for other surveys |
| Controllable | You can edit outputs between steps |
| Works with long data | Process data in chunks, then combine |
Common chain patterns#
Research → Outline → Draft → Edit#
1. "List the key points a beginner should know about UPI security."
2. "Create an outline for a 600-word blog post using these points."
3. "Write the post from this outline for college students."
4. "Edit the post: shorten long sentences, add a catchy title, check facts."
Chunk → Summarise → Combine (for long documents)#
Split a long document into parts, summarise each part separately, then summarise the summaries.
Generate → Review → Improve#
Ask for a draft, then ask the model (in a new prompt) to review it against criteria, then to apply the fixes. More on this in the next lesson.
Extract → Transform → Format#
1. Extract dates, amounts and party names from each invoice text.
2. Convert amounts to numbers and dates to YYYY-MM-DD.
3. Output as CSV for Excel.
Automating chains with Python#
When the same chain runs many times, code can pass outputs along automatically. Here ask_ai is a stand-in - in the Using AI APIs lesson you'll replace it with a real API call:
In chat tools, you can chain inside one conversation ("Now take the themes above and..."). For important work, check each step before saying "next". For automation, keep each step's prompt in a separate template.
Summary#
- Prompt chaining breaks a complex task into focused steps; each output feeds the next.
- It improves quality, makes errors visible, and lets you review between steps.
- Common patterns: research → outline → draft → edit; chunk → summarise → combine; extract → transform → format.
- Pass data between steps inside clear tags; automate repeated chains with Python.