Skip to content

fix(providers): handle empty choices array defensively (#6715) - #6817

Open
MyDude92 wants to merge 2 commits into
keephq:mainfrom
MyDude92:fix-empty-choices-6715
Open

MyDude92 wants to merge 2 commits into
keephq:mainfrom
MyDude92:fix-empty-choices-6715

Conversation

@MyDude92

Copy link
Copy Markdown

Description

Resolves #6715.

Defensively handles scenarios where the OpenAI or DeepSeek API returns an empty choices list (e.g. content filtering, moderation blocks, or blank completions) instead of throwing an unhandled IndexError: list index out of range.

Changes Made

  • Added defensive check: if response and response.choices and len(response.choices) > 0:
  • Gracefully falls back to empty string "" matching existing provider patterns.
  • Applied to both openai_provider.py and deepseek_provider.py.

Checklist

@CLAassistant

CLAassistant commented Sep 12, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openai and deepseek providers crash on an empty choices list

2 participants