Lesson 6 of 6·7 min read

Prompt Chaining and Structured Output 🔗

For complex tasks, a single prompt is rarely enough. Prompt chaining breaks large tasks into small steps — and Structured Output makes AI results machine-readable for automation.


🎯 What You'll Learn

  • How prompt chaining makes complex tasks manageable
  • Four proven chaining patterns
  • Structured output for JSON, CSV, and databases
  • How to use Function Calling and JSON Mode

What is Prompt Chaining? ⛓️

📖 Definition: Prompt chaining connects multiple prompts into a workflow, where each step uses the previous result as input. Instead of solving a complex task in one massive prompt, you break it into manageable substeps.

Example: Competitive report in 4 steps

Step 1: "Identify the 5 most important competitors for
[company] in [market] based on: market share, product
offering, pricing model."

Step 2: "Analyze for each identified competitor: strengths,
weaknesses, pricing model, target audience, and current
strategy."

Step 3: "Create a 2x2 positioning matrix based on the
analysis (axes: price and feature depth)."

Step 4: "Formulate 3 strategic recommendations: How can
we differentiate ourselves?"

💡 Tip: Each step in a chain should deliver a clearly verifiable result. Check the result before moving to the next step — catch errors early, not at the end.


Four Chaining Patterns 🧩

PatternDescriptionIdeal ForExample
🔗 SequentialStep by step, linearReports, analysesResearch → Analysis → Recommendation
🌐 Fan-OutOne prompt generates multiple parallel tasksBrainstorming, variants1 briefing → 5 campaign ideas → evaluation
🔽 FilterGenerate → Evaluate → Select bestContent creation10 headlines → evaluate 3 → select 1
VerifyGenerate → Fact-check → CorrectResearch, reportsSummary → Fact check → Final version

Fan-Out example:

Step 1: "Create 5 different campaign concepts for [PRODUCT].
Each concept: name, target audience, core message, channels."

Step 2 (for each concept): "Evaluate concept [N]:
Originality (1-10), Feasibility (1-10), Expected impact."

Step 3: "Select the best concept and create a detailed
implementation plan."

Structured Output 📐

For automation and system integration, you need machine-readable outputs. Modern LLMs like Claude Opus 4.6 and GPT-5 handle JSON output reliably.

Analyze the following customer review and return the result
as valid JSON. No explanatory text, only JSON.

{
  "sentiment": "positive" | "neutral" | "negative",
  "score": 1-10,
  "topics": ["string", "string"],
  "urgency": 1-5,
  "summary": "string (max 50 words)",
  "recommended_action": "string"
}

Review: [INSERT TEXT]

📖 Definition: JSON Mode is a feature of modern APIs (Claude, GPT-5) that guarantees the model outputs only valid JSON. This prevents parsing errors in your automations.


Function Calling: AI Meets Action 🤖

The latest development in AI automation: Function Calling allows the model to invoke predefined functions — e.g., "Create a calendar event" or "Send an email."

FeatureWhat It DoesAvailable In
JSON ModeGuarantees valid JSON outputClaude API, OpenAI API
Function CallingModel calls predefined functionsClaude API, OpenAI API
Tool UseModel uses external tools (web, DB, APIs)Claude, GPT-5
Example: Function Calling for ticket creation

Functions:
- create_ticket(title, priority, assignee, description)
- send_notification(recipient, message)

Prompt: "The customer reported that the login page isn't
loading. Create a ticket and notify the development team."

→ AI calls create_ticket() and send_notification()

⚠️ Caution: Function Calling is powerful but requires careful permission control. Define exactly which functions the AI may call, and implement confirmation for critical actions.


Practice: Automated Workflows 🔄

Combine chaining + structured output for fully automated workflows:

  • 📧 Email triage: Incoming emails → AI classifies (JSON) → Automatic routing
  • 🎫 Support tickets: Customer inquiry → AI categorizes + prioritizes → Ticket created
  • 📝 Content pipeline: Briefing → AI generates draft → Review → CMS upload
  • 📊 Reporting: Data export → AI analyzes → Dashboard update

🏢 Real-world example: An e-commerce company automated product review analysis: New reviews are sent to Claude via API, classified as JSON (sentiment, topics, urgency), and automatically fed into the CRM. 500 reviews/day processed in seconds.


📋 Summary

  • Prompt chaining breaks complex tasks into manageable steps
  • Four patterns: Sequential, Fan-Out, Filter, Verify
  • Structured output (JSON) makes AI results machine-readable
  • JSON Mode and Function Calling enable real automation
  • Check each step individually before moving to the next

🎯 Exercise: Create a 3-step prompt chain for a recurring task from your daily work. Bonus: Define the last step's output as a JSON schema.


Congratulations! You've completed the "Prompt Engineering" course. In the next course, you'll discover the best AI tools for your daily work.