Structured Outputs
Structured Output Schema
You can set the response_format parameter to your defined schema to ensure the model produces a JSON object that matches your specified structure.
Ensure to set the "strict" parameter to false, as true isn’t supported yet. When it is available, it will ensure the model strictly follows your function schema instead of making a best-effort attempt.
JSON mode
You can set the response_format parameter to json_object in your request to ensure that the model outputs a valid JSON. In case the mode is not able to generate a valid JSON, an error will be returned.
In case the model fails to generate a valid JSON, you will get an error message Model did not output valid JSON.
Other methods of structured outputs
Beyond JSON mode, structured outputs can be generated using the Instructor library. Learn more on the Instructor integration page.