Schema-first prompting means designing the JSON object your downstream code needs before you write a single instruction to the model. You define fields, types, enums, and nullability against the consumer's real requirements, then write a prompt that references that contract. Skip this order and you end up patching parsing bugs in production instead of preventing them.
Quick Answer: Design the output schema from the consuming system's needs first — field names, types, enums vs. free strings, required vs. nullable. Then write the prompt to satisfy that schema. Version the schema explicitly (additive changes only within a version) so old consumers never break when you improve it.
Why Schema-First Beats Prompt-First for Technical PMs
A prompt written before the schema optimizes for what sounds good to a model, not what a parser can safely consume. The result is brittle: a field that's sometimes a string, sometimes an array, sometimes missing. Schema-first inverts the order so the contract, not the prose, is the source of truth.
Think of it as an API design problem wearing a prompt-engineering costume. Your downstream code — a database write, a UI render, a workflow trigger — has fixed expectations about shape and type. Those expectations exist whether or not you write them down. The only choice is whether you make them explicit before generation or discover them as runtime exceptions after.
The consuming system defines the object; the object defines the prompt. This is the entire discipline in one sentence, and it reverses how most people approach LLM output. They write a prompt, run it, look at what came back, and reverse-engineer a parser around whatever shape showed up. That's prompt-first thinking, and it produces schemas that are accidents rather than decisions.
What Breaks Without a Schema-First Approach
Three failure modes recur constantly in production LLM integrations, and all three trace back to skipping the schema step:
- Type drift — a field that's a number in one response and
"N/A"(a string) in another, crashing a strict parser. - Silent enum sprawl — a
statusfield that returns"in progress","In-Progress", and"pending review"across calls because nothing constrained the vocabulary. - Ambiguous absence — no distinction between "this field legitimately has no value" (
null) and "the model forgot to populate it" (missing key), so your code can't tell a valid empty state from a bug.
Each of these is a parsing bug that schema-first design prevents structurally, not through better wording. As covered in our complete guide to prompt design, the instructions you write are only half the system — the contract they're bound to is the other half, and it has to come first.
Designing the Object Before the Prompt
Start by asking what your code does with the output, not what you want the model to say. A downstream SQL insert needs typed columns. A UI component needs a discriminated shape it can switch on. A workflow trigger needs a stable enum it can branch against. Each consumer constrains the schema before you write one word of instruction.
The Three Questions That Define Every Field
Work through these for every field you plan to include, in this order:
- Who reads this field, and how? A field feeding a
switchstatement needs a closed enum. A field displayed as free text can tolerate open-ended strings. - Can this legitimately be absent, and does absence mean something? Decide
nullvs. omitted vs. required before you decide anything about the prompt wording. - What's the blast radius if the model gets the type wrong? A miscast boolean in a display field is cosmetic; a miscast boolean gating a payment action is a production incident.
Only after answering these for every field do you draft the prompt. The prompt's job at that point is narrow: describe the schema accurately, give the model enough context to fill it correctly, and constrain generation format (JSON mode, function calling, or a structured-output API feature) so the shape is enforced mechanically, not just requested politely. This sequencing is the practical extension of the idea in system prompt is the new PRD — the contract you write down disciplines everything downstream of it, including the model's behavior.
Enums vs. Free Strings: The Core Design Decision
Choose an enum whenever downstream code branches on the value; choose a free string only when the value is purely descriptive and never drives logic. This single decision prevents more parsing bugs than any other schema choice, because it converts an infinite space of possible model outputs into a closed, testable set.
The tell is simple: if your code ever writes if status == "...", that field should be an enum. If your code only ever displays the value to a human, a free string is fine — and forcing it into an enum just creates a maintenance burden every time a legitimate new value shows up.
| Field type | Use enum when | Use free string when | Failure mode if you choose wrong |
|---|---|---|---|
status / category | Downstream code branches on the value (routing, filtering, gating) | — | Enum sprawl: "done", "Done", "completed" all mean the same thing to a human, nothing to a switch |
summary / notes | — | Value is displayed, not evaluated | Forcing free text into an enum truncates real information or crashes on the first unseen case |
priority | A fixed, small set of levels drives SLAs or sorting | Priority is a continuous score, not a bucket | Mixing scales ("high" and 0.87) in the same field across versions |
confidence | Never — this is almost always a number, not an enum | Rarely — free text hides a comparable value | Treating a numeric confidence as a categorical label loses the ability to threshold it |
Constrain enums at the schema level, not just in prompt instructions. If your generation method supports a enum: [...] constraint (JSON Schema, function-calling parameter definitions), use it — this makes invalid values structurally impossible rather than merely discouraged. A prompt instruction saying "return one of: open, closed, pending" is a request; a schema-level enum constraint is a guarantee, and the gap between those two is exactly where production bugs live.
Nullable vs. Required: Deciding What the Model Must Commit To
Mark a field required only when the task cannot be considered complete without it; mark it nullable when a legitimate "no value" state exists. Conflating these two produces either models that hallucinate values to satisfy an over-eager required field, or code that can't distinguish absence from error.
Required fields should feel uncomfortable to add. Every required field is a promise that the model will always populate it, correctly, across every input the schema will ever see — including edge cases you haven't tested yet. A schema with fifteen required fields either has a model straining to invent plausible values for the ones it's unsure about, or a parser crashing on the first response that legitimately can't fill one in.
A Practical Nullability Checklist
- Ask "is there a valid real-world state where this is genuinely empty?" If yes, it's nullable, not required — a
cancellation_reasonfield is null for every order that wasn't cancelled, and that's correct, not missing data. - Never let "the model usually fills this in" substitute for a real required/nullable decision. Usually isn't always, and the gap surfaces in production, not in your test set.
- Distinguish
nullfrom omitted keys explicitly in your parser, and pick one convention project-wide. Mixing "sometimes the key is missing, sometimes it's null" doubles the branches every consumer has to handle. - Required fields need a fallback story in the prompt — tell the model explicitly what to do when it's uncertain (a documented placeholder value, a lower-confidence estimate) rather than leaving it to improvise.
This is the same discipline covered in structured outputs that ship as real JSON: the schema is the enforceable half of the contract, and nullability rules are where most of that enforcement actually lives.
Versioning the Schema Without Breaking Consumers
Version schemas the way you version APIs: additive changes stay within a version, anything that removes a field, changes a type, or repurposes a name's meaning ships as a new version. This lets you improve the object over time without every prior consumer breaking the moment you deploy.
The trap technical PMs fall into is treating the schema as a living document that mutates freely because "it's just JSON, not a real API." It is a real API — the model is the server, your downstream code is the client, and the same compatibility rules that govern REST or GraphQL contracts apply here with equal force.
Worked Example: Evolving v1 to v2
Consider a schema for extracting action items from meeting notes.
v1 schema:
{
"action_items": [
{ "task": "string", "owner": "string", "due_date": "string | null" }
]
}
This ships fine until product asks for priority levels and a completion flag. The tempting move is to add fields directly into this shape and redeploy. Don't — that's how a consumer written against v1, which doesn't expect a priority key, ends up with silent extra data it never validates, or worse, a strict schema validator that rejects the whole payload for unrecognized fields.
v2 schema, versioned explicitly:
{
"schema_version": "2",
"action_items": [
{
"task": "string",
"owner": "string",
"due_date": "string | null",
"priority": "low | medium | high",
"completed": "boolean"
}
]
}
Three rules made this evolution safe:
- A
schema_versionfield ships in the payload itself, so any consumer can branch on it without out-of-band coordination — no consumer has to guess which shape it received. - New fields (
priority,completed) are additive, not repurposing an existing field's meaning —taskandownermean exactly what they meant in v1. - The prompt references the version explicitly: "Return JSON matching schema version 2, defined as: [schema]." The model is told which contract it's filling, not left to infer from examples alone.
If a later version needs to actually remove or restructure a field — say, splitting owner into owner_id and owner_name — that's a v3, run in parallel with v2 until every consumer has migrated, exactly as you'd stage a breaking REST endpoint change. Our guide on versioning prompts like code and testing them like features covers the release-management side of this same discipline — the prompt and the schema version together, not separately.
How the Prompt References the Schema
Once the schema exists, the prompt's job shrinks to three things: state the schema (or a pointer to it), constrain the output format mechanically, and give the model the context it needs to fill fields correctly. Everything else — the vocabulary, the shape, the nullability rules — is already decided.
A well-formed prompt fragment for the v2 schema above might read:
"Extract action items from the meeting notes below. Return JSON matching this schema:
schema_version: '2',action_items: [{ task: string, owner: string, due_date: string|null, priority: 'low'|'medium'|'high', completed: boolean }]. If a due date isn't mentioned, usenull. If priority isn't stated, infer from urgency language ('ASAP', 'whenever') or default to'medium'."
Notice what this does not do: it doesn't ask the model to be "thorough" or "accurate" in the abstract. It gives explicit fallback behavior for the ambiguous cases the nullability checklist surfaced earlier. That specificity is only possible because the schema decisions were made first — the prompt is downstream of the contract, not the other way around.
Use your platform's structured-output enforcement wherever available. JSON mode, function-calling schemas, and constrained decoding all reduce the model's ability to drift from the contract at generation time, rather than relying on the prompt's wording alone plus a hopeful regex on the other end.
Where Prodinja Fits: Contracts as the Foundation
This same discipline — define the contract before anything downstream depends on it — is the reasoning behind how Prodinja's API Designing tool works in the current prototype. It walks endpoints into real specs and runnable curl examples, reinforcing that a defined contract, not a vague description, is what an integration is actually built on. Whether the contract is a REST endpoint or a JSON object a prompt fills in, the sequencing is identical: define the shape the consumer needs, then build the thing that produces it.
That connects to a broader pattern worth naming: the fields you choose to model in any structured output — action items, owners, priorities — trace back to real jobs your downstream system needs done, the same underlying logic covered in our complete guide to jobs to be done. A schema field that doesn't map to an actual consumer need is a sign the schema was designed prompt-first after all.
Key Takeaways
- Design the JSON schema before the prompt — the consuming system's requirements define the object, and the object defines what the prompt needs to instruct.
- Choose enums for any field downstream code branches on; reserve free strings for purely descriptive values that are only ever displayed.
- Decide nullable vs. required deliberately per field — a required field is a promise the model will always fill it correctly, and that promise should feel costly to make.
- Distinguish
nullfrom a missing key explicitly, and enforce one convention across your whole system so every consumer handles absence the same way. - Version the schema like an API contract: additive changes stay in-version; anything that removes or repurposes a field ships as a new version with a
schema_versionfield in the payload. - Reference the schema and its version directly in the prompt, and lean on structured-output enforcement (JSON mode, function-calling schemas) rather than wording alone.
- A defined contract is the foundation of any integration — whether it's an API endpoint or a JSON object an LLM fills in, the sequencing is the same.
Frequently Asked Questions
What is schema-first prompting?
Schema-first prompting is designing the exact JSON object your downstream code needs — fields, types, enums, nullability — before writing the prompt that generates it. The prompt then references that finished schema instead of the schema emerging accidentally from whatever the model happens to return.
How do I decide between an enum and a free string in an output schema?
Use an enum whenever your code branches on the value (routing, filtering, gating logic); use a free string only when the value is purely displayed to a human and never evaluated programmatically. This single rule prevents most silent type-drift bugs in production.
Should every field in my JSON schema be required?
No — mark a field required only when the task genuinely cannot be considered complete without it. Fields with a legitimate "no value" state should be nullable instead, or you'll force the model to invent plausible-sounding values it isn't confident about.
How do I version a JSON output schema without breaking existing consumers?
Ship a schema_version field in every payload, keep changes within a version strictly additive, and release any field removal or type change as a new version running alongside the old one until consumers migrate — the same discipline as versioning a REST API.
Does structured output from an LLM need a schema if I'm just displaying it to users?
Even display-only output benefits from a lightweight schema, since UI components still need to know which fields to expect and in what shape. The stakes are lower than a field feeding a database write, but skipping the schema still risks a render crashing on an unexpected type or missing key.