Pattern 7 of 10

Force structured output when you need it

If something downstream has to read the output, you need structure you can rely on. In 2026 there is a native way to get it, plus a simple chat trick.

For machine-readable output, use native schema modes; pre-fill helps in chat.

Structured output means the model returns a predictable shape, usually JSON, that your code can parse without guesswork. The reliable way to get it now is provider-native, not prompt-pleading.

Why it works

How to do it

  • In production (API): use the provider’s structured-output or JSON-schema mode and pass your schema. The model cannot return malformed JSON.
  • In a chat box: you cannot pass a schema, so describe the exact shape and give one example. A known trick is to pre-fill the start of the answer, beginning the reply with { or an opening tag, which nudges clean, parseable output with no preamble.

Example you can copy

Chat: specify shape + example
Extract the order details as JSON with exactly these keys:
{ "item": string, "quantity": number, "ship_by": "YYYY-MM-DD" }

Rules:
- Return only the JSON object, no commentary.
- If a value is missing, use null.

Order text:
"Need 3 blue mugs shipped before March 2."

When it helps

  • Any output another program will read or store
  • Extraction, classification, and data-shaping tasks
  • Pipelines where malformed output breaks the next step

When to skip it

  • Free-form prose meant for a human to read
  • Exploratory chat where rigid structure gets in the way

Common mistakes

  • Relying on "respond only with JSON" in production instead of schema mode
  • Not specifying what to do for missing or unknown values
  • Allowing prose around the JSON, which breaks parsers

Frequently asked

How do I force ChatGPT or Claude to return valid JSON?

In production use the provider’s structured-output or JSON-schema mode, which constrains the output to valid JSON. In a chat box, describe the exact JSON shape, give one example, and start the answer with an opening brace to avoid extra text.