Output Formatting: Specifying Exact Formats

Learn how to specify exact output formats like JSON, XML, tables, and structured data.

Format specification
Specifying exact formats ensures outputs are usable and parseable

Many use cases require specific output formats: JSON for APIs, tables for data, XML for structured content, or custom formats for integration. Specifying exact formats in prompts ensures outputs are usable and parseable without manual editing.

Common Format Requirements

JSON is the most common structured format. Specify the exact schema: "Output as JSON with fields: title, author, date, content." Provide examples of the structure you want for best results.

Tables work well for comparative data. Specify columns and structure: "Create a table with columns: Tool, Price, Rating. Include 5 rows." The model will format it appropriately.

Markdown is useful for formatted text. Specify markdown elements: "Use headers, bullet points, and code blocks." The model will produce properly formatted markdown.

Best Practices

Provide format examples. Show the model exactly what you want: "Output format: { 'name': 'string', 'age': number }" is clearer than just saying "JSON format."

Specify validation requirements. Tell the model what makes valid output: "Ensure all required fields are present" or "Numbers must be integers."

Use few-shot examples for complex formats. For intricate structures, showing 2-3 examples is more reliable than describing the format in words alone.

Key Takeaways

  • • Specify exact formats for structured outputs
  • • Provide format examples for clarity
  • • Include validation requirements
  • • Use few-shot examples for complex formats
  • • Essential for API integration and automation