Skip to main content
Structured outputs let you request responses that match a JSON shape you define. When you supply a schema, the model is far less likely to invent keys or return malformed JSON than when you ask for a format in the system prompt. Deepshi uses the OpenAI response_format field, so the schema format matches the OpenAI structured outputs guide.

JSON mode

For simple “just give me valid JSON” cases, set response_format to json_object:

JSON schema

To enforce an exact shape, pass a json_schema. This example asks the model to show its steps solving an equation:
The model returns content matching the schema exactly:
Beyond math, use this for data extraction, classification, UI generation, and any case where you parse the model’s output downstream.

Gotchas

  • Every property must be listed in required. To make a field optional, allow null in its type: "type": ["string", "null"].
  • additionalProperties must be set to false for strict schemas.
  • strict must be true for the schema to be enforced.
  • A schema constrains the shape, not the correctness. The values still depend on the prompt and the model.
  • Very large schemas can hit max_tokens or time out before completing. Keep schemas focused.

Next steps

Tool calling

Let the model call your functions.

Reasoning

Use models that think before they answer.