Support top-level array in JSON schema

I always want the GPT API to be able to return a JSON array instead of an object. There are many normal use cases where I expect the LLM to extract a list of things.

I tried the latest Structured Output feature and was disappointed this is still not supported:

openai.BadRequestError: Error code: 400 - {'error': {'message': 'Invalid schema for response_format \'PolicyStatements\': schema must be a JSON Schema of \'type: "object"\', got \'type: "array"\'.', 'type': 'invalid_request_error', 'param': 'response_format', 'code': None}}

I know I can always put the array into a single-key object, but it’s just so annoying I also have to modify the prompts to accomodate this.

Is there any practical reason not to support this?

1 Like