Error with too many enums in structured output

I’m using Vertex AI API with flash 2.5 model version 4-17 and running into an issue where I get the following error:
{‘code’: 400, ‘message’: ‘Request contains an invalid argument.’, ‘status’: ‘INVALID_ARGUMENT’}

I’ve traced it back to a list of enums in my structured output. When I reduce the list to just 3 options, everything works fine, but with ~100 options, it fails. The input size is around 6000 tokens. I also tried switching from enums to literals, but the error still occurs.

Has anyone encountered this before or found a workaround?

The error you’re encountering—400 Invalid Argument—is likely due to the number of enum values in your response schema.. Community feedback suggests that schemas with around 100 enum values can lead to this error however Gemini API doesn’t explicitly document a max number of enum values.

Try to reduce the number of enum values or use literal values instead of enums

I tried using Literals, and got the same error. Do you have an example of how it should be done?