[GH-ISSUE #21070] issue:AttributeError: 'str' object has no attribute 'get' in citation parser when web search fails #58039

Closed
opened 2026-05-05 22:14:04 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @bennixview on GitHub (Jan 31, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/21070

Check Existing Issues

  • I have searched for any existing and/or related issues.
  • I have searched for any existing and/or related discussions.
  • I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!).
  • I am using the latest version of Open WebUI.

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

  • I have read and followed all instructions in README.md.
  • I am using the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have provided every relevant configuration, setting, and environment variable used in my setup.
  • I have clearly listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc).
  • I have documented step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation. My steps:
  • Start with the initial platform/version/OS and dependencies used,
  • Specify exact install/launch/configure commands,
  • List URLs visited, user input (incl. example values/emails/passwords if needed),
  • Describe all options and toggles enabled or changed,
  • Include any files or environmental changes,
  • Identify the expected and actual result at each stage,
  • Ensure any reasonably skilled user can follow and hit the same issue.

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

  1. Configure web search with any search engine
  2. Trigger a web search query while the search API is unavailable or times out
  3. Observe the error in logs

Logs & Screenshots

Logs

2026-01-30 18:23:07.286 | ERROR | open_webui.utils.middleware:get_citation_source_from_tool_result:279

  • Error parsing tool result for search_web: 'str' object has no attribute 'get'

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 []

      if tool_name == "search_web":                                                                                 
          results = parsed  # Reuse parsed result                                                                   
          # ... rest of the code                                                                                    

This fix:

  • Is generic and covers all tools (search_web, query_knowledge_files, etc.)
  • Parses JSON only once (performance improvement)
  • Returns empty sources on error, allowing the chat to continue gracefully

Additional Information

Related but different issues:

  • #19733 - Bocha API format issue (different root cause)
  • #20936 - SearchResultWeb object issue (different root cause)

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

Originally created by @bennixview on GitHub (Jan 31, 2026). Original GitHub issue: https://github.com/open-webui/open-webui/issues/21070 ### Check Existing Issues - [x] I have searched for any existing and/or related issues. - [x] I have searched for any existing and/or related discussions. - [x] I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!). - [x] I am using the latest version of Open WebUI. ### 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 - [x] I have read and followed all instructions in `README.md`. - [x] I am using the latest version of **both** Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have **provided every relevant configuration, setting, and environment variable used in my setup.** - [x] I have clearly **listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup** (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc). - [x] I have documented **step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation**. My steps: - Start with the initial platform/version/OS and dependencies used, - Specify exact install/launch/configure commands, - List URLs visited, user input (incl. example values/emails/passwords if needed), - Describe all options and toggles enabled or changed, - Include any files or environmental changes, - Identify the expected and actual result at each stage, - Ensure any reasonably skilled user can follow and hit the same issue. ### 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 1. Configure web search with any search engine 2. Trigger a web search query while the search API is unavailable or times out 3. Observe the error in logs ### Logs & Screenshots Logs 2026-01-30 18:23:07.286 | ERROR | open_webui.utils.middleware:get_citation_source_from_tool_result:279 - Error parsing tool result for search_web: 'str' object has no attribute 'get' ### 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 [] if tool_name == "search_web": results = parsed # Reuse parsed result # ... rest of the code This fix: - Is generic and covers all tools (search_web, query_knowledge_files, etc.) - Parses JSON only once (performance improvement) - Returns empty sources on error, allowing the chat to continue gracefully Additional Information Related but different issues: - #19733 - Bocha API format issue (different root cause) - #20936 - SearchResultWeb object issue (different root cause) 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
GiteaMirror added the bug label 2026-05-05 22:14:04 -05:00
Author
Owner

@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:

  1. #19733 issue: AttributeError: 'str' object has no attribute 'get' when using Bocha search engine
    by Sorkai • Dec 04, 2025 • bug

  2. #20936 issue: Error in External search: 'SearchResultWeb' object has no attribute 'get'
    by freeNestor • Jan 26, 2026 • bug


💡 Tips:

  • If this is a duplicate, please consider closing this issue and adding any additional details to the existing one
  • If you found a solution in any of these issues, please share it here to help others

This comment was generated automatically by a bot. Please react with a 👍 if this comment was helpful, or a 👎 if it was not.

<!-- gh-comment-id:3828638399 --> @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: 1. [#19733](https://github.com/open-webui/open-webui/issues/19733) **issue: AttributeError: 'str' object has no attribute 'get' when using Bocha search engine** *by Sorkai • Dec 04, 2025 • `bug`* 2. [#20936](https://github.com/open-webui/open-webui/issues/20936) **issue: Error in External search: 'SearchResultWeb' object has no attribute 'get'** *by freeNestor • Jan 26, 2026 • `bug`* --- 💡 **Tips:** - If this is a duplicate, please consider closing this issue and adding any additional details to the existing one - If you found a solution in any of these issues, please share it here to help others *This comment was generated automatically by a bot.* Please react with a 👍 if this comment was helpful, or a 👎 if it was not.
Author
Owner

@bennixview commented on GitHub (Jan 31, 2026):

Here is a possible PR : https://github.com/open-webui/open-webui/pull/21071

<!-- gh-comment-id:3828695156 --> @bennixview commented on GitHub (Jan 31, 2026): Here is a possible PR : https://github.com/open-webui/open-webui/pull/21071
Author
Owner

@bennixview commented on GitHub (Feb 1, 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:

  1. #19733 issue: AttributeError: 'str' object has no attribute 'get' when using Bocha search engine
    by Sorkai • Dec 04, 2025 • bug
  2. #20936 issue: Error in External search: 'SearchResultWeb' object has no attribute 'get'
    by freeNestor • Jan 26, 2026 • bug

💡 Tips:

  • If this is a duplicate, please consider closing this issue and adding any additional details to the existing one
  • If you found a solution in any of these issues, please share it here to help others

This comment was generated automatically by a bot. Please react with a 👍 if this comment was helpful, or a 👎 if it was not.

Both seemes to be something else. Here is a possible PR : https://github.com/open-webui/open-webui/pull/21071

<!-- gh-comment-id:3830951778 --> @bennixview commented on GitHub (Feb 1, 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: > > 1. [#19733](https://github.com/open-webui/open-webui/issues/19733) **issue: AttributeError: 'str' object has no attribute 'get' when using Bocha search engine** > _by Sorkai • Dec 04, 2025 • `bug`_ > 2. [#20936](https://github.com/open-webui/open-webui/issues/20936) **issue: Error in External search: 'SearchResultWeb' object has no attribute 'get'** > _by freeNestor • Jan 26, 2026 • `bug`_ > > 💡 **Tips:** > > * If this is a duplicate, please consider closing this issue and adding any additional details to the existing one > * If you found a solution in any of these issues, please share it here to help others > > _This comment was generated automatically by a bot._ Please react with a 👍 if this comment was helpful, or a 👎 if it was not. Both seemes to be something else. Here is a possible PR : https://github.com/open-webui/open-webui/pull/21071
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#58039