Fix #604 Chat Completion model raises runtime error when response.choices is empty - #935
Merged
Merged
Conversation
Member
Author
|
now this is ready for reviews |
rm-openai
approved these changes
Jun 25, 2025
seratch
force-pushed
the
issue-604-chat-completions-runtime-error
branch
from
June 25, 2025 23:26
951b9c7 to
403aeea
Compare
gn00295120
added a commit
to gn00295120/openai-agents-python
that referenced
this pull request
Oct 22, 2025
Add defensive checks before accessing response.choices[0] to prevent IndexError when Gemini or other providers return an empty choices array. This follows the same pattern as PR openai#935 which fixed the identical issue in openai_chatcompletions.py. Changes: - Add null checks for response.choices before array access - Return empty output when choices array is empty - Preserve usage information even when choices is empty - Add appropriate type annotations for litellm types
This was referenced Oct 22, 2025
gn00295120
added a commit
to gn00295120/openai-agents-python
that referenced
this pull request
Oct 24, 2025
Add defensive checks before accessing response.choices[0] to prevent IndexError when Gemini or other providers return an empty choices array. This follows the same pattern as PR openai#935 which fixed the identical issue in openai_chatcompletions.py. Changes: - Add null checks for response.choices before array access - Return empty output when choices array is empty - Preserve usage information even when choices is empty - Add appropriate type annotations for litellm types
seratch
pushed a commit
that referenced
this pull request
Oct 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request resolves #604; just checking the existence of the data and avoiding the runtime exception should make sense.