# Extra required key error in response format for JSON schema?

**URL:** <https://community.openai.com/t/extra-required-key-error-in-response-format-for-json-schema/970694>\
**Category:** API\
**Tags:** fine-tuning\
**Created:** [October 7, 2024, 6:54pm UTC](https://community.openai.com/t/extra-required-key-error-in-response-format-for-json-schema/970694 "2024-10-07T18:54:26Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [October 12, 2024, 4:53pm UTC](https://community.openai.com/t/extra-required-key-error-in-response-format-for-json-schema/970694/3 "2024-10-12T16:53:29Z")

</div>

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.

```json
{
  "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:

```json
{
  "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.)

> [@wolsen](#):
>
> I am having the exact same issue

Two people sending the exact same schemas??

---

_[View the full topic](https://community.openai.com/t/extra-required-key-error-in-response-format-for-json-schema/970694)._
