Skip to content

Technique

Intermediate

Structured output prompting

Ask for answers in a precise format — tables, JSON, CSV, or fixed sections — so results are easy to scan, compare, or reuse.

What it is

Structured output prompting means specifying an exact format for the response: a table with named columns, a JSON object with defined fields, a CSV, or a fixed set of headings. Instead of free-flowing prose, you get output that's predictable, easy to scan, and easy to paste into a spreadsheet, document, or program.

The more precisely you define the structure, the more consistently the model follows it.

When to use it

  • Comparing options side by side (products, plans, job offers)
  • Output that goes into a spreadsheet, database, or code
  • Extracting specific fields from messy text (invoices, emails, resumes)
  • Reports that must follow the same sections every time

How it works

Why it works

A named format gives the model a template to fill in. Column names and field names act like mini-instructions: each one tells the model exactly what information to produce and where. It also makes missing or wrong information obvious at a glance.

Tables for humans

Before

Compare these three phone plans for me.

After

Compare the three phone plans below in a markdown table with these columns: Plan | Monthly cost | Data | Contract length | Best for Then add one sentence recommending a plan for someone who uses ~5 GB a month and travels abroad twice a year.

JSON for software

When output feeds into code or an automation, define the shape exactly and show it:

Prompt
Extract the details from the email below and return ONLY valid JSON,
with no extra text, matching this shape:

{
  "customer_name": string,
  "order_number": string or null,
  "issue_type": "refund" | "shipping" | "damaged" | "other",
  "requested_action": string,
  "urgent": boolean
}

If a field isn't mentioned, use null. Don't guess.

Email:
"""
[paste email]
"""

Key details that improve reliability:

  • Show the exact shape, including field names and allowed values.
  • Say what to do with missing data ("use null," "write N/A") so the model doesn't invent it.
  • Ask for the format only when a program will parse it, with no greeting or explanation around it.
  • Give an example (few-shot) if the structure is unusual.

Watch out: Structured output can make wrong information look authoritative. A neat table of "facts" is still only as reliable as its source; verify numbers and details that matter.

Note: For software, many AI platforms offer dedicated structured-output or JSON modes that enforce valid formatting. If you're a developer, prefer those and still validate the result in code.

Step by step

  1. 1

    Decide where the output will go (reading, spreadsheet, code) and pick the format to match.

  2. 2

    Name every column, field, or section, in the order you want.

  3. 3

    Define allowed values or types for fields that need consistency.

  4. 4

    Tell the model how to handle missing or uncertain information.

  5. 5

    For machine-readable output, ask for the format only, with no extra commentary.

  6. 6

    Check or validate the result, and add an example if the format keeps breaking.

Weak vs strong

Weak prompt
Pull out the important info from these receipts.
Why it falls short: "Important info" is undefined, and no format is given, so each receipt may come back in a different shape that's hard to total or paste into a spreadsheet.
Strong prompt
From the receipts below, create a CSV with the header row: date,vendor,category,amount
Use YYYY-MM-DD for dates, numbers only for amount (no currency symbol), and one of these categories: food, travel, office, other. If a value is unreadable, write UNKNOWN. Output the CSV only.

Receipts:
"""
[paste receipt text]
"""
Why it works: Columns, date format, number format, allowed categories, missing-data handling, and output boundaries are all defined, so the result can be pasted straight into a spreadsheet.

Practical use cases

  • Decision tables

    Compare apartments, job offers, or software tools in a table with your own criteria as columns.

  • Data extraction

    Turn invoices, resumes, or support emails into consistent rows or JSON records.

  • Repeatable reports

    Get a weekly status update that always has the same sections: Done, In progress, Blocked, Next week.

  • App and automation inputs

    Produce JSON that a script, spreadsheet import, or no-code tool can consume directly.

Practice exercise

Mess to table. Paste a messy block of text — a long group-chat thread about weekend plans, or a few product reviews.

  1. Ask the AI to extract it into a table with 4 columns you choose.
  2. Specify how to handle missing information.
  3. Then ask for the same data as JSON and check whether the field names and values stay consistent.