mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[PR #21133] [CLOSED] fix: reconstruct tool_calls from history to prevent model hallucinations #25943
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?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/21133
Author: @Yambr
Created: 2/3/2026
Status: ❌ Closed
Base:
main← Head:fix/tool-calls-reconstruction📝 Commits (1)
7f6e7c8fix: reconstruct tool_calls from history to prevent model hallucinations📊 Changes
2 files changed (+99 additions, -22 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+94 -0)📝
src/lib/utils/index.ts(+5 -22)📄 Description
Summary
Fixes #20600 - Tool call results not decoded from HTML entities before sending to LLM
This PR addresses a critical bug where models (especially Qwen3) hallucinate/fake tool calls as text after 2-3 iterations of actual tool use.
Root Cause
processDetails()converts<details type="tool_calls">to plain text with HTML-escaped entitiesremoveAllDetails()strips ALL<details>tags before sending to backendSolution
Frontend (
src/lib/utils/index.ts):removeAllDetails(): Add negative lookahead to preserve<details type="tool_calls">tagsprocessDetails(): Simplify to only removereasoningandcode_interpreterdetails, leavingtool_callsintactBackend (
backend/open_webui/utils/middleware.py):reconstruct_tool_messages()function to parse preserved<details type="tool_calls">tagstool_callsfield on assistant messagestoolrole messages with resultsHow It Works
<details type="tool_calls" id="..." name="..." arguments="..." result="...">in message contenttool_callsarraytool_call_idand result contentModel Compatibility
Testing
Related Issues
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.