Skip to content

issue: Built-in search_web tool ignores WEB_SEARCH_RESULT_COUNT admin setting (hardcoded count=5) #21371

@sewasti

Description

@sewasti

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

Ollama Version (if applicable)

No response

Operating System

Linux (Debian 11 bullseye)

Browser (if applicable)

Version 144.0.7559.133

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

The built-in search_web tool (used in Native Function Calling mode) should respect
the admin setting WEB_SEARCH_RESULT_COUNT (Admin → Settings → Web Search →
Search Result Count). When set to 10, web searches should return 10 results.

Actual Behavior

The built-in search_web tool always returns exactly 5 results, regardless of
the admin WEB_SEARCH_RESULT_COUNT setting.

Confirmed via API that the admin setting IS correctly stored:

GET /api/v1/retrieval/config → WEB_SEARCH_RESULT_COUNT: 10 ✅

But in Native Function Calling mode, only 5 sources are ever returned.

Steps to Reproduce

  1. Install Open WebUI v0.8.0 via Docker.
  2. Configure a web search engine (e.g. Tavily with API key in Admin → Settings → Web Search).
  3. Set Search Result Count to 10 in Admin → Settings → Web Search.
  4. Verify setting via API:
    curl -H "Authorization: Bearer " http://localhost:8080/api/v1/retrieval/config | jq '.web.WEB_SEARCH_RESULT_COUNT'
    → should return 10.
  5. Configure a model to use Native Function Calling mode:
    Admin → Chat Controls → Function Calling Mode → "Native".
  6. Start a new chat and ask the model to search the web for any topic, e.g.:
    "Search the web for the latest news about AI regulation in the EU"
  7. Observe: the model returns exactly 5 sources, not the configured 10.
  8. This is 100% reproducible — every single web search returns exactly 5 results.

Logs & Screenshots

No runtime errors in browser console or Docker logs. The bug is in the source code.

Root Cause in open_webui/tools/builtin.py (lines ~148-173):

async def search_web(
    query: str,
    count: int = 5,   # ← hardcoded default, ignores admin WEB_SEARCH_RESULT_COUNT
    __request__: Request = None,
    __user__: dict = None,
) -> str:
    ...
    results = await asyncio.to_thread(_search_web, __request__, engine, query, user)
    results = results[:count]  # ← re-truncates results to 5

The underlying _search_web() in routers/retrieval.py correctly uses the admin setting
request.app.state.config.WEB_SEARCH_RESULT_COUNT for the search engine API call
(e.g. Tavily receives max_results=10 and returns 10 results).

But then builtin.py re-truncates with results[:count], where count defaults to 5
because LLMs typically call search_web(query="...") without passing the count parameter.

This is a double-truncation bug: the backend fetches the correct number, but the
tool function silently discards the extra results.

Additional Information

Suggested Fix

Option A (simplest): Remove the [:count] truncation in builtin.py, since
_search_web() already applies the admin limit via the search engine API:

results = await asyncio.to_thread(_search_web, __request__, engine, query, user)
# results = results[:count]  ← remove this line, backend already limits

Option B: Use the admin config as the effective default:

if __request__:
    admin_count = getattr(__request__.app.state.config, 'WEB_SEARCH_RESULT_COUNT', 5)
    count = max(count, admin_count)
results = results[:count]

Scope

  • Only affects the Native Function Calling path (built-in tools in builtin.py).
  • Classic web search (middleware-based chat_web_search_handler) correctly uses the admin setting.
  • Tested with Tavily search engine; the issue is engine-agnostic (same code path for all engines).

Workaround

Add a system prompt instruction: "When using the search_web tool, always pass count=10."
This forces the LLM to explicitly pass the parameter instead of using the hardcoded default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions