Skip to content

fix: guard against IndexError/AttributeError on empty LLM choices (19 sites)#259

Open
qizwiz wants to merge 1 commit into
Alibaba-NLP:mainfrom
qizwiz:fix/guard-unguarded-llm-choices
Open

fix: guard against IndexError/AttributeError on empty LLM choices (19 sites)#259
qizwiz wants to merge 1 commit into
Alibaba-NLP:mainfrom
qizwiz:fix/guard-unguarded-llm-choices

Conversation

@qizwiz
Copy link
Copy Markdown

@qizwiz qizwiz commented May 17, 2026

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.

… 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.
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