fix: guard against IndexError/AttributeError on empty LLM choices (19 sites)#259
Open
qizwiz wants to merge 1 commit into
Open
fix: guard against IndexError/AttributeError on empty LLM choices (19 sites)#259qizwiz wants to merge 1 commit into
qizwiz wants to merge 1 commit into
Conversation
… sites)
LLM APIs (OpenAI-compatible) can return HTTP 200 with an empty choices list
on content filtering, provider errors, or quota limits — the SDK does NOT
raise, causing IndexError. Gemini 2.5 Flash additionally returns
choices[0].message=None on PROHIBITED_CONTENT (finish_reason: content_filter),
causing AttributeError: 'NoneType' object has no attribute 'content'.
Guards added to 17 files across inference/ and WebAgent/:
inference/react_agent.py, inference/tool_visit.py,
inference/file_tools/video_analysis.py,
WebAgent/WebWeaver/{react_agent_outline_write,react_agent_search_id,tool/tool_retrieve}.py,
WebAgent/AgentFold/infer.py,
WebAgent/WebSailor/src/{react_agent,tool_visit,evaluate}.py,
WebAgent/WebResummer/src/{react_agent,tool_visit}.py,
WebAgent/WebWatcher/infer/scripts_eval/agent_eval.py,
WebAgent/WebWatcher/.../qwen_agent/tools/private/visit.py,
WebAgent/WebWalker/src/{rag_system,agent}.py,
WebAgent/WebDancer/demos/tools/private/visit.py
Found by pact (https://github.com/qizwiz/pact) static analysis, mode: llm_response_unguarded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LLM APIs (OpenAI-compatible) can return HTTP 200 with an empty choices list or choices[0].message=None — SDK does NOT raise. 17 files, 19 guard sites. Found by pact static analysis.