GoodPrompts
Main navigation
Concepts

Structured outputs and JSON mode

Distinguish JSON syntax, schema enforcement and factual correctness.

Sources checked

How to use it

  1. A prose instruction can ask for JSON. A JSON mode may constrain syntax. A schema feature can constrain fields, types and permitted values. These are different contracts and vary across providers.
  2. Put schema settings in the actual API request and use only the supported schema subset. Define nullability and additional properties deliberately, then validate every received record.
  3. Handle refusals, incomplete responses and request failures as distinct outcomes. Validate facts against the input after structural validation because a well-shaped response can still contain invented values.

Prompt template

Extract {{data}} into the schema configured in this request. Use null for absent optional facts. Do not infer identifiers or dates. Preserve source evidence for each value. If the task cannot be completed, use the application's supported failure path rather than fabricating a record.

Check the result

  • Test absent fields, unexpected values, empty input and truncated responses.
  • Check both schema compliance and value-level evidence.

Common mistakes

  • An example JSON object is not an executable schema, and valid JSON is not necessarily a valid business record.

Sources