OpenAI has introduced a significant enhancement to its API with the addition of Structured Outputs. This new feature empowers developers to ensure that model outputs strictly adhere to predefined JSON Schemas. By providing a JSON schema, developers can now guarantee that model responses will always be in the correct format, containing all necessary fields and values. This eliminates the need for extensive post-processing and validation, streamlining development workflows.
Structured Outputs are available in two primary modes: function calling and response format. In function calling mode, developers can define functions with input and output schemas, allowing the model to directly generate structured outputs. The response format mode enables developers to specify a desired output structure for the model’s overall response.
OpenAI has achieved 100% reliability in matching output schemas through a combination of advanced model training techniques and constrained decoding methods. This ensures that developers can confidently rely on the structured data generated by the API.
To facilitate seamless integration, OpenAI’s Python and Node SDKs have been updated with native support for Structured Outputs. Developers can effortlessly define schemas using familiar data structures like Pydantic or Zod, and the SDKs will handle the conversion to JSON schema, deserialization of responses, and parsing of refusals.
With Structured Outputs, developers can expect a significant boost in efficiency and reliability when working with OpenAI’s models. The ability to obtain structured data directly from the API opens up new possibilities for building robust and sophisticated applications.