ASAmol Shukla
Projects
Courses
Prompts
Skills
Contact
Resume
Course Outline
Syllabus Overview

Complete Prompt Engineering Course: From Basics to Mastery

Courses/Complete Prompt Engineering Course: From Basics to Mastery/Lesson 3: Structured Outputs & Prompt Templates
45 mins lesson duration•9 mins read

Lesson 3: Structured Outputs & Prompt Templates

Master techniques for getting consistent, structured outputs and building reusable prompt templates.

Getting Structured Outputs

One of the biggest challenges in prompt engineering is getting outputs in a consistent, usable format. Here are techniques to ensure you always get what you need.

1. Explicit Format Instructions

Tell the model exactly what format you want.

Example:

Analyze this customer feedback and return the result as JSON with the following structure:
{
  "sentiment": "positive" | "negative" | "neutral",
  "key_themes": ["theme1", "theme2"],
  "urgency": "high" | "medium" | "low",
  "suggested_response": "string"
}

Customer feedback: "Your product broke after 2 days and support hasn't responded!"

Result:

{
  "sentiment": "negative",
  "key_themes": ["product quality", "customer support"],
  "urgency": "high",
  "suggested_response": "I sincerely apologize for the product issue and delayed response. Let me prioritize your case and arrange a replacement immediately."
}

2. Markdown Tables

Use markdown tables for comparative or structured data.

Example:

Compare React and Vue.js in a markdown table with these columns:
| Feature | React | Vue.js |
|---|---|---|
| Learning Curve | | |
| Performance | | |
| Ecosystem | | |
| Use Cases | | |

Then provide a recommendation based on the comparison.

3. XML Tags for Structure

Use XML-like tags to separate different parts of your output.

Example:

Write a blog post about AI in healthcare.

<outline>
[Provide a structured outline]
</outline>

<introduction>
[Write the introduction]
</introduction>

<body>
[Write the main content]
</body>

<conclusion>
[Write the conclusion]
</conclusion>

Building Reusable Prompt Templates

A prompt template is a reusable framework that you can fill in with different variables.

Template Structure

You are a [ROLE] with expertise in [DOMAIN].

TASK: [SPECIFIC_TASK]

CONTEXT:
- [Context point 1]
- [Context point 2]
- [Context point 3]

REQUIREMENTS:
1. [Requirement 1]
2. [Requirement 2]
3. [Requirement 3]

OUTPUT FORMAT:
[Desired format description]

EXAMPLE:
[Example of expected output]

Example: Content Creation Template

You are a content marketing specialist with expertise in [INDUSTRY].

TASK: Create a [CONTENT_TYPE] about [TOPIC].

CONTEXT:
- Target audience: [AUDIENCE_DESCRIPTION]
- Brand voice: [TONE_AND_STYLE]
- Key message: [MAIN_POINT]
- Competitor examples: [COMPETITOR_CONTENT_LINKS]

REQUIREMENTS:
1. Headline that hooks readers in under 10 words
2. Introduction that identifies the reader's pain point
3. 3-5 actionable tips with examples
4. Conclusion with clear call-to-action
5. SEO-optimized for keyword: [TARGET_KEYWORD]

OUTPUT FORMAT:
- Title: [H1 headline]
- Meta description: [150-160 characters]
- Body: [Structured with H2s, bullet points, and short paragraphs]
- CTA: [Specific action for readers]

EXAMPLE OUTPUT STRUCTURE:
Title: "10 Proven Ways to Boost Email Open Rates in 2026"
Meta: "Discover 10 actionable strategies to increase your email open rates by 40%..."
[Body content]
CTA: "Download our free email marketing checklist..."

Example: Data Analysis Template

You are a data analyst specializing in [ANALYSIS_TYPE].

TASK: Analyze the following data and provide insights.

DATA:
[Insert data here — CSV, JSON, or description]

ANALYSIS REQUIREMENTS:
1. Summary statistics (mean, median, mode, std dev)
2. Key trends and patterns
3. Anomalies or outliers
4. Correlations between variables
5. Actionable recommendations

