Topic 2 of 5 · 5 min read
Fixed templates and JSON shapes
Goal: Write a template or JSON shape with named fields for a recurring output, and say when a schema-enforced mode is needed instead.
When the same kind of output is needed again and again, give the model a template with named fields to fill in. When a program reads the output, use JSON with a fixed set of keys, and turn on a schema-enforced mode if your tool offers one. A prompt alone asks politely. A schema makes the shape a rule.
Check yourself · 1 of 3
Why add "use null if the call does not say" to a JSON prompt?
Why it matters
Free-form answers vary from run to run. A weekly status update that has "Risks" on Monday and "Concerns" on Tuesday is hard to compare or paste into a tracker. A template fixes the section names and their order, so every output looks the same and gaps show up as empty fields instead of missing sections.
How to do it
- Write the template out with a label for each field, in the order you want, and say "fill in every field; write 'none' if there is nothing to report".
- Say what goes in each field in a few words: "Status: one of on track, at risk, blocked".
- For JSON, list the keys and their types, and give one filled example.
- Allow an honest empty value. If a field can be unknown, say so ("use null"). Otherwise the model invents a value to fill the slot.
- Use the enforced mode when a program depends on it. The OpenAI, Gemini and Claude APIs each have a structured-output feature that takes a JSON Schema and constrains the response to it. Chat apps usually do not expose this, so there the prompt is all you have.
Before and after
Before: Summarise this customer call as JSON.
You may get any keys, in any nesting, sometimes wrapped in friendly text.
After: Summarise this customer call as JSON with exactly these keys: "customer" (string), "sentiment" (one of "positive", "neutral", "negative"), "issues" (list of short strings), "follow_up_needed" (true or false). If the call does not say, use null. Return only the JSON.
A template for people works the same way: "Use this layout: Goal / Progress this week / Risks / Needs from others. Write 'none' under a heading if empty."
What goes wrong
- Prompt-only JSON. Without an enforced mode, a model can add a comment, drop a key or break a bracket. A program must still validate the result.
- A template with no examples of values. "Status" gets filled with a sentence one week and a word the next.
- No empty option. Asked for a "due date" the call never mentions, the model makes one up.
- A schema that is too clever. Deep nesting and many optional fields raise the chance of errors. Keep shapes flat and small.
{ "customer": "Northwind", "sentiment": "neutral", "issues": ["late delivery"], "follow_up_needed": true }
That optional code branch is only for people who feed the result to a program. Everyone else can use the same ideas with a plain-text template.
Examples
A weekly update template
Prompt: Turn my notes into a weekly update using exactly this layout:
Goal: Progress this week: Risks: Needs from others:
Write "none" under any heading with nothing to report.
Every week the update has the same four sections in the same order, and empty ones say "none" instead of vanishing.
JSON for a program
Prompt: Extract the order from this email as JSON with keys "item" (string), "quantity" (integer) and "deliver_by" (date as YYYY-MM-DD, or null if not stated). Return only the JSON.
The types and the null rule leave little room for invented dates.
Key points
- A template with named fields makes recurring outputs look the same every time.
- For JSON, list each key with its type and give one filled example.
- Give the model an allowed empty value, such as null, so it does not invent data.
- Prompt-only JSON can still break; a schema-enforced mode constrains the response to the shape.
- Keep schemas flat and small to reduce errors.
Common mistakes
- Asking for JSON without naming the keys.
- Forgetting an empty value, so the model invents data.
- Trusting prompt-only JSON without validating it in code.
- Building deep, complex schemas when a flat one would do.
Check yourself · 2 of 3
Which prompt is most likely to give the same sections every week?
Check yourself · 3 of 3
Your app parses the model's JSON, and a few replies start with "Sure, here it is:" and break the parser. What is the most reliable fix?
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.
More for this topic
- Structured outputs (Claude docs) (opens in a new tab)DocsFree
Anthropic's page on getting responses that match a schema.