Skip to content
TokIQ

Structured output

Structured output: getting JSON you can actually parse

Structured output prompting is how you get a model to answer in a fixed, machine-readable shape, usually JSON that matches a schema. The reliable approach combines a clear schema, an example, the provider’s structured-output or JSON mode when available, and validation in your code with a retry when parsing fails.

Coming soon onApp StoreComing soon onGoogle Play

Sample question · Structured output

Your app parses the model’s JSON, but sometimes the reply starts with “Sure! Here is the JSON:”. What is the most robust fix?

  1. AAdd “please” to the prompt
  2. BUse the API’s structured-output / JSON mode with a schema and validate the result
  3. CLower the temperature to 0 and hope
  4. DStrip the first line of every reply
Show the answer and why

B. Use the API’s structured-output / JSON mode with a schema and validate the result Native structured-output modes constrain the reply to valid JSON, and schema validation catches the rest. String hacks break as soon as the wording changes.

What the questions test

  • Describing a schema the model can follow
  • Required fields, enums and empty values
  • Validating output and retrying on failure
  • Keeping prose out of machine-readable answers

What you’ll learn

  • How to specify JSON output with a schema
  • How to handle missing or unknown values
  • When to use native structured-output features
  • How to validate and recover from bad output

How to practice it in TokIQ

  1. 1. Open Structured output. Pick it from the topic list on the Quiz tab. It is a Premium topic; the free plan includes Fundamentals, Role & context and Examples.
  2. 2. Answer one question at a time. You see right away whether you were correct.
  3. 3. Tap Why? Read the short explanation and answer three follow-up questions on the same idea.
  4. 4. Watch your accuracy. The Progress tab shows how Structured output compares with your other topics.

Structured output: common questions

How do I make an LLM return valid JSON?

Give a schema and an example, use the provider’s structured-output or JSON mode if it has one, and validate the reply in code. On failure, retry with the validation error included.

What should the model do when a field is unknown?

Tell it explicitly, for example “use null when the document does not say”. Otherwise models tend to fill gaps with plausible guesses.

Further reading

More topics

Practice structured output a few questions a day.

Short quizzes on real prompting decisions, with an explanation for every answer. Free to start on iPhone and Android.

Coming soon onApp StoreComing soon onGoogle Play