API rejects valid JSON schema

I’m trying to get it to generate valid Vega-Lite chart definitions using the new Structured Outputs JSON Schema. If I feed it the JSON Schema directly from the schema they provide, it complains:

Invalid schema for response_format ‘Vega-Lite’: schema must be a JSON Schema of ‘type: "object"’, got ‘type: "None"’.

This is easy to fix, I just injected "type": "object" in the root of the schema.

After that, it gives a different error:

Invalid schema for response_format ‘Vega-Lite’: In context=(), ‘required’ is required to be supplied and to be an array including every key in properties. Missing ‘groupby’

The part its complaining about happens early in the schema:

"AggregateTransform": {
  "additionalProperties": false,
  "properties": {
    "aggregate": {
      "description": "Array of objects that define fields to aggregate.",
      "items": {"$ref": "#/definitions/AggregatedFieldDef"},
      "type": "array"
    },
    "groupby": {
      "description": "The data fields to group by. If not specified, a single group containing all data objects will be used.",
      "items": {"$ref": "#/definitions/FieldName"},
      "type": "array"
    }
  },
  "required": ["aggregate"],
  "type": "object"
},

I can fix that by adding “groupby” to the “required” array, but then it complains about the same thing in the next definition, and this isn’t the right approach anyways. It seems the API is insisting that every property be required, even when it isn’t required by the schema.

Is there a way to convince the API that this schema is valid, or is there a bug that its rejecting valid schemas?

TIA

1 Like

Looks like it’s in the docs:

All fields must be required
Although all fields must be required (and the model will return a value for each parameter), it is possible to emulate an optional parameter by using a union type with null.

https://platform.openai.com/docs/guides/structured-outputs/supported-schemas

There’s also this:

A schema may have up to 100 object properties total, with up to 5 levels of nesting.

So the chances of a 3rd-party generated schema working out-of-the-box with this are pretty slim.

1 Like