Back to Curriculum

Output Formatting: Engineering Machine-Readable Responses

In automated growth pipelines, the AI's output is rarely the final step. It must be parsed by a script, inserted into a database, or rendered in a UI. This lesson teaches you how to force the model to output valid JSON, HTML, or Markdown with 100% reliability.

🏗️ The Schema Enforcement Hierarchy

  1. Structural Priming: Define the keys and data types before the task.
  2. Negative Constraints: "No conversational filler. Start with '{' and end with '}'."
  3. Few-Shot Examples: Provide a sample of the exact output format.

🛠️ Technical Snippet: The JSON Schema Prompt

### TASK
Audit the provided landing page for 3 conversion leaks.

### OUTPUT FORMAT
Provide a valid JSON object with the following schema:
{
  "audit_id": "string",
  "leaks": [
    { "location": "string", "issue": "string", "fix": "string", "impact": "int (1-10)" }
  ]
}

### CONSTRAINT
Output ONLY the JSON object. Zero markdown formatting or code blocks.

🔍 Nuance: Markdown Code Blocks

While JSON is for machines, Markdown is for human readability. Use technical delimiters like --- or # to ensure your AI-generated reports are "Ready-to-Post" on LinkedIn or your blog.


⚡ Practice Lab: The Schema Validator

  1. Input: Give an AI a messy set of business hours.
  2. Command: "Convert this into a valid JSON array of objects: {day, open, close}."
  3. Test: Copy the output and paste it into a JSON Validator.
  4. Fix: If it fails (due to a missing comma or trailing text), refactor your prompt using the "Strict Boundary" rule.

📝 Homework: The Email Template Generator

Write a prompt that generates an HTML email template for a "DHA-based Restaurant." The HTML must use inline CSS and include placeholders like {{customer_name}} and {{discount_code}}.