Topic 4 of 5 · 5 min read
Formats for machines versus people
Goal: Pick the right output format for its destination, and fix a prompt whose output breaks the program or app that reads it.
Choose the output format from where the text will land: a chat window, an email, a document, or a program. Chat shows markdown nicely. Most other places do not. A program also needs a strict shape with nothing extra around it.
Check yourself · 1 of 3
You paste a chat answer into a plain-text email and see "**" and "-" symbols. Why?
Why it matters
Chat apps turn **bold** and - bullets into clean formatting. The same text pasted into a plain-text email shows stray asterisks and hyphens. Pasted into a form field or a spreadsheet cell, it can look broken. And a program that expects a number, a date or JSON will fail on a friendly opening line such as "Sure! Here is the result:".
How to do it
- Name the destination in the prompt. "This goes into a plain-text email" or "This will be read by a script".
- For people outside chat: ask for plain text with no markdown symbols, and describe the layout in words: "blank line between paragraphs, no bullet symbols".
- For programs: ask for the data only. "Return only the JSON, with no explanation and no code fence." Add the exact keys and types.
- Say what to return on failure. For example, an object with an "error" key. Otherwise the model explains in prose, and the parser breaks.
- Validate in code. Check that the reply parses and that each field is the right type. Retry or flag it if not. If your API has a schema-enforced mode, use it.
Before and after
Before: Extract the invoice total from this text.
The reply might be "The total is $1,240.00 (including tax)." A script that needs a number cannot use that.
After: Extract the invoice total from the text below. Return only the number with a dot as the decimal separator, for example 1240.00. If there is no total, return the word NONE. No other text.
For an email: "Write this as plain text for an email. No asterisks, no hash signs, no bullet symbols. Use short paragraphs and a blank line between them."
import json
try:
data = json.loads(reply) # reply is the model's text
assert isinstance(data["total"], (int, float))
except (ValueError, KeyError, AssertionError):
data = None # retry or flag for review
The code above is an optional branch for people who build apps.
What goes wrong
- Markdown in the wrong place. Asterisks and pound signs in a customer email look careless.
- Preamble and sign-off. A script that expects pure JSON gets "Here you go!" and crashes.
- Code fences around JSON. Triple backticks are part of the text, so the parser fails on them.
- No validation. Even with a good prompt, a rare bad reply will reach production unless code checks it.
Examples
Plain text for an email
Prompt: Write a reminder to a tenant about the rent due on 1 March. This goes into a plain-text email, so use no markdown symbols. Short paragraphs, a blank line between each, and a polite closing line.
The reader sees clean text instead of asterisks and bullets.
A strict reply for a script
Prompt: Classify this support message as one word: "billing", "bug" or "other". Return only that word in lower case.
A script can compare the reply to three known values. If it sees anything else, it can retry.
Key points
- Choose the format from the destination: chat, email, document or program.
- Markdown symbols render in chat but show up as stray characters in plain-text email and fields.
- Programs need only the data: no preamble, no sign-off, no code fence.
- Tell the model what to return when it cannot answer, so the parser gets a known shape.
- Validate the reply in code, because a good prompt still does not guarantee a good shape.
Common mistakes
- Pasting chat markdown into an email or form without asking for plain text.
- Allowing chatty openings and closings when a program reads the output.
- Wrapping JSON in a code fence the parser cannot read.
- Skipping validation because the prompt worked in testing.
Check yourself · 2 of 3
A script reads the model's reply as a number. Which instruction is best?
Check yourself · 3 of 3
Your parser fails on JSON that the model wrapped in a code fence. What is the best next step?
Practice items, not counted towards your mastery.
Start here
- Prompting best practices (Claude docs) (opens in a new tab)DocsFree
Anthropic's guide, with a section on controlling the format of responses.
- Structured model outputs (OpenAI API docs) (opens in a new tab)DocsFree
Explains JSON Schema-constrained responses and when they beat prompting alone.
- Structured output (Gemini API) (opens in a new tab)DocsFree
Google's page on schema-enforced JSON, with examples of typed fields.