[GH-ISSUE #17860] issue: Bug: RAG Web Search fails with "cannot access local variable 'tool'" #57087

Closed
opened 2026-05-05 20:34:59 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @alexandrsuk on GitHub (Sep 28, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/17860

Check Existing Issues

  • I have searched for any existing and/or related issues.
  • I have searched for any existing and/or related discussions.
  • I am using the latest version of Open WebUI.

Installation Method

Docker

Open WebUI Version

v0.6.31

Ollama Version (if applicable)

ollama version is 0.12.3

Operating System

Windows 11 PRO, Docker Deskop v4.46.0, Ubuntu 20.04.6 LTS

Browser (if applicable)

Chrome v140.0.7339.186

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

After the AI prepares the tool call (e.g., browser.search), the Open WebUI backend should successfully execute the HTTP request to the configured web search tool (SearXNG).

The AI should then receive the search results from the tool and use them to formulate a factual, helpful answer to the user's question, without displaying an error message.

Actual Behavior

The AI correctly identifies the need for a web search and successfully prepares the tool call JSON, as seen in the UI (e.g., Spouštím browser.search... with the correct parameters).

However, the process then fails. The UI first displays a generic message "An error occurred while searching the web," immediately followed by the specific Python backend error: cannot access local variable 'tool' where it is not associated with a value.

The actual HTTP request to the configured SearXNG URL is never sent. The failure happens internally within the Open WebUI backend before the tool is dispatched.

Steps to Reproduce

Rozumím, tato část je nejdůležitější. Zde je podrobný návod krok za krokem, který můžete zkopírovat. Je napsaný v angličtině a obsahuje minimální docker-compose.yml, aby to mohli vývojáři snadno a rychle otestovat.

Steps to Reproduce
Prepare the environment: Create a directory with the following three files:

docker-compose.yml:

YAML

services:
ollama:
container_name: ollama
image: ollama/ollama:latest
restart: unless-stopped
ports:
- "11434:11434"
volumes:
- ollama_models:/root/.ollama

open-webui:
image: ghcr.io/open-webui/open-webui:latest
container_name: open-webui
restart: unless-stopped
ports:
- "8080:8080"
depends_on:
- ollama
- caddy
- searxng
environment:
- 'OLLAMA_BASE_URL=http://ollama:11434'
- 'WEBUI_SECRET_KEY=secret_key_for_testing'
- RAG_WEB_SEARCH=true
- RAG_WEB_SEARCH_ENGINE=searxng
- RAG_SEARXNG_API_URL=http://caddy:80/

caddy:
container_name: caddy
image: caddy:2-alpine
restart: unless-stopped
ports:
- "8087:80"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro

searxng:
image: searxng/searxng:latest
container_name: searxng
restart: unless-stopped
volumes:
- ./searxng:/etc/searxng:rw
depends_on:
- caddy

volumes:
ollama_models: {}
open-webui: {}
Caddyfile:

Fragment kódu

:80 {
reverse_proxy searxng:8080
}
searxng/settings.yml: (Nezapomeňte vytvořit podadresář searxng a v něm tento soubor)

YAML

server:
secret_key: "a_very_random_secret_key_for_testing"
use_forwarded_for: true
search:
formats:
- html
- json
Start the services: In the directory containing the files, run the command:

Bash

docker-compose up -d --build
Set up Open WebUI:

Open your browser to http://localhost:8080.

Create an admin account.

Pull a model if necessary (e.g., from Ollama library, or use a model like gpt-oss:20b).

Start a new chat.

Trigger the Bug:

Ask a question that requires a web search, for example:
What is the current weather in Prague?

Observe the Error:

The AI will respond with "An error occurred while searching the web" followed by the Python error cannot access local variable 'tool' where it is not associated with a value.

Logs & Screenshots

I am providing a screenshot of the user interface right after the error occurs. It shows the AI's attempt to use the tool and the resulting UnboundLocalError.

Additionally, I am providing the relevant logs from the open-webui container, which show the full traceback for the cannot access local variable 'tool' where it is not associated with a value error.

Samozřejmě. Tato část je pro vývojáře klíčová, protože jim poskytne konkrétní důkazy o chybě.

Zde je text, který můžete zkopírovat a vložit. Přesně popisuje, jaké materiály přikládáte.

Logs and Screenshots
I am providing a screenshot of the user interface right after the error occurs. It shows the AI's attempt to use the tool and the resulting UnboundLocalError.

Additionally, I am providing the relevant logs from the open-webui container, which show the full traceback for the cannot access local variable 'tool' where it is not associated with a value error.

Screenshot of the UI:
Image

Relevant logs from the open-webui container:

log-open-webui-001.txt

Additional Information

Jasně, zde je text, který můžete zkopírovat a vložit do sekce "Additional Information". Stručně a jasně shrnuje kontext, který pomůže vývojářům rychleji pochopit problém.

Additional Information
The self-hosted SearXNG instance is fully functional and has been tested independently. It works correctly when accessed directly via its URL (http://localhost:8087). The logs for the searxng container show a successful startup and do not indicate any errors when receiving requests.

The error cannot access local variable 'tool' appears to be happening entirely within the Open WebUI backend. Based on the logs and the UI feedback, the failure occurs after the AI has decided which tool to use and has prepared the parameters, but before the actual HTTP request is dispatched to the searxng service via Caddy.

This suggests the issue is not related to network connectivity or the SearXNG configuration itself, but rather an internal bug in the tool-dispatching logic within Open WebUI, likely related to the RAG web search implementation.

Originally created by @alexandrsuk on GitHub (Sep 28, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/17860 ### 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 am using the latest version of Open WebUI. ### Installation Method Docker ### Open WebUI Version v0.6.31 ### Ollama Version (if applicable) ollama version is 0.12.3 ### Operating System Windows 11 PRO, Docker Deskop v4.46.0, Ubuntu 20.04.6 LTS ### Browser (if applicable) Chrome v140.0.7339.186 ### 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 After the AI prepares the tool call (e.g., browser.search), the Open WebUI backend should successfully execute the HTTP request to the configured web search tool (SearXNG). The AI should then receive the search results from the tool and use them to formulate a factual, helpful answer to the user's question, without displaying an error message. ### Actual Behavior The AI correctly identifies the need for a web search and successfully prepares the tool call JSON, as seen in the UI (e.g., Spouštím browser.search... with the correct parameters). However, the process then fails. The UI first displays a generic message "An error occurred while searching the web," immediately followed by the specific Python backend error: cannot access local variable 'tool' where it is not associated with a value. The actual HTTP request to the configured SearXNG URL is never sent. The failure happens internally within the Open WebUI backend before the tool is dispatched. ### Steps to Reproduce Rozumím, tato část je nejdůležitější. Zde je podrobný návod krok za krokem, který můžete zkopírovat. Je napsaný v angličtině a obsahuje minimální docker-compose.yml, aby to mohli vývojáři snadno a rychle otestovat. Steps to Reproduce Prepare the environment: Create a directory with the following three files: docker-compose.yml: YAML services: ollama: container_name: ollama image: ollama/ollama:latest restart: unless-stopped ports: - "11434:11434" volumes: - ollama_models:/root/.ollama open-webui: image: ghcr.io/open-webui/open-webui:latest container_name: open-webui restart: unless-stopped ports: - "8080:8080" depends_on: - ollama - caddy - searxng environment: - 'OLLAMA_BASE_URL=http://ollama:11434' - 'WEBUI_SECRET_KEY=secret_key_for_testing' - RAG_WEB_SEARCH=true - RAG_WEB_SEARCH_ENGINE=searxng - RAG_SEARXNG_API_URL=http://caddy:80/ caddy: container_name: caddy image: caddy:2-alpine restart: unless-stopped ports: - "8087:80" volumes: - ./Caddyfile:/etc/caddy/Caddyfile:ro searxng: image: searxng/searxng:latest container_name: searxng restart: unless-stopped volumes: - ./searxng:/etc/searxng:rw depends_on: - caddy volumes: ollama_models: {} open-webui: {} Caddyfile: Fragment kódu :80 { reverse_proxy searxng:8080 } searxng/settings.yml: (Nezapomeňte vytvořit podadresář searxng a v něm tento soubor) YAML server: secret_key: "a_very_random_secret_key_for_testing" use_forwarded_for: true search: formats: - html - json Start the services: In the directory containing the files, run the command: Bash docker-compose up -d --build Set up Open WebUI: Open your browser to http://localhost:8080. Create an admin account. Pull a model if necessary (e.g., from Ollama library, or use a model like gpt-oss:20b). Start a new chat. Trigger the Bug: Ask a question that requires a web search, for example: What is the current weather in Prague? Observe the Error: The AI will respond with "An error occurred while searching the web" followed by the Python error cannot access local variable 'tool' where it is not associated with a value. ### Logs & Screenshots I am providing a screenshot of the user interface right after the error occurs. It shows the AI's attempt to use the tool and the resulting UnboundLocalError. Additionally, I am providing the relevant logs from the open-webui container, which show the full traceback for the cannot access local variable 'tool' where it is not associated with a value error. Samozřejmě. Tato část je pro vývojáře klíčová, protože jim poskytne konkrétní důkazy o chybě. Zde je text, který můžete zkopírovat a vložit. Přesně popisuje, jaké materiály přikládáte. Logs and Screenshots I am providing a screenshot of the user interface right after the error occurs. It shows the AI's attempt to use the tool and the resulting UnboundLocalError. Additionally, I am providing the relevant logs from the open-webui container, which show the full traceback for the cannot access local variable 'tool' where it is not associated with a value error. Screenshot of the UI: <img width="1002" height="527" alt="Image" src="https://github.com/user-attachments/assets/58e4b8e3-c4f9-4f64-93c6-af73c7c94aad" /> Relevant logs from the open-webui container: [log-open-webui-001.txt](https://github.com/user-attachments/files/22584626/log-open-webui-001.txt) ### Additional Information Jasně, zde je text, který můžete zkopírovat a vložit do sekce "Additional Information". Stručně a jasně shrnuje kontext, který pomůže vývojářům rychleji pochopit problém. Additional Information The self-hosted SearXNG instance is fully functional and has been tested independently. It works correctly when accessed directly via its URL (http://localhost:8087). The logs for the searxng container show a successful startup and do not indicate any errors when receiving requests. The error cannot access local variable 'tool' appears to be happening entirely within the Open WebUI backend. Based on the logs and the UI feedback, the failure occurs after the AI has decided which tool to use and has prepared the parameters, but before the actual HTTP request is dispatched to the searxng service via Caddy. This suggests the issue is not related to network connectivity or the SearXNG configuration itself, but rather an internal bug in the tool-dispatching logic within Open WebUI, likely related to the RAG web search implementation.
GiteaMirror added the bug label 2026-05-05 20:34:59 -05:00
Author
Owner

@tjbck commented on GitHub (Sep 28, 2025):

@alexandrsuk could you confirm if this is still the case with our latest dev branch?

<!-- gh-comment-id:3344194834 --> @tjbck commented on GitHub (Sep 28, 2025): @alexandrsuk could you confirm if this is still the case with our latest dev branch?
Author
Owner

@alexandrsuk commented on GitHub (Sep 29, 2025):

Yes this is happening to me on the latest Open Webui 0.6.31.

Image
<!-- gh-comment-id:3344616171 --> @alexandrsuk commented on GitHub (Sep 29, 2025): Yes this is happening to me on the latest Open Webui 0.6.31. <img width="1063" height="376" alt="Image" src="https://github.com/user-attachments/assets/539cf942-35cf-4938-b049-0645d8d21049" />
Author
Owner

@tjbck commented on GitHub (Sep 29, 2025):

requests.exceptions.InvalidURL: Failed to parse: http://caddy:80search

We're unable to reproduce your issue.

<!-- gh-comment-id:3344865385 --> @tjbck commented on GitHub (Sep 29, 2025): `requests.exceptions.InvalidURL: Failed to parse: http://caddy:80search` We're unable to reproduce your issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#57087