Structured Output Prompting: Getting Reliable JSON, Tables, and Formatted Data
Why Structured Output Matters
For many professional and technical applications, you do not just want the AI to write something. You want it to produce data in a specific format that another system, spreadsheet, or workflow can consume directly. You want JSON that a developer can parse, a table that can be pasted into Excel, a numbered list that follows a precise structure, or extracted fields that match a database schema.
Getting consistent structured output from AI requires knowing how to ask for it precisely. This tutorial covers the most important patterns.
Asking for JSON
The most common structured output request is JSON. When you need the model to return data in a format a program can parse, JSON is usually the right choice.
Basic JSON request:
Extract the following information from the job posting below and return it as JSON.
Fields to extract:
- job_title (string)
- company_name (string)
- location (string)
- salary_range (string or null if not mentioned)
- required_experience_years (integer or null)
- key_responsibilities (array of strings, max 5)
Return only the JSON object. No explanation.
Job posting:
[paste job posting]
The key elements here are: name the fields explicitly, specify the data type for each field (string, integer, array, null), and tell the model to return only the JSON with no surrounding explanation. That last instruction is important. Without it, the model often wraps the JSON in a paragraph of text.
Providing a Schema
For more complex structures, provide an example schema the model should follow.
Analyze the customer feedback below and return a JSON object matching this schema:
{
"overall_sentiment": "positive" | "neutral" | "negative",
"score": 1-10,
"key_themes": ["theme1", "theme2"],
"specific_complaints": ["complaint1"] or [],
"specific_praise": ["praise1"] or [],
"recommended_action": "string describing what to do"
}
Return only the JSON. No markdown code blocks. No explanation.
Customer feedback:
[paste feedback]
Showing the schema as an example is clearer than describing it in words, and reduces ambiguity about nesting, field names, and data types.
Asking for Tables
For output that will go into a spreadsheet or document, ask for a markdown table with explicit column headers.
Here is a list of project tasks. Create a table with these columns:
| Task | Owner | Priority (High/Medium/Low) | Estimated Days | Status |
Fill in the table based on the information below. If a field is unknown, write "TBD".
[paste task descriptions]
Markdown tables paste cleanly into Notion, Google Docs, and many other tools. For Excel, ask for a CSV instead:
Return the same information as a CSV (comma-separated values), one row per task,
with the same column headers. Include the header row. No other text.
Extracting Multiple Fields From Unstructured Text
One of the most practical applications of structured output is extracting specific fields from unstructured text: emails, meeting transcripts, contracts, support tickets.
Read the email below and extract the following information.
Return your answer in this exact format:
Sender name: [name]
Sender company: [company]
Request type: [question / complaint / order / other]
Key request or question: [one sentence]
Deadline mentioned: [date or "none"]
Urgency: [high / medium / low]
Recommended response: [what we should do]
Do not include any other text.
Email:
[paste email]
This pattern is extremely useful for processing incoming communications at volume. You can run the same prompt over dozens of emails and get consistently formatted output that can be sorted, filtered, or entered into a CRM.
Numbered Lists and Constrained Structures
For simpler structured output, you can specify exactly how many items you want and in what format.
Give me exactly 5 subject line options for this email campaign. No more, no less.
Number them 1 through 5. No bullet points. No explanation. Just the five lines.
Or:
Write a SWOT analysis for the business described below.
Use exactly this structure:
Strengths:
1. [strength]
2. [strength]
3. [strength]
Weaknesses:
1. [weakness]
2. [weakness]
3. [weakness]
Opportunities:
1. [opportunity]
2. [opportunity]
3. [opportunity]
Threats:
1. [threat]
2. [threat]
3. [threat]
[business description]
Providing the exact structure in the prompt is more reliable than describing the structure in words.
Handling Inconsistent Output
Even with precise instructions, models sometimes produce output that does not match the requested format. A few techniques help:
Repeat the format instruction at the end. Models attend to both the beginning and end of a prompt. Adding "Remember: return only the JSON. No other text." at the end of a long prompt reinforces the instruction.
Use negative instructions. "Do not include any explanation" is clearer than just "return the JSON."
Add a validation step. Ask the model to check its own output: "Review your JSON and verify it is valid. Fix any formatting issues before returning it."
Use a follow-up prompt. If the output is close but not right, follow up: "Your output contains extra text before the JSON. Please return just the JSON object, starting with {".
When to Use Structured Output
Structured output prompting is the right approach when:
- The output will be consumed by another system, not just read by a human
- You are processing many documents and need consistent field extraction
- You are building a repeatable workflow where format consistency matters
- You want to paste the output directly into a spreadsheet, database, or template
For one-off tasks read by a human, a well-formatted plain text response is usually simpler and equally useful.
Discussion
Sign in to comment. Your account must be at least 1 day old.