Force JSON Output from AI
Stop getting 'Sure, here is the JSON…' — the output-contract pattern that forces models to return only parseable JSON: schema, example, and a strict rule block.
Native JSON modes guarantee syntax, not your schema. The prompt contract that covers field names, types, and null discipline — whether or not the API has JSON mode.
OpenAI, Claude, and Gemini all offer some form of native structured output — and teams keep getting burned by assuming that solves the problem. Native modes guarantee the response parses; they don't guarantee it contains your field names, your types, or null instead of invented values. The prompt contract still does that work. This resource loads a support-ticket contract that works identically with JSON mode on (where it constrains content) and off (where it also forces syntax) — one prompt, both worlds.
Generate the loaded contract
Note what native JSON mode can't do here: the severity value space, the null rule, the no-extra-fields rule.
Pair with your API settings
JSON mode on: keep the schema and validation sections, the syntax rules become redundant insurance. JSON mode off: everything earns its place.
Constrain values in descriptions
The severity field shows the pattern — enumerate legal values in the description and the model treats it as validation.
Because native modes guarantee the response parses — not that it holds your field names, types, or null instead of invented values. This support-ticket contract does that: it names the schema, constrains severity to "critical, high, medium, or low," and requires reply_needed as a real boolean. With JSON mode on the syntax rules become redundant insurance; with it off they also force valid JSON. One contract, both worlds.
Enumerate the legal values inside the field's line — the pattern the severity field shows: "critical, high, medium, or low" listed in the SCHEMA, which the model treats as validation. The whyThisWorks calls this "the cheapest enum enforcement available," since native JSON modes typically don't constrain value spaces. The prompt encodes it; run the output through a validator if your parser is strict.
Stop getting 'Sure, here is the JSON…' — the output-contract pattern that forces models to return only parseable JSON: schema, example, and a strict rule block.
When the destination is a spreadsheet, CSV is the contract: one header row, one data row, quoting rules, and an honest answer about nested data.
Automation platforms fail silently on malformed model output. The strict contract that keeps AI steps feeding clean JSON into the rest of the flow.
Free text in, named fields out. The extraction prompt pattern that turns any unstructured text into consistent, parseable records.
The JSON won't parse and you can't see why. Deterministic cause-sniffing — trailing commas, single quotes, unclosed brackets — and the repair prompt that fixes it.
'Make it good', 'be detailed', 'keep it interesting' — vague prompts get vague output. The fix is mechanical: replace every fuzzy word with a checkable instruction.
Build prompts that return structured data — JSON first, with YAML, XML, and CSV modes — parseable every time.