Structured Outputs arrives in the OpenAI API

Original development: 6 August 2024

OpenAI announced Structured Outputs in its API on 6 August 2024. The feature was designed to make generated responses conform to a supplied JSON Schema, a significant development for applications that pass model output to other software.

Read the original OpenAI announcement.

Why a predictable response format matters

Earlier integrations often asked an assistant to return JSON and then attempted to repair malformed responses. A schema allows the application to define expected field types, required values and permitted categories. That simplifies the interface between an AI component and a conventional business system.

A small-business example

A support workflow could extract an enquiry type, customer reference, urgency and missing fields. The schema might require enquiry type to be one of four allowed values, with the customer reference permitted to be null. The application should validate whether the reference actually exists in its CRM before proceeding.

Schema compliance is not factual accuracy. A syntactically valid date can still be wrong. Validate source-dependent values separately and retain human approval for consequential actions.

Plan for refusals and failures

Handle errors, incomplete responses and refusals as explicit states. Do not assume that every successful HTTP response contains a usable business record. Check supported schema features in the current API documentation and include regression tests for unusual cases.

See also the developer’s Structured Outputs documentation for technical details and limitations.

Illustrative stock photograph: Chris Ried / Unsplash.

Define a schema that matches the destination system

Consider an engineering firm that receives service requests by email. The application needs to extract a job reference, requested service, preferred date and any missing information. A schema can require each field to be present while permitting an explicit null value where the source does not establish a fact. The surrounding application can then distinguish missing information from an invalid response.

{
  "job_reference": null,
  "service": "inspection",
  "preferred_date": null,
  "missing_fields": ["job_reference", "preferred_date"]
}

This illustrative output is valid as a draft even though the source is incomplete. A downstream application should not create a confirmed appointment until it has obtained and verified the required information. Do not instruct a model to make every field non-null simply to satisfy an inflexible database interface.

Apply two independent layers of validation

Structural validation checks the shape; semantic validation checks the meaning. The first layer confirms that the response contains the expected fields and types. The second checks whether a job reference actually exists, whether the requested service is offered and whether the date is compatible with the business’s operating schedule.

For currency, define whether the value is a decimal amount or an integer number of pence. Do the arithmetic in conventional code. A JSON field containing a number does not prove that the number was accurately copied from a supplier quotation.

Handle failures without corrupting records

Store a pending item when validation fails. Include the source reference and reason for the failure so a reviewer can correct it. If the service returns a refusal, an incomplete response or a timeout, treat these as distinct states. Do not substitute a plausible-looking record simply because the next integration expects a valid object.

Test both ordinary and awkward inputs: a request containing two dates, a reference that belongs to a different customer and a message with no useful job description. Set acceptance criteria for each field and check whether ambiguous results are escalated appropriately.

OpenAI’s evaluation best practices complement the schema documentation. Our Responses API briefing explains how structured arguments fit into a tool-calling workflow. The aim is a predictable interface that supports verification, not an application that trusts every syntactically correct result.

Plan schema changes with the downstream system

Adding a required field or changing a category can break consumers that expect the earlier response format. Keep a schema version in the application and test older records alongside new ones before deployment. For a gradual rollout, ensure that each destination can recognise the version it receives.

Test the failure contract as carefully as the success contract. The application should distinguish a model refusal, invalid business value and unavailable upstream service. The function calling documentation provides further context for structured tool arguments. See our automation guide for the surrounding retry and exception-handling design.