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

Open
opened 2026-05-31 13:51:07 -05:00 by GiteaMirror · 0 comments
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.
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#6487