Structured outputs

Early access
Copy Page as Markdown

Structured Outputs ensures the model's reply matches your JSON Schema — set text.format.type (Responses) or response_format.type (Chat Completions) to "json_schema" and define your schema (name and schema).

For a yes/no, category, or rating judgment with probabilities, use the Decisions API instead.

Field reference

Responses APIChat Completions
Enabletext.format.type: "json_schema"response_format.type: "json_schema"
Schema nametext.format.nameresponse_format.json_schema.name
Strict modetext.format.strictresponse_format.json_schema.strict
Schematext.format.schemaresponse_format.json_schema.schema
Output locationoutput[0].content[0].textchoices[0].message.content

Note the Responses shape is flattened — name, strict, and schema sit directly on text.format — while Chat Completions nests them under response_format.json_schema. Both accept the same JSON Schema shape in schema.

Schema requirements

  • Root type must be object.
  • List every property in required.
  • Set additionalProperties: false on each object.
  • Supported types: string, number, boolean, integer, enum, array, nested object.

There is no native datetime type—use a string field with ISO 8601 in the name or description (for example, submit_by, detected_at).

For the full constraint list, see OpenAI's supported schemas.

Example

List Nobel Peace Prize winners from 2022 through 2024, classifying each as a person or an organization.

cURLTypeScriptPython

The model returns schema-valid JSON as a string at output[0].content[0].text.

Shown below after parsing (same shape either way — only the output location differs, see Field reference):

{
  "laureates": [
    {
      "year": 2022,
      "name": "Ales Bialiatski",
      "kind": "👤",
      "country_code": "BY",
      "motivation": "Recognized for his tireless efforts to expose human rights abuses and promote democracy in Belarus."
    },
    {
      "year": 2022,
      "name": "Memorial",
      "kind": "🏛️",
      "country_code": "RU",
      "motivation": "Honored for its documentation of political repression and human rights violations in the Soviet Union and Russia."
    },
    {
      "year": 2022,
      "name": "Center for Civil Liberties",
      "kind": "🏛️",
      "country_code": "UA",
      "motivation": "Commended for its courageous work defending human rights and civil liberties in Ukraine."
    },
    {
      "year": 2023,
      "name": "Narges Mohammadi",
      "kind": "👤",
      "country_code": "IR",
      "motivation": "Awarded for her unwavering fight against oppression and her advocacy for women's rights in Iran."
    },
    {
      "year": 2024,
      "name": "Nihon Hidankyo",
      "kind": "🏛️",
      "country_code": "JP",
      "motivation": "Recognized for its efforts to achieve a world free of nuclear weapons and its work to eliminate nuclear weapons."
    }
  ]
}
FieldTypeNotes
laureatesarrayOne object per laureate
yearintegerAward year
namestringPerson or organization
kindenum👤 individual, 🏛️ organization
country_codestringISO 3166-1 alpha-2
motivationstringOne-sentence citation summary

Set stream to false or omit it for a single JSON response.

Response handling

Parse the JSON string at the output location from the field reference above. Before parsing, check for HTTP 4xx errors, refusals/incomplete status, and truncation, then validate the parsed JSON in your app.

Best practices

  • Use the system message (or instructions) to interpret the schema. The schema sets shape; the system prompt sets meaning. Spell out formats, enums, and terse field names—the example above does this.
  • Define fallbacks for missing data. Required fields still need a value when input omits them—e.g. "use 0 for exposure_usd when not applicable."
  • Keep schemas small. Flat objects are easier to satisfy than deep nesting.