Ryan Daws is a senior editor at TechForge Media with over a decade of experience in crafting compelling narratives and making complex topics accessible. His articles and interviews with industry leaders have earned him recognition as a key influencer by organisations like Onalytica. Under his leadership, publications have been praised by analyst firms such as Forrester for their excellence and performance. Connect with him on X (@gadget_ry) or Mastodon (@[email protected])
OpenAI has unveiled “Structured Outputs”, a new API feature designed to address the long-standing challenge of reliably generating structured data from large language models (LLMs). The feature, available now, guarantees that model-generated outputs will adhere to developer-defined JSON Schemas.
Generating structured data from unstructured input is a cornerstone of many AI applications today. Developers leverage the OpenAI API to build sophisticated assistants capable of fetching data, answering complex questions via function calling, extracting structured data for seamless data entry, and enabling multi-step workflows where LLMs can take specific actions.
However, the inherent limitations of LLMs in consistently producing structured output have led developers to employ workarounds such as open-source tooling, intricate prompting techniques, and repeated request retries. These workarounds, while functional, add complexity and compromise efficiency.
OpenAI’s Structured Outputs aims to eliminate these workarounds by aligning OpenAI models with developer-supplied schemas and training them to understand and follow complex data structures better.
“Structured Outputs solves this issue by aligning OpenAI models with developer-supplied schemas and training our models to comprehend complicated schemas,” OpenAI explained in a blog post.
Internal evaluations using complex JSON schemas have demonstrated remarkable improvements. The latest model, gpt-4o-2024-08-06, achieved a perfect 100% score in adherence to structured outputs, a substantial upgrade over the previous gpt-4-0613, which scored less than 40%.
Structured Outputs is available in two primary implementations:
OpenAI has prioritized safety in Structured Outputs, ensuring it aligns with pre-existing safety policies. The model retains the ability to refuse unsafe requests, indicated to developers by a new refusal string value in API responses. This allows for programmatic detection of refusals, ensuring predictable behavior and simplified error handling. Notably, the absence of a refusal value and a successful generation process (signified by finish_reason) guarantee a valid JSON output matching the developer-defined schema.
Native support for Structured Outputs has been integrated into OpenAI’s Python and Node SDKs, simplifying its use. Developers can define schemas for tools or response formats by providing a Pydantic or Zod object, which the SDKs automatically convert to JSON Schema. The SDKs also manage the deserialization of JSON responses into typed data structures and handle potential refusals.
Our newest GPT-4o model is 50% cheaper for input tokens and 33% cheaper for output tokens.
It also supports Structured Outputs, which ensures model outputs exactly match your JSON Schemas. pic.twitter.com/9HXp5UAHth
Developers wanting to get started with Structured Outputs can check out OpenAI’s docs here.
“`html
(Photo by Growtika)
See also: Hugging Face partners with NVIDIA to democratise AI inference
Want to learn more about AI and big data from industry leaders? Check out AI & Big Data Expo taking place in Amsterdam, California, and London. The comprehensive event is co-located with other leading events including Intelligent Automation Conference, BlockX, Digital Transformation Week, and Cyber Security & Cloud Expo.
Explore other upcoming enterprise technology events and webinars powered by TechForge here.
“`
Welcome to DediRock, your trusted partner in high-performance hosting solutions. At DediRock, we specialize in providing dedicated servers, VPS hosting, and cloud services tailored to meet the unique needs of businesses and individuals alike. Our mission is to deliver reliable, scalable, and secure hosting solutions that empower our clients to achieve their digital goals. With a commitment to exceptional customer support, cutting-edge technology, and robust infrastructure, DediRock stands out as a leader in the hosting industry. Join us and experience the difference that dedicated service and unwavering reliability can make for your online presence. Launch our website.