Skip to content

fix: guard against empty/filtered LLM responses in groqclient#362

Open
qizwiz wants to merge 1 commit into
microsoft:masterfrom
qizwiz:fix/llm-response-unguarded
Open

fix: guard against empty/filtered LLM responses in groqclient#362
qizwiz wants to merge 1 commit into
microsoft:masterfrom
qizwiz:fix/llm-response-unguarded

Conversation

@qizwiz
Copy link
Copy Markdown

@qizwiz qizwiz commented May 18, 2026

What

Adds a null check in omnitool/gradio/agent/llm_utils/groqclient.py before accessing completion.choices[0].message.

Why

Two silent failure modes crash at this line:

  1. IndexErrorchoices is an empty list when the provider returns no completions
  2. AttributeErrorchoices[0].message is None when content is filtered (some providers return HTTP 200 with a filtered finish reason)

Fix

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

Detected by pact static analysis.

An empty choices list raises IndexError; a None message raises
AttributeError. Add a null check before accessing choices[0].message.
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