[GH-ISSUE #839] bug: unguarded OpenAI API response access crashes beifong news/podcast agent #13440

Closed
opened 2026-07-11 18:57:53 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @zavoryn on GitHub (May 25, 2026).
Original GitHub issue: https://github.com/Shubhamsaboo/awesome-llm-apps/issues/839

Bug Description

Three files in the beifong news/podcast multi-agent app access response.choices[0].message.content without first checking that choices is non-empty and content is not None.

This can cause:

  • IndexError when the API returns an empty choices list (e.g. content filter triggered, quota exceeded, or transient API error)
  • TypeError when json.loads() receives None instead of a string

Affected Files

File Line Pattern
processors/ai_analysis_processor.py 74 json.loads(response.choices[0].message.content)
utils/translate_podcast.py 48 response.choices[0].message.content
utils/get_articles.py 30 json.loads(resp.choices[0].message.content.strip())

Expected Behavior

The code should guard against an empty or null API response before accessing choices[0], similar to the fix applied in PR #820 for the DeepSeek API calls.

Fix

Add a guard before each access:

if not response.choices or response.choices[0].message.content is None:
    raise ValueError("Received empty or null response from OpenAI API")

I have a PR ready with the fix applied to all three files.

Originally created by @zavoryn on GitHub (May 25, 2026). Original GitHub issue: https://github.com/Shubhamsaboo/awesome-llm-apps/issues/839 ## Bug Description Three files in the `beifong` news/podcast multi-agent app access `response.choices[0].message.content` without first checking that `choices` is non-empty and `content` is not `None`. This can cause: - `IndexError` when the API returns an empty `choices` list (e.g. content filter triggered, quota exceeded, or transient API error) - `TypeError` when `json.loads()` receives `None` instead of a string ## Affected Files | File | Line | Pattern | |------|------|---------| | `processors/ai_analysis_processor.py` | 74 | `json.loads(response.choices[0].message.content)` | | `utils/translate_podcast.py` | 48 | `response.choices[0].message.content` | | `utils/get_articles.py` | 30 | `json.loads(resp.choices[0].message.content.strip())` | ## Expected Behavior The code should guard against an empty or null API response before accessing `choices[0]`, similar to the fix applied in PR #820 for the DeepSeek API calls. ## Fix Add a guard before each access: ```python if not response.choices or response.choices[0].message.content is None: raise ValueError("Received empty or null response from OpenAI API") ``` I have a PR ready with the fix applied to all three files.
Author
Owner

@carter-smalls commented on GitHub (May 25, 2026):

Seems like rate-limit trouble with OpenAI. A quick npx ai-doctor run can flag missing Retry-After handling and unsafe retry logic.

<!-- gh-comment-id:4534074180 --> @carter-smalls commented on GitHub (May 25, 2026): Seems like rate-limit trouble with OpenAI. A quick `npx ai-doctor` run can flag missing Retry-After handling and unsafe retry logic.
Author
Owner

@markseibal-png commented on GitHub (May 25, 2026):

Looks like a rate-limit problem on OpenAI. npx ai-doctor can surface missing Retry-After handling and unsafe retry logic.

<!-- gh-comment-id:4534182672 --> @markseibal-png commented on GitHub (May 25, 2026): Looks like a rate-limit problem on OpenAI. `npx ai-doctor` can surface missing Retry-After handling and unsafe retry logic.
Author
Owner

@Shubhamsaboo commented on GitHub (Jun 2, 2026):

Thanks for flagging this. The proposed fix in #840 was reviewed and closed without merging, so we're closing this issue to match. In get_articles.py the call is already wrapped in a try/except that falls back to [prompt.strip()], so an empty/None response is handled there rather than crashing. We're not planning to add the extra guards across the beifong utilities right now. If it shows up as a real crash in practice, we can revisit.


Generated by Claude Code

<!-- gh-comment-id:4607907704 --> @Shubhamsaboo commented on GitHub (Jun 2, 2026): Thanks for flagging this. The proposed fix in #840 was reviewed and closed without merging, so we're closing this issue to match. In `get_articles.py` the call is already wrapped in a `try/except` that falls back to `[prompt.strip()]`, so an empty/`None` response is handled there rather than crashing. We're not planning to add the extra guards across the beifong utilities right now. If it shows up as a real crash in practice, we can revisit. --- _Generated by [Claude Code](https://claude.ai/code)_
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/awesome-llm-apps#13440