
azure-openai
#10473
schema_validation_error
Invalid schema for response_format: Expected at most a specified number of enum values in total within a single schema when using structured outputs, but received an excess. Consider reducing the number of enums, or opt out of structured outputs by setting 'strict: false'.
This error has been identified and solved.
Reason
The 400 status error in the Azure OpenAI API, specifically related to the "Invalid schema for response_format," is likely due to the following reasons:
Exceeding Enum Value Limits
The error message indicates that the schema contains more than the allowed 500 enum values within a single schema when using structured outputs. This exceeds the predefined limit, leading to the "Bad Request" response.
Structured Output Constraints
The issue is tied to the use of structured outputs, which have specific constraints, such as the maximum number of enum values allowed in the schema. This constraint is in place to maintain the integrity and performance of the API.
Schema Complexity
The complexity of the schema, particularly the number of enum values and potentially other structural elements, is triggering the validation check that results in the 400 error.
Solution
To resolve the 400 status error in the Azure OpenAI API due to the "Invalid schema for response_format" issue, you need to address the exceeding enum value limit. Here are the steps to fix it:
Reduce the number of enum values in the schema to be within the 500-limit threshold.
Alternatively, use the
strict: false
option to opt out of structured outputs, which would relax the enum value constraints.Review and simplify the schema to ensure it complies with the API's structured output requirements.
By implementing these adjustments, you should be able to avoid the "Bad Request" error and successfully use the API.
Suggested Links
https://portkey.ai/error-library/prompt-error-10016
https://community.openai.com/t/error-invalid-schema-for-response-format/1075981
https://cheatsheet.md/chatgpt-cheatsheet/openai-api-error-axioserror-request-failed-status-code-400
https://www.googlecloudcommunity.com/gc/AI-ML/Unexpected-400-errors-with-Generated-Output-Schema/td-p/807575
https://learn.microsoft.com/en-us/answers/questions/1479386/azure-openai-api-calling-issue
https://community.openai.com/t/500-enums-limitation-in-structured-output/974416
https://github.com/instructor-ai/instructor/issues/961
https://learn.microsoft.com/hi-in/azure/ai-services/openai/quotas-limits