Skip to content
Navigation
Dashboard
💻Interactive•20 min

Output Formatting (JSON, Structured)

Learn to get structured, parseable outputs from LLMs.

Structured Output from LLMs

Why Structure Matters

Unstructured text is hard to process programmatically. Structured output enables:

  • Reliable parsing
  • Integration with code
  • Consistent formatting
  • JSON Output

    Prompt Template: "Extract the following information and return as JSON: { "name": "...", "email": "...", "company": "..." }"

    Techniques

    1. Schema Definition Provide the exact schema you want.

    2. Examples Show input → output pairs.

    3. Explicit Instructions "Return ONLY valid JSON, no other text."

    4. Structured Outputs API OpenAI and others now offer guaranteed JSON mode.

    Common Formats

  • JSON for structured data
  • Markdown for formatted text
  • XML for hierarchical data
  • YAML for configuration
  • Tables for comparisons
  • 🎯 Key Takeaways

    • ✓Structured outputs enable programmatic processing
    • ✓Provide schema examples for consistency
    • ✓Use JSON mode when available
    • ✓Be explicit about format requirements

    📚 Additional Resources