Skip to main content

Chapter 3: Formatting and Structure

🎯 Learning Objectives​

After completing this chapter, you will be able to:

  • Use markdown formatting effectively in prompts
  • Create output templates for consistent results
  • Specify complex structures (tables, JSON, code)
  • Build reusable prompt frameworks

📚 Introduction​

The format of your output is as important as its content. A well-structured response is easier to read, use, and process. This chapter teaches you how to get exactly the format you need.

Markdown in Prompts​

Why Use Markdown?​

AI models understand and generate markdown well. Using it helps:

  • Organize complex prompts
  • Request specific formatting
  • Get consistent, readable outputs

Common Markdown Elements​

# Headers for sections
## Subheaders
### Sub-subheaders

**Bold** for emphasis
*Italic* for terms
`code` for inline code

- Bullet points
- For lists

1. Numbered lists
2. For sequences

> Blockquotes for quotes

| Tables | For | Data |
|--------|-----|------|

```code blocks```

Requesting Markdown Output​

Write a summary of machine learning. Format using:
- H2 headers for main sections
- Bullet points for key concepts
- Bold for important terms
- A comparison table for ML types

Output Templates​

What is an Output Template?​

A predefined structure that the AI fills in:

Generate a product review using this template:

---
Product Name: [name]
Rating: [X/5 stars]
Price Paid: [amount]

Pros:
• [pro 1]
• [pro 2]
• [pro 3]

Cons:
• [con 1]
• [con 2]

Summary: [one paragraph]
Recommendation: [Buy/Consider/Avoid]
---

Benefits of Templates​

BenefitDescription
ConsistencySame structure every time
CompletenessEnsures all required info
ParseabilityEasy to extract data
ProfessionalismClean, organized output

Template Examples​

Meeting Notes Template:

Format the discussion as meeting notes:

## Meeting: [Title]
**Date:** [Date]
**Attendees:** [Names]

### Key Decisions
1. [Decision 1]
2. [Decision 2]

### Action Items
| Item | Owner | Due Date |
|------|-------|----------|
| [Task] | [Person] | [Date] |

### Next Steps
- [Next step 1]
- [Next step 2]

Bug Report Template:

Document this bug using the template:

**Bug ID:** AUTO-[number]
**Severity:** [Critical/High/Medium/Low]
**Status:** Open

**Description:**
[One sentence summary]

**Steps to Reproduce:**
1. [Step 1]
2. [Step 2]
3. [Step 3]

**Expected Behavior:**
[What should happen]

**Actual Behavior:**
[What happens instead]

**Environment:**
- OS: [Operating System]
- Browser: [Browser + version]
- App Version: [Version]

Structured Data Formats​

JSON Output​

Extract contact information and return as JSON:

{
"name": "",
"email": "",
"phone": "",
"company": "",
"role": ""
}

Text: "Hi, I'm Sarah Chen from TechCorp. I'm the VP of
Engineering. Reach me at sarah.chen@techcorp.com or
call 555-0123."

Output:

{
"name": "Sarah Chen",
"email": "sarah.chen@techcorp.com",
"phone": "555-0123",
"company": "TechCorp",
"role": "VP of Engineering"
}

XML/HTML Output​

Convert this data to HTML format:

Product: Wireless Mouse
Price: $29.99
Features: Ergonomic, Silent clicks, 12-month battery

Output as an HTML product card with appropriate
semantic tags.

CSV Output​

Convert these sales records to CSV format with headers:

"John sold 15 units of Product A for $500 on Monday.
Mary sold 20 units of Product B for $800 on Tuesday.
Bob sold 10 units of Product A for $350 on Wednesday."

CSV:

Table Structures​

Simple Table Request​

Compare Python, JavaScript, and Java in a table with
columns: Language, Best For, Learning Curve, Job Market.

Complex Table Request​

Create a decision matrix table for choosing a database:

Rows: PostgreSQL, MongoDB, Redis, MySQL
Columns:
- Use Case (best fit)
- Scalability (1-5 rating)
- Learning Curve (Easy/Medium/Hard)
- Cost (Free tier availability)
- When to Choose

Add a header row and brief notes below the table.

Code Output Specifications​

Basic Code Request​

Write a Python function to calculate factorial.
Include:
- Type hints
- Docstring with examples
- Error handling for negative numbers

Detailed Code Request​

Write a JavaScript function with this specification:

Function Name: validateEmail
Parameters: email (string)
Returns: { valid: boolean, reason: string }

Requirements:
- Check for @ symbol
- Check for domain
- Check for valid TLD
- Return specific reason for any failure

Include:
- JSDoc comments
- 3 test cases as comments
- ES6+ syntax only

Multi-Part Response Structures​

Sequential Sections​

Analyze this business proposal in three parts:

PART 1: EXECUTIVE SUMMARY (2-3 sentences)
[Analysis here]

PART 2: STRENGTHS AND WEAKNESSES
Strengths:
- [Point 1]
- [Point 2]

Weaknesses:
- [Point 1]
- [Point 2]

PART 3: RECOMMENDATIONS
[Numbered list of recommendations]

Layered Detail​

Explain quantum computing at three levels:

LEVEL 1 - FOR A CHILD (2 sentences):
[Simple explanation]

LEVEL 2 - FOR A HIGH SCHOOL STUDENT (1 paragraph):
[Intermediate explanation]

LEVEL 3 - FOR A COMPUTER SCIENCE STUDENT (2-3 paragraphs):
[Technical explanation with terminology]

Building Reusable Frameworks​

Framework Structure​

┌─────────────────────────────────────────────────────────────┐
│ REUSABLE PROMPT FRAMEWORK │
├─────────────────────────────────────────────────────────────┤
│ │
│ [ROLE] │
│ You are a {role} with expertise in {domain}. │
│ │
│ [TASK] │
│ Your task is to {action} the following {input_type}. │
│ │
│ [CONTEXT] │
│ Audience: {audience} │
│ Purpose: {purpose} │
│ Constraints: {constraints} │
│ │
│ [INPUT] │
│ {actual_input} │
│ │
│ [OUTPUT FORMAT] │
│ {template_structure} │
│ │
└─────────────────────────────────────────────────────────────┘

Example Framework: Content Review​

CONTENT REVIEW FRAMEWORK

Role: You are a content editor for {publication_type}.

Task: Review the following {content_type} for
{review_criteria}.

Provide feedback using this structure:

## Overall Assessment
Score: X/10
Summary: [1 sentence]

## Strengths
1. [Strength with example]
2. [Strength with example]

## Areas for Improvement
1. [Issue]: [Specific suggestion]
2. [Issue]: [Specific suggestion]

## Edited Version (if applicable)
[Revised content]

---
Content to review:
{content}

Key Takeaways​

Summary
  1. Markdown helps organize prompts and specify output formatting
  2. Templates ensure consistent, complete outputs
  3. Request structured data (JSON, CSV, tables) for programmatic use
  4. Build reusable frameworks for repeated tasks
  5. Layer complexity when needed (simple → detailed)

← Previous: Context and Constraints | Take the Quiz →