Skip to content

fix(browser): guard LLM response content against None in snapshot and vision#3532

Closed
binhnt92 wants to merge 1 commit intoNousResearch:mainfrom
binhnt92:fix/browser-tool-content-none-guard
Closed

fix(browser): guard LLM response content against None in snapshot and vision#3532
binhnt92 wants to merge 1 commit intoNousResearch:mainfrom
binhnt92:fix/browser-tool-content-none-guard

Conversation

@binhnt92
Copy link
Copy Markdown
Contributor

_extract_relevant_content and browser_vision in browser_tool.py both access response.choices[0].message.content without checking for None. Reasoning-only models (DeepSeek-R1, QwQ via OpenRouter) return content=None, which causes _extract_relevant_content to return None (making the snapshot null) and browser_vision to return {"success": true, "analysis": null}.

These two sites were missed when #3449 applied the (content or "").strip() guard across the other tool files.

Changes Made

File Line Fix
tools/browser_tool.py 996 _extract_relevant_content: guard + fall back to truncated snapshot
tools/browser_tool.py 1626 browser_vision: guard + fall back to descriptive message

How to Test

python3 -m pytest tests/tools/test_browser_content_none_guard.py -v

7 tests covering: None content fallback, normal content passthrough, empty string fallback, and source-line verification.

Checklist

  • Tests added (7 tests)
  • Full test suite run — no regressions
  • Tested on Linux (Ubuntu 22.04)

… vision

_extract_relevant_content and browser_vision both access
response.choices[0].message.content without a None check. Reasoning-only
models (DeepSeek-R1, QwQ via OpenRouter) return content=None, producing
null snapshots and null vision analysis.

Apply the same (content or "").strip() guard used across the rest of the
codebase since NousResearch#3449. For _extract_relevant_content, fall back to the
truncated snapshot. For browser_vision, fall back to a descriptive message.
teknium1 added a commit that referenced this pull request Mar 29, 2026
… vision (#3642)

Salvage of PR #3532 (binhnt92). Guards browser_tool.py against None content from reasoning-only models (DeepSeek-R1, QwQ). Follow-up to #3449.

Co-Authored-By: binhnt92 <[email protected]>
@teknium1
Copy link
Copy Markdown
Contributor

Merged via PR #3642. Cherry-picked onto current main with authorship preserved. All browser tests passing. Thanks for catching the remaining unguarded sites!

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.

2 participants