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.
Legacy integrations and enterprise systems still speak XML. The output contract for well-formed, single-root XML responses — same engine, XML rules.
XML output is a compatibility play: SOAP-era integrations, enterprise middleware, feed formats. The contract engine is the same as JSON's — schema, example, validation, strictness — with XML's failure modes addressed by name: exactly one root element, one child element per field, entity escaping for &, <, and >. This resource loads an invoice-metadata contract in XML mode. One boundary worth knowing: this is XML as OUTPUT — using XML tags to structure your prompt's INPUT for Claude is a different technique, covered by the System Prompt Generator.
Generate in XML mode
Note the single-root rule and the escaping rule — XML's two signature failures, addressed by name.
Check the empty-element convention
Unknown optional values become empty elements, keeping the element set stable for downstream XPath.
Keep element order
Strict mode pins schema order — XML consumers are far more order-sensitive than JSON ones.
The OUTPUT RULES pin exactly one <result> root element with one child element per field, and require escaping &, <, and > inside element values, naming XML's two signature failures. JSON Output Prompt Builder generates this contract in XML mode; you run the prompt in your own assistant, then validate the returned XML against your parser before ingesting it.
As empty elements, not omitted tags. The OUTPUT RULES say to use empty elements for unknown values, and VALIDATION RULES keep optional fields present but empty, so the element set stays stable across runs and downstream XPath keeps matching. In the invoice schema that means line_item_count appears as an empty element rather than disappearing when absent.
No, that is a different technique. This is XML as OUTPUT, an invoice-metadata contract returning a <result> document; using XML tags to structure your prompt's INPUT is input formatting. The notFor points that work to the System Prompt Generator, keeping this tool out of Claude-tag territory and focused on the returned document instead.
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.