500 Enums Limitation in Structured Output

Hi everybody!

I recently ran into an interesting and undocumented (afaik) limitation of Structured Output feature - a limit of 500 Enum values per schema.

Error message is the following:

openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'MyTemplate': Expected at most 500 enum values in total within a single schema when using structured outputs, but received 520. Consider reducing the number of enums, or use 'strict: false' to opt out of structured outputs.", 'type': 'invalid_request_error', 'param': 'response_format', 'code': None}}

I wonder what is the constraining factor behind this limitation (e.g. context window size)? Why the number 500 was chosen? Are there plans to increase this limit?

Finally, I think it is worth to document this limitation in Structured Output docs as currently it is only discoverable by exceeding it.

Hope this helps others and the limit gets increased!

8 Likes