OpenAI’s API now supports Structured Outputs that ensure model responses strictly adhere to developer-supplied JSON Schemas, significantly improving output reliability.
đź’Ž Structured Outputs ensure that model responses match exact JSON schemas.
đź’Ż gpt-4o-2024-08-06 achieves 100% accuracy in schema adherence in evaluations.
🛠️ Function calling and response_format are two ways developers can utilize Structured Outputs.
đź”’ Safety measures prevent the model from producing unsafe outputs, ensuring adherence to existing safety policies.
Key insights
Introduction to Structured Outputs
New API Feature: Structured Outputs ensure that model outputs adhere strictly to JSON Schemas provided by developers.
Improved Reliability: The previous JSON mode did not guarantee schema conformity. The new Structured Outputs feature corrects this.
Use Cases
Generating structured data from unstructured inputs.
Building reliable applications like data extraction, user interface generation, and multi-step workflows.
Examples: Extracting data for entries, separating final answers from reasoning, and dynamically generating UIs based on user input.
Function calling and response formats
Function calling: Structured Outputs can be enabled by setting strict: true in function definitions. This is compatible with models gpt-4-0613 and later.
Response Format: Developers can enforce a JSON Schema via the json_schema option in the response_format parameter. This applies to models like gpt-4o-2024-08-06 and gpt-4o-mini-2024-07-18.
Under the hood
Training and Engineering: The GPT-4o-2024-08-06 model understands complex schemas due to training. Further, constrained decoding ensures strict schema adherence.
Constrained Decoding: Restricting the model to valid tokens based on the JSON Schema ensures output correctness.
Context-Free Grammar (CFG): Used for preprocessing JSON Schemas to facilitate efficient sampling, ensuring adherence to complex and nested schemas.
Limitations and restrictions
Latency: The first response with a new schema incurs additional latency, but subsequent ones are quick.
Errors: The accuracy of filled values within the JSON object isn't guaranteed.
Parallel Calls: Structured Outputs are not compatible with parallel function calls.
Safety Measures: Feature is aligned with OpenAI's safety standards to ensure no unsafe content is generated.
Key quotes
"Structured Outputs ensure model-generated outputs will exactly match JSON Schemas provided by developers."
"Our new model gpt-4o-2024-08-06 scores a perfect 100% on evals for complex JSON schema following."
"Constrained decoding forces valid outputs by constraining our models to only tokens that would be valid according to the supplied schema."
"Structured Outputs is generally available today in the API."
"Developers save 50% on inputs and 33% on outputs by switching to the new gpt-4o-2024-08-06."
This summary contains AI-generated information and may have important inaccuracies or omissions.