OUTPUT FORMAT:
- Executive Summary (2-3 sentences)
- Key Findings (bullet points)
- Detailed Analysis (with charts described)
- Recommendations (numbered list with expected impact)

The DELIMITER Technique

Use clear delimiters to separate different parts of your prompt.

Delimiter Best For
``` Code blocks, long examples
--- Separating sections
### Headings within prompts
""" Multi-line strings
XML tags Complex nested structures

Example with delimiters:

Classify the following text into categories.

---
Text 1: "The weather is beautiful today" → Category: Weather
Text 2: "Apple released a new iPhone" → Category: Technology
Text 3: "The stock market crashed" → Category: Finance
---

Text to classify: "The new AI model achieves human-level performance"

Common Mistakes to Avoid

  • Mistake: Not specifying output format — Fix: Always tell the model what format you want.
  • Mistake: Overly complex templates — Fix: Keep templates simple and easy to fill in.
  • Mistake: Not including examples of desired format — Fix: Show exactly what the output should look like.
  • Mistake: Ignoring token limits — Fix: Long templates may exceed context windows.

Professional Tips & Tricks

  • Create a library of templates for your most common tasks.
  • Use JSON mode when available for guaranteed valid JSON.
  • Test templates with edge cases — unusual inputs often break formats.
  • Version control your templates — track what works and what doesn't.

Key Takeaways

  • Explicit format instructions ensure consistent outputs.
  • Markdown tables, XML tags, and JSON are powerful formatting tools.
  • Prompt templates save time and ensure consistency across uses.
  • Always include an example of the desired output format.
  • Test templates with diverse inputs to ensure robustness.

Next up: Advanced prompt patterns — self-reflection, role-playing, and iterative refinement.

Interactive Lesson Code Snippet
# Structured Output Templates

## JSON Output Template
"Analyze the following and return as JSON:
{
  "analysis": {
    "summary": "string",
    "key_findings": ["string"],
    "recommendations": ["string"],
    "confidence": "high" | "medium" | "low"
  }
}

Input: [Your data here]"

## Markdown Table Template
"Compare [ITEM_1] and [ITEM_2] in a table:

| Aspect | [ITEM_1] | [ITEM_2] |
|--------|----------|----------|
| [Aspect 1] | | |
| [Aspect 2] | | |
| [Aspect 3] | | |

Then provide a recommendation."

## Reusable Template Framework

### Content Creation Template
ROLE: You are a [EXPERTISE] specializing in [DOMAIN].

TASK: Create [CONTENT_TYPE] about [TOPIC].

CONTEXT:
- Audience: [AUDIENCE]
- Tone: [TONE]
- Goal: [GOAL]

FORMAT:
- Structure: [OUTLINE]
- Length: [WORD_COUNT]
- Style: [STYLE_GUIDE]

### Data Analysis Template
ROLE: You are a [ANALYSIS_TYPE] analyst.

TASK: Analyze [DATA_DESCRIPTION].

DATA:
[DATA_HERE]

DELIVERABLES:
1. [DELIVERABLE_1]
2. [DELIVERABLE_2]
3. [DELIVERABLE_3]

FORMAT: [OUTPUT_FORMAT]
Language: text

Lesson Code (Python)

# Structured Output Templates

## JSON Output Template
"Analyze the following and return as JSON:
{
  "analysis": {
    "summary": "string",
    "key_findings": ["string"],
    "recommendations": ["string"],
    "confidence": "high" | "medium" | "low"
  }
}

Input: [Your data here]"

## Markdown Table Template
"Compare [ITEM_1] and [ITEM_2] in a table:

| Aspect | [ITEM_1] | [ITEM_2] |
|--------|----------|----------|
| [Aspect 1] | | |
| [Aspect 2] | | |
| [Aspect 3] | | |

Then provide a recommendation."

## Reusable Template Framework

### Content Creation Template
ROLE: You are a [EXPERTISE] specializing in [DOMAIN].

TASK: Create [CONTENT_TYPE] about [TOPIC].

CONTEXT:
- Audience: [AUDIENCE]
- Tone: [TONE]
- Goal: [GOAL]

FORMAT:
- Structure: [OUTLINE]
- Length: [WORD_COUNT]
- Style: [STYLE_GUIDE]

### Data Analysis Template
ROLE: You are a [ANALYSIS_TYPE] analyst.

TASK: Analyze [DATA_DESCRIPTION].

DATA:
[DATA_HERE]

DELIVERABLES:
1. [DELIVERABLE_1]
2. [DELIVERABLE_2]
3. [DELIVERABLE_3]

FORMAT: [OUTPUT_FORMAT]

Console Output

Structured Output Templates

## JSON Output Template
"Analyze the following and return as JSON:
{
  "analysis": {
    "summary": "string",
    "key_findings": ["string"],
    "recommendations": ["string"],
    "confidence": "high" | "medium" | "low"
  }
}

Input: [Your data here]"

## Markdown Table Template
"Compare [ITEM_1] and [ITEM_2] in a table:

| Aspect | [ITEM_1] | [ITEM_2] |
|--------|----------|----------|
| [Aspect 1] | | |
| [Aspect 2] | | |
| [Aspect 3] | | |

Then provide a recommendation."

## Reusable Template Framework

### Content Creation Template
ROLE: You are a [EXPERTISE] specializing in [DOMAIN].

TASK: Create [CONTENT_TYPE] about [TOPIC].

CONTEXT:
- Audience: [AUDIENCE]
- Tone: [TONE]
- Goal: [GOAL]

FORMAT:
- Structure: [OUTLINE]
- Length: [WORD_COUNT]
- Style: [STYLE_GUIDE]

### Data Analysis Template
ROLE: You are a [ANALYSIS_TYPE] analyst.

TASK: Analyze [DATA_DESCRIPTION].

DATA:
[DATA_HERE]

DELIVERABLES:
1. [DELIVERABLE_1]
2. [DELIVERABLE_2]
3. [DELIVERABLE_3]

FORMAT: [OUTPUT_FORMAT]

Code Visualization Tips

  • 🧠Create a visual template library with cards for each template type.
  • 🧠Draw a flowchart showing how structured prompts flow through the LLM.
  • 🧠Use color-coding to separate different parts of complex prompts.

Professional Tips & Tricks

  • ⚡Always specify the output format at the END of your prompt — it's the last thing the model processes.
  • ⚡Use placeholder variables like [VARIABLE] to make templates reusable.
  • ⚡Test your templates with 3-5 different inputs to ensure consistency.

Python Code Judge & Practice Arena

LeetCode Style

Run real Python 3.12 WebAssembly code directly in your browser against automated test suites.

Solved:0 / 2
0 / 30 XP
Challenges:
Problem 1 of 2

Template Creation Exercise

Medium+20 XP
Create a reusable prompt template for generating social media post ideas. Include placeholders for industry, target audience, and platform.
main.pyPython 3.12 (WASM)
1
2
3
4
5
6
7
8
9
10
11
12
Press Run Code to test or Submit to verify test cases

Test Your Knowledge

Instant feedback

Quick Check: Structured Outputs & Templates

1 / 2
Why is it important to specify output format in prompts?

Up next · Continue learning

Chain-of-Thought Variants

Explore different chain-of-thought approaches: zero-shot CoT, few-shot CoT, and auto-CoT.

10 mins read50 mins
Start next lesson
Previous: Core Prompting TechniquesNext: Chain-of-Thought Variants
Made withbyAmol Shukla·amolshukla.online
ASAmol Shukla

AI Developer, Trainer & Agentic AI Expert building practical learning systems and real-world AI applications.

Explore

  • Projects
  • Courses
  • Prompts
  • Skills
  • Contact
  • Experience
  • Blogs

Connect

  • Resume
  • Contact
© 2026 Amol Shukla·Created withbyamolshukla.online
Back to top