The JSON schema you provided seems to be well-structured and adheres to the JSON schema standards. However, it’s missing the root structure documented for the OpenAI API’s response_format
parameter.
{
"type": "json_schema",
"json_schema": {
"name": "your_schema_name",
"schema": {
// Your JSON Schema definition
},
"strict": true // or false
}
}
Here’s how you can wrap your schema to meet the OpenAI API requirements:
{
"type": "json_schema",
"json_schema": {
"name": "table_component",
"schema": {
"type": "object",
"properties": {
"table": {
"type": "object",
"properties": {
"name": {"type" : "string"},
"columns": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name" : {"type" : "string"},
"type" : {"type" : "string"}
},
"required" : ["name", "type"],
"additionalProperties" : False
}
}
},
"required": ["name", "columns"],
"additionalProperties" : False
},
"component" : {"type": "object"}
},
"required" : ["component","table"],
"additionalProperties" : False
},
"strict": true
}
}
This structure now meets the OpenAI API requirements for the response_format
parameter.
Let’s break down the schema:
-
Root Level: The root level of the schema is an object, as required. It includes the
type
field set to"json_schema"
, thejson_schema
field containing the schema definition, and thestrict
field set totrue
. -
json_schema
Level: This level includes thename
of your schema, theschema
definition, and thestrict
field. Thestrict
field is set totrue
, meaning all properties are required. -
schema
Level: This level defines the actual JSON schema. It’s an object with two properties:table
andcomponent
. Both properties are required, as specified in therequired
field. -
table
Level: This level is an object with two properties:name
andcolumns
. Both properties are required. Thename
is a string, andcolumns
is an array of objects. -
columns
Level: This level is an array of objects. Each object has two properties:name
andtype
. Both properties are required and are strings. -
component
Level: This level is an object. However, it doesn’t specify any properties, so it can contain any valid JSON object.
Remember, the strict
field being set to true
means that all properties are required. An object like "component"
being empty makes no sense for a structured schema. If you want to make some properties optional or free-running, you would need to set strict
to false
and adjust the required
fields accordingly.
(not a question that gpt-4o can answer correctly.)
Two people sending the exact same schemas??