Extra required key error in response format for JSON schema?

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", the json_schema field containing the schema definition, and the strict field set to true.

  • json_schema Level: This level includes the name of your schema, the schema definition, and the strict field. The strict field is set to true, meaning all properties are required.

  • schema Level: This level defines the actual JSON schema. It’s an object with two properties: table and component. Both properties are required, as specified in the required field.

  • table Level: This level is an object with two properties: name and columns. Both properties are required. The name is a string, and columns is an array of objects.

  • columns Level: This level is an array of objects. Each object has two properties: name and type. 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??

1 Like