mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[GH-ISSUE #21070] issue:AttributeError: 'str' object has no attribute 'get' in citation parser when web search fails #58039
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @bennixview on GitHub (Jan 31, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/21070
Check Existing Issues
Installation Method
Docker
Open WebUI Version
0.7.2
Ollama Version (if applicable)
AWS Bedrock via Bedrock Access Gateway
Operating System
alpine linux
Browser (if applicable)
Safari
Confirmation
README.md.Expected Behavior
When web search fails (timeout, API error, etc.), the chat should continue gracefully without crashing. The error should be logged but not cause an exception in the citation parser.
Actual Behavior
When all search engines timeout or fail, search_web in builtin.py returns {"error": "..."} (a dict). The citation parser in middleware.py expects a list and iterates over the result. When iterating over a dict, Python yields the keys (strings), causing AttributeError: 'str' object has no attribute 'get'.
Steps to Reproduce
Logs & Screenshots
Logs
2026-01-30 18:23:07.286 | ERROR | open_webui.utils.middleware:get_citation_source_from_tool_result:279
Additional Information
Root Cause Analysis
In backend/open_webui/tools/builtin.py:178-180:
except Exception as e:
log.exception(f"search_web error: {e}")
return json.dumps({"error": str(e)}) # Returns dict, not list!
In backend/open_webui/utils/middleware.py:163-170:
if tool_name == "search_web":
results = json.loads(tool_result) # {"error": "..."} on failure
for result in results: # Iterates over dict keys → "error"
title = result.get("title", "") # "error".get() → AttributeError!
Proposed Fix
Add generic error detection at the start of get_citation_source_from_tool_result since all builtin tools return
{"error": ...} on failure:
def get_citation_source_from_tool_result(...):
try:
# Handle error responses from tools - all builtin tools return {"error": ...} on failure
parsed = json.loads(tool_result)
if isinstance(parsed, dict) and "error" in parsed:
return []
This fix:
Additional Information
Related but different issues:
I'm happy to submit a PR with this fix if desired.
Alternative Solutions (Root Cause Fix)
The proposed fix above is defensive - it handles the symptom in the caller. A cleaner solution would fix the source in
builtin.py to ensure consistent return types.
Option A: Always return a list (recommended for tools)
Since these are LLM tool functions, a consistent return type makes parsing easier:
In builtin.py search_web()
except Exception as e:
log.exception(f"search_web error: {e}")
return json.dumps([]) # Empty list instead of error dict
Pros: Consistent API, no caller changes needed, LLM sees empty results
Cons: Error details are lost (only logged)
Option B: Return error inside the list
except Exception as e:
log.exception(f"search_web error: {e}")
return json.dumps([{"error": str(e)}]) # Error as list item
@owui-terminator[bot] commented on GitHub (Jan 31, 2026):
🔍 Similar Issues Found
I found some existing issues that might be related to this one. Please check if any of these are duplicates or contain helpful solutions:
#19733 issue: AttributeError: 'str' object has no attribute 'get' when using Bocha search engine
by Sorkai • Dec 04, 2025 •
bug#20936 issue: Error in External search: 'SearchResultWeb' object has no attribute 'get'
by freeNestor • Jan 26, 2026 •
bug💡 Tips:
This comment was generated automatically by a bot. Please react with a 👍 if this comment was helpful, or a 👎 if it was not.
@bennixview commented on GitHub (Jan 31, 2026):
Here is a possible PR : https://github.com/open-webui/open-webui/pull/21071
@bennixview commented on GitHub (Feb 1, 2026):
Both seemes to be something else. Here is a possible PR : https://github.com/open-webui/open-webui/pull/21071