[GH-ISSUE #23924] fix: Client-provided tools crash Ollama models without native tool support (returns null) #35640

Closed
opened 2026-04-25 09:48:12 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @pvyswiss on GitHub (Apr 21, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/23924

Bug Description

API clients that send tools and tool_choice (e.g., for title generation) crash Ollama models that don't support tools (DeepSeek R1). Open WebUI catches the exception but returns null, crashing the SDK.

Related to: #23917 (Bug 5)

Root Cause

API clients like @ai-sdk/openai-compatible automatically send tools if the caller supports them. Open WebUI passes these through to Ollama, which rejects them for models without tool support.

The except Exception handler logs at DEBUG level and falls through without returning a proper response. None is serialized as null.

Fix

Strip client-provided tools and tool_choice when the model doesn't have function_calling: "native":

if (
    form_data.get('tools')
    and model_info_params.get('function_calling') != 'native'
):
    form_data.pop('tools', None)
    form_data.pop('tool_choice', None)

Also upgrade error handler from log.debug to log.warning.

Impact

  • Web UI: None (Web UI tools use tools_dict in middleware)
  • API clients: Tools stripped gracefully; request proceeds as normal chat

File

backend/open_webui/main.py

Reproduction

curl -s -H "Authorization: Bearer $KEY" \
  -d '{"model":"deepseek-r1:32b","messages":[{"role":"user","content":"hi"}],"tools":[{"type":"function","function":{"name":"test","parameters":{"type":"object","properties":{}}}}],"stream":true}' \
  http://localhost:3000/api/chat/completions
# Result: null
Originally created by @pvyswiss on GitHub (Apr 21, 2026). Original GitHub issue: https://github.com/open-webui/open-webui/issues/23924 ## Bug Description API clients that send `tools` and `tool_choice` (e.g., for title generation) crash Ollama models that don't support tools (DeepSeek R1). Open WebUI catches the exception but returns `null`, crashing the SDK. Related to: #23917 (Bug 5) ## Root Cause API clients like `@ai-sdk/openai-compatible` automatically send `tools` if the caller supports them. Open WebUI passes these through to Ollama, which rejects them for models without tool support. The `except Exception` handler logs at DEBUG level and falls through without returning a proper response. `None` is serialized as `null`. ## Fix Strip client-provided `tools` and `tool_choice` when the model doesn't have `function_calling: "native"`: ```python if ( form_data.get('tools') and model_info_params.get('function_calling') != 'native' ): form_data.pop('tools', None) form_data.pop('tool_choice', None) ``` Also upgrade error handler from `log.debug` to `log.warning`. ## Impact - **Web UI**: None (Web UI tools use `tools_dict` in middleware) - **API clients**: Tools stripped gracefully; request proceeds as normal chat ## File `backend/open_webui/main.py` ## Reproduction ```bash curl -s -H "Authorization: Bearer $KEY" \ -d '{"model":"deepseek-r1:32b","messages":[{"role":"user","content":"hi"}],"tools":[{"type":"function","function":{"name":"test","parameters":{"type":"object","properties":{}}}}],"stream":true}' \ http://localhost:3000/api/chat/completions # Result: null ```
Author
Owner

@tjbck commented on GitHub (Apr 24, 2026):

Addressed in dev to forward relevant error messages.

<!-- gh-comment-id:4311230765 --> @tjbck commented on GitHub (Apr 24, 2026): Addressed in dev to forward relevant error messages.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#35640