Tuesday, September 17, 2024

OpenAI API: Structured Outputs (JSON "schema")

 Structured Outputs - OpenAI API

Structured Outputs is available in two forms in the OpenAI API:

  1. When using function calling
  2. When using a json_schema response format
Structured Outputs via response_format are more suitable when you want to indicate a structured schema for use when the model responds to the user, rather than when the model calls a tool.

Structured Outputs with response_format: {type: "json_schema", ...} is only supported with the gpt-4o-minigpt-4o-mini-2024-07-18, and gpt-4o-2024-08-06 model snapshots and later.



Pydantic is the most widely used data validation library for Python.

The name "Pydantic" is a portmanteau of "Py" and "pedantic."


TypeScript-first schema validation with static type inference


JSON mode is a more basic version of the Structured Outputs feature. While JSON mode ensures that model output is valid JSON, Structured Outputs reliably matches the model's output to the schema you specify.


Structured Outputs supports a subset of the JSON Schema language.

The following types are supported for Structured Outputs:

  • String
  • Number
  • Boolean
  • Integer
  • Object
  • Array
  • Enum
  • anyOf

No comments:

Post a Comment