[GH-ISSUE #841] bug: unguarded OpenAI API response access crashes memory tutorial apps #14233

Closed
opened 2026-07-12 22:16:19 -05:00 by GiteaMirror · 1 comment
Owner

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

Bug Description

Four apps in advanced_llm_apps/llm_apps_with_memory_tutorials/ 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 (content filter, quota exceeded, or transient error)
  • Silent None being passed to downstream code when message.content is None

Affected Files

File Line Usage
ai_arxiv_agent_memory/ai_arxiv_agent_memory.py 50 response.choices[0].message.content
ai_travel_agent_memory/travel_agent_memory.py 88 response.choices[0].message.content
llm_app_personalized_memory/llm_app_memory.py 55 response.choices[0].message.content
multi_llm_memory/multi_llm_memory.py 68, 77 response.choices[0].message.content

Fix

Add the same guard applied in PR #820 and PR #840 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 fixing all four files.

Originally created by @zavoryn on GitHub (May 25, 2026). Original GitHub issue: https://github.com/Shubhamsaboo/awesome-llm-apps/issues/841 ## Bug Description Four apps in `advanced_llm_apps/llm_apps_with_memory_tutorials/` 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 (content filter, quota exceeded, or transient error) - Silent `None` being passed to downstream code when `message.content` is `None` ## Affected Files | File | Line | Usage | |------|------|-------| | `ai_arxiv_agent_memory/ai_arxiv_agent_memory.py` | 50 | `response.choices[0].message.content` | | `ai_travel_agent_memory/travel_agent_memory.py` | 88 | `response.choices[0].message.content` | | `llm_app_personalized_memory/llm_app_memory.py` | 55 | `response.choices[0].message.content` | | `multi_llm_memory/multi_llm_memory.py` | 68, 77 | `response.choices[0].message.content` | ## Fix Add the same guard applied in PR #820 and PR #840 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 fixing all four files.
Author
Owner

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

Thanks for the detailed report. The proposed fix in #842 was reviewed and closed without merging, so we're closing this issue to match. The unguarded access is a minor defensive edge case (it only triggers on an empty choices list or None content from a content filter or quota), and we're not planning to add the guards across these tutorial apps right now. If it resurfaces as an actual crash in practice, we can revisit.


Generated by Claude Code

<!-- gh-comment-id:4607907524 --> @Shubhamsaboo commented on GitHub (Jun 2, 2026): Thanks for the detailed report. The proposed fix in #842 was reviewed and closed without merging, so we're closing this issue to match. The unguarded access is a minor defensive edge case (it only triggers on an empty `choices` list or `None` content from a content filter or quota), and we're not planning to add the guards across these tutorial apps right now. If it resurfaces as an actual 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#14233