OpenAI releases feature to force JSON output to conform to a specific schema with 100% accuracy



OpenAI has released a mode that allows you to structure your data in a way that ensures it adheres to a schema you specify.

Introducing Structured Outputs in the API | OpenAI

https://openai.com/index/introducing-structured-outputs-in-the-api/



Reading unstructured data and outputting structured data is one of the main use cases for AI. Until now, OpenAI's API had a setting called 'JSON mode,' which made it possible to have AI output JSON with a specified structure, but the data output did not necessarily match the specified structure.

In the newly released 'gpt-4o-2024-08-06' model, by setting strict to 'true', data can be output according to the specified structure with 100% accuracy.



There are two ways to use this feature. The first is to set 'strict: true' when calling a function using 'tools', which is available on all models after gpt-4-0613 and gpt-3.5-turbo-0613.



The second is to set 'json_schema' in the newly available 'response_format' option. This is available in the gpt-4o-2024-08-06 and gpt-4o-mini-2024-07-18 models.



If the model refuses to generate a response due to an unsafe request, the refusal will be noted in the response's 'refusal' field, allowing your program to immediately determine that the structured data specified was not generated.



In addition, the specified structured data may not be output if the execution is stopped midway due to reaching the token limit, etc. There are also other limitations, such as the inability to use parallel function calls and additional latency in the initial API response.

By switching from the conventional model gpt-4o-2024-05-13 to the newly released gpt-4o-2024-08-06 model, the fee based on the number of input tokens will be half the price, at $2.5 per million tokens (about 366 yen), and the fee based on the number of output tokens will be 33% off, at $10 per million tokens (about 1,460 yen).

in Software, Posted by log1d_ts