Skip to content

fix: guard against None message before accessing .content#1369

Open
qizwiz wants to merge 1 commit into
FoundationAgents:mainfrom
qizwiz:fix/llm-response-unguarded
Open

fix: guard against None message before accessing .content#1369
qizwiz wants to merge 1 commit into
FoundationAgents:mainfrom
qizwiz:fix/llm-response-unguarded

Conversation

@qizwiz

@qizwiz qizwiz commented May 18, 2026

Copy link
Copy Markdown

What

Extend two guard conditions in app/llm.py to also check choices[0].message is None before accessing .content.

Why

The existing guards:

if not response.choices or not response.choices[0].message.content:

protect against an empty choices list and empty/None content, but if choices[0].message is None (returned by some providers on content-filtered responses with HTTP 200, e.g. Gemini PROHIBITED_CONTENT), accessing .content raises AttributeError: 'NoneType' object has no attribute 'content' before the guard evaluates.

Fix

# Before:
if not response.choices or not response.choices[0].message.content:

# After:
if not response.choices or response.choices[0].message is None or not response.choices[0].message.content:

Both occurrences (~line 425 and ~line 595) are fixed. No behaviour change for well-formed responses.

The existing guards check response.choices[0].message.content but if
message itself is None (returned by some providers on content-filtered
responses with HTTP 200), this crashes with AttributeError before the
guard can fire. Extend both guard conditions to check message is None
first.
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.

1 participant