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.
When the consumer is a config file or a human-reviewed pipeline, YAML beats JSON. The same output-contract engine, rendered as a YAML mode.
YAML output makes sense in a narrow band: configuration files, CI pipelines, and outputs a human reviews before committing. The contract mechanics are identical to JSON — schema, example, validation, strictness — with YAML-specific rules taking over: two-space indentation, quoting for special characters, no document separators. This resource loads an event-registration contract in YAML mode to show the engine's format switch in action; if your consumer is code rather than a file, the same schema is one click away from JSON.
Generate in YAML mode
Same schema engine, YAML serializer — note the format-specific rule block.
Check the indentation rule
Two-space indentation is pinned explicitly; indentation drift is YAML's signature failure.
Flip formats to compare
Switch the select to JSON and watch the contract re-render — the schema investment is format-portable.
Choose YAML mode when the consumer is a config file, a CI pipeline, or output a human reviews before committing; keep JSON when code parses it. The schema is identical across both, so flipping the format select re-renders the same event-registration contract in the other syntax. For deeply nested structures, JSON parses more predictably.
The generated prompt carries an OUTPUT RULE that says return only the YAML document and do not wrap it in markdown code fences, precisely because assistants default to fencing YAML. If fences still appear, strip them before your parser reads the file, or re-run the prompt keeping that rule intact. NewPrompt does not run the model or clean the output for you.
It does not guarantee validity; the prompt pins two-space indentation and null-for-unknown rules to reduce YAML's signature failure, but you run it in your own assistant and own the review. That is why this contract targets human-reviewed configs: check indentation and that dietary_notes is set to null rather than omitted before you commit.
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.
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.
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.