๐Ÿ“š Beginner

4. Input/Output Formatting

Master structured inputs and outputs. Learn JSON, XML, markdown, and custom formats for consistent results.

Why Formatting Matters

Unstructured outputs are the #1 cause of AI integration failures. When you need to process AI outputs programmatically, consistent formatting is essential.

๐Ÿ’ก The Reality: 90% of production AI applications require structured output that can be parsed and processed by code.

Input Formatting Techniques

Using Delimiters

Clearly separate different parts of your input using consistent delimiters.

Analyze the following customer reviews. Each review is separated by --- REVIEW 1: --- Great product, fast shipping! --- REVIEW 2: --- Item arrived broken, poor packaging. --- REVIEW 3: --- Decent quality for the price. ---

XML-Style Tags

Use XML tags for complex, nested inputs.

<document> <metadata> <author>John Smith</author> <date>2024-01-15</date> </metadata> <content> The quarterly report shows significant growth... </content> </document> Summarize the above document.

Output Formatting Specifications

JSON Output

โŒ Vague Request

"Analyze this product review and give me the results."

Output: Free-form text that's hard to parse

โœ… Structured Request
Analyze this review and return a JSON object with: { "sentiment": "positive|negative|neutral", "score": 0.0-1.0, "key_points": ["string", ...], "recommended_action": "string" } Only return valid JSON, no explanations.

Markdown Tables

Compare these products and return a markdown table with columns: | Product | Price | Rating | Pros | Cons | Include all 5 products. Use concise bullet points for Pros/Cons.

Custom Formats

When you need a specific format, show it explicitly:

Parse this email and extract information in this EXACT format: SENDER: [email address] SUBJECT: [email subject] URGENCY: [HIGH/MEDIUM/LOW] ACTION_REQUIRED: [YES/NO] SUMMARY: [one sentence summary]

Format Enforcement Strategies

1
Explicit Schema Definition

Define the exact structure with field names and types

2
Example Outputs

Show 1-2 examples of correctly formatted outputs

3
Negative Examples

Show what NOT to do: "Do not include markdown formatting"

4
Strict Instructions

"Return ONLY the JSON object, no explanations or markdown"

Handling Arrays and Lists

Extract all action items from this meeting transcript. Return as a JSON array where each item has: { "task": "description", "assignee": "person name or 'unassigned'", "deadline": "YYYY-MM-DD or 'not specified'", "priority": "high|medium|low" } If no action items exist, return an empty array: []
๐Ÿ”‘ Key Takeaway: Always specify your output format explicitly. Use schemas, examples, and strict instructions to ensure consistent, parseable outputs that integrate smoothly with your applications.
๐Ÿงช

Try It Yourself

Practice what you learned with our interactive tools.

โœจ Open Magic Optimizer
๐Ÿ’ก

Pro Tips

  • โ€ข Be specific with your instructions
  • โ€ข Use examples when possible
  • โ€ข Iterate and refine your prompts

Sign in to track your progress

Sign in to Complete