fix(providers): guard against empty choices list in openai and deepseek providers - #6717
fix(providers): guard against empty choices list in openai and deepseek providers#6717Prabal864 wants to merge 1 commit into
Conversation
…ek providers An OpenAI-compatible backend can return HTTP 200 with an empty choices list (e.g. a content-filter block). Both providers indexed into choices[0] unconditionally, raising IndexError and failing the workflow step instead of degrading, same failure already fixed for grok/litellm/vllm in keephq#6710 and keephq#6705. Guard the access and fall back to an empty string.
|
@shahargl this duplicates #6716, which has been open against #6715 since 20 Aug and is linked from it.
Your call which one goes in, so here is the state of each. #6716 has run the full matrix. sqlite, postgres, integration and unit are all green. The one red job is One other thing worth flagging. The inline comment added here is a light rewording of the one in #6716, and the two test files reuse the helpers and test names from |
|
Fair point on the timing — #6716 was open and linked well before I got here, closing mine in favor of it. One clarification on the code overlap, since it's worth stating plainly: I mirrored the pattern from the merged grok fix (#6710), not from #6716 — I hadn't looked at #6716's diff until you flagged this. The wording is close because we're both paraphrasing the same source for the same bug, but a couple of things differ if you want to check — my except clause also catches AttributeError, and my test filenames follow grok's existing |
Fixes #6715.
Both the OpenAI and DeepSeek providers read
response.choices[0].message.contentwithout checking thatchoicesis non-empty. An OpenAI-compatible backend can return HTTP 200 with an emptychoiceslist (e.g. a content-filter block), which raisesIndexErrorand fails the workflow step instead of degrading — same failure already fixed for litellm/vllm in #6705 and for grok in #6710, these two providers weren't covered.Guards the access with try/except and falls back to an empty string, matching the grok/litellm/vllm behavior.
Added tests for both providers covering the empty-choices case and the normal-response case, mocking the OpenAI SDK client directly since these two providers go through the SDK rather than raw
requestscalls.