Controlling the Output Format
Reviewed & published by Brayan K
Telling the AI exactly how to shape its answer — as a table, JSON, bullet points, or a one-paragraph summary — gets you a result you can use immediately, instead of a wall of prose you have to reformat by hand.
Part of the free Prompt Engineering course at LearnCodingFast — hands-on lessons with worked examples and the output they print, plus practice exercises and a quick quiz.
You almost always know where the answer is going next: a spreadsheet, a program, a slide, a quick scan. Say so. This lesson shows you the formats worth asking for and how to nail length, too.
What You'll Learn in This Lesson
- Why naming a format saves you re-prompting
- Asking for tables and CSV for spreadsheet-ready data
- Getting clean, parseable JSON for programs
- Bullet lists, numbered steps, and markdown
- Controlling length: word limits, bullet counts, one sentence
- Forbidding preamble: 'just the answer, nothing else'
1 Say where the answer is going
If you don’t name a format, the model defaults to paragraphs — and you waste a round re-asking. Same question, two prompts:
Tell me about the 5 biggest
planets in the solar system.You get rambling prose you’d have to reformat to use anywhere.
List the 5 biggest planets as a table
with columns: Planet, Diameter (km),
Moons. Sort largest first. Table only.Spreadsheet-ready, sorted, no fluff — usable the instant it arrives.
2 A catalog of formats to ask for
| Format | Ask for it when… |
|---|---|
| 📊 Table / CSV | You want spreadsheet-ready rows and columns. |
| 🔧 JSON | A program will read the output — name the keys. |
| • Bullet list | You want a quick, scannable summary. |
| 1. Numbered steps | Order matters (a recipe, a how-to). |
| 📝 Markdown | You want headings and bold that render in docs. |
| ¶ One paragraph | You need flowing prose, not a list. |
For JSON, add “return ONLY valid JSON, nothing before or after” so a chatty intro doesn’t break your parser.
3 Control the length precisely
“Keep it short” is vague. Concrete limits work far better:
• "in exactly 3 bullet points"
• "under 100 words"
• "one sentence"
• "a single short paragraph"
• "the answer only, no introduction or sign-off"📋 Copy-paste output-format template
<your request>.
Format the answer as <table / JSON / bullets / etc.>.
<For JSON: with keys: ...; return ONLY JSON.>
Length: <3 bullets / under 100 words / one sentence>.
Do not add any introduction or sign-off.Try it for real
Asking for JSON does not get you JSON — it gets you something that usually looks like JSON. Run this on three real-shaped replies: one clean, one wrapped in chatter, one with a trailing comma a human reads straight past. The prompt asks for the format; the parser is what makes your program safe when the reply drifts.
# The rule this lesson is really teaching: never trust a format you did not verify.
# Below are three replies a model gave when asked for JSON. Two of them look fine.
import json
replies = [
'{"name": "Ada", "role": "engineer"}',
'Sure! Here is the JSON:\n{"name": "Ada", "role": "engineer"}',
'{"name": "Ada", "role": "engineer",}',
]
REQUIRED = {"name", "role"}
for i, raw in enumerate(replies, 1):
print(f"--- reply {i}: {raw!r}")
try:
data = json.loads(raw)
except json.JSONDecodeError as e:
print(f" REJECTED — not parseable: {e.msg} at column {e.colno}")
continue
missing = REQUIRED - data.keys()
if missing:
print(f" REJECTED — missing keys: {sorted(missing)}")
else:
print(f" ACCEPTED — {data}")
print()
print("Reply 2 is valid JSON wrapped in chat. Reply 3 has a trailing comma, which")
print("a human reads straight past. Both are why 'reply in JSON' belongs in the")
print("prompt AND a parser belongs in your code.")# 🎯 YOUR TURN — write the guard that decides what your program accepts.
import json
REQUIRED = {"title", "priority"}
replies = [
'{"title": "Fix login", "priority": "high"}',
'{"title": "Fix login"}',
'here you go: {"title": "Fix login", "priority": "low"}',
]
def validate(raw):
# 1) Anything that is not parseable JSON is rejected outright.
try:
data = json.loads(raw)
except json.JSONDecodeError:
return "not JSON"
# 2) A parsed object still has to carry every required key.
missing = REQUIRED ___ data.keys()
# 👉 replace ___ with -
return "ok" if not missing else f"missing {sorted(missing)}"
for raw in replies:
print(validate(raw))
# ✅ Expected output:
# ok
# missing ['priority']
# not JSONCommon Mistakes (and the fix)
- Not naming a format. — You get prose; say “as a table” or “as JSON”.
- Asking for JSON without “only JSON”. — A friendly sentence sneaks in and breaks parsers.
- Saying “keep it short”. — Give a number: 3 bullets, under 100 words.
- Forgetting to name the columns/keys. — Specify them so the structure is predictable.
⏱ Test Yourself — Timed Quiz
10 quick questions, 12 seconds each. Instant feedback — beat the clock!
🎉 Lesson Complete
- ✅ Name the format — table, JSON, bullets — so the answer is usable now
- ✅ For JSON, demand “only JSON, nothing else” and name the keys
- ✅ Control length with concrete limits, not “keep it short”
- ✅ Forbid preamble when you want just the answer
- ✅ Picture where the output lands and ask for that exact shape
Practice quiz
Why specify the OUTPUT FORMAT in your prompt?
- It is rude not to
- It makes the AI slower
- You get the answer in a shape you can use right away, with less re-prompting
- It has no effect
Answer: You get the answer in a shape you can use right away, with less re-prompting. Naming the format saves back-and-forth and gives you a usable, predictable result.
You want data you can paste into a spreadsheet. Ask for…
- A table or CSV with named columns
- A poem
- A long paragraph
- Just one word
Answer: A table or CSV with named columns. Tables or CSV map cleanly into spreadsheet rows and columns.
To get machine-readable output for a program, request…
- A story
- A bulleted list of feelings
- Random text
- Valid JSON with specific keys
Answer: Valid JSON with specific keys. JSON with defined keys is the standard machine-readable format.
Which prompt controls length best?
- 'write about dogs'
- 'summarize this in exactly 3 bullet points, under 15 words each'
- 'tell me stuff'
- 'go on'
Answer: 'summarize this in exactly 3 bullet points, under 15 words each'. Stating a precise count and word limit controls length reliably.
For a quick scannable answer, ask for…
- A bulleted or numbered list
- One giant paragraph
- JSON only
- No formatting
Answer: A bulleted or numbered list. Bullet and numbered lists are easy to scan.
If you need only the answer with no preamble, say…
- 'explain everything'
- 'be friendly'
- 'reply with only the answer, no introduction or sign-off'
- 'add lots of context'
Answer: 'reply with only the answer, no introduction or sign-off'. Explicitly forbidding preamble removes the chatty intro and outro.
Asking for JSON but the model adds a sentence before it. Best fix?
- Give up
- Say 'return ONLY valid JSON, nothing before or after'
- Ask for a poem
- Ignore it
Answer: Say 'return ONLY valid JSON, nothing before or after'. Emphasizing 'only JSON, nothing else' keeps the output clean and parseable.
To compare options side by side, request…
- A single number
- A haiku
- A wall of text
- A table with one row per option and columns for each criterion
Answer: A table with one row per option and columns for each criterion. A comparison table lines options up against the same criteria.
Which is a length constraint?
- 'use JSON'
- 'keep it under 100 words'
- 'use a table'
- 'be formal'
Answer: 'keep it under 100 words'. A word or sentence limit constrains length.
Markdown formatting is handy when you want…
- Raw bytes
- A binary file
- Headings, bold, and lists that render nicely in docs and chat
- No structure at all
Answer: Headings, bold, and lists that render nicely in docs and chat. Markdown gives readable headings, bold, and lists in most chat and doc tools.
Continue this course
- Previous: Chain-of-Thought Reasoning
- Next: Prompting AI to Write Code — Give language, version, the error and the goal — then read and test the result
Frequently asked questions
Why should I tell the AI what format I want?
Because you almost always have a use in mind — a spreadsheet, a slide, code, a quick scan. If you don't say, the model defaults to prose, and you waste a round re-asking for a table or list. Naming the format up front ('reply as a 3-column table') gets you something usable on the first try.
How do I get clean JSON I can use in a program?
Ask for it explicitly and name the keys: 'Return ONLY valid JSON with keys name, price, and inStock. No text before or after.' The 'nothing before or after' part matters — otherwise models often wrap the JSON in a friendly sentence that breaks parsers.
Can I control how long the answer is?
Yes, and it's one of the most useful controls. Be specific: 'in exactly 3 bullet points', 'under 100 words', 'one sentence', or 'a single paragraph'. Vague asks like 'keep it short' work less reliably than a concrete number.
What formats can I ask for?
Tables, CSV, JSON, bullet or numbered lists, markdown with headings, a single paragraph, a checklist, or 'just the answer with no preamble'. Pick whatever matches where the output is going next.