Skip to content

fix: guard against empty choices and message=None in LLM response - #999

Open
qizwiz wants to merge 1 commit into
2noise:devfrom
qizwiz:fix/guard-unguarded-llm-choices
Open

fix: guard against empty choices and message=None in LLM response#999
qizwiz wants to merge 1 commit into
2noise:devfrom
qizwiz:fix/guard-unguarded-llm-choices

Conversation

@qizwiz

@qizwiz qizwiz commented May 18, 2026

Copy link
Copy Markdown

Problem

In tools/llm/llm.py, the LLM response is accessed without checking if choices is empty or message is None:

return completion.choices[0].message.content

This raises IndexError (empty choices) or AttributeError (message=None on filtered responses).

Fix

if not completion.choices or completion.choices[0].message is None:
    raise ValueError("LLM returned empty or filtered response")
return completion.choices[0].message.content

2 lines added, 0 deleted.

Detected by pact static analysis.

completion.choices[0].message.content raises IndexError when choices is
empty or AttributeError when message is None (filtered/refused content).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
github-actions Bot changed the base branch from main to dev May 18, 2026 00:04
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