-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Fix: Handle missing 'choices' field in Azure OpenAI responses #13201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix: Handle missing 'choices' field in Azure OpenAI responses #13201
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
- Add defensive checks before accessing response_object['choices'] - Check if 'choices' key exists and is not None - Raise descriptive exception instead of KeyError - Add comprehensive tests for missing choices field scenarios - Fixes intermittent batch_completion failures with Azure OpenAI Fixes BerriAI#13139
11051a8
to
07ca0cf
Compare
how does this fix the problem?
18:03:20 - LiteLLM:INFO: utils.py:1260 - Wrapper: Completed Call, calling success_handler looking at the raw response, i can see choices exists |
I reported the issue, and I can confirm that the choices was indeed present in the response when failing. |
when will this be ready for review? |
Title
Fix: Handle missing 'choices' field in Azure OpenAI responses
Relevant issues
Fixes #13139
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/
directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit
Type
Bug Fix
Changes
This PR fixes a KeyError that occurs when Azure OpenAI returns responses without the 'choices' field during batch completion operations.
Root Cause
Azure OpenAI can return responses without the 'choices' field in certain error scenarios, such as:
prompt_filter_results
Implementation
Added defensive checks in
convert_dict_to_response.py
at three critical locations:convert_to_streaming_response_async
(lines 115-119)convert_to_streaming_response
(lines 188-192)convert_to_model_response_object
(lines 515-519)The checks verify that:
When either condition fails, the code now raises a descriptive exception with the response content instead of a KeyError.
Testing
Comprehensive tests were created to verify all edge cases:
All tests pass successfully, confirming the fix handles the intermittent failures reported in the issue.