mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[PR #21135] [CLOSED] fix: reconstruct tool_calls from history to prevent model hallucinations #64800
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/21135
Author: @Yambr
Created: 2/3/2026
Status: ❌ Closed
Base:
dev← Head:fix/tool-calls-reconstruction📝 Commits (1)
f5ea795fix: reconstruct tool_calls from history to prevent model hallucinations📊 Changes
2 files changed (+139 additions, -22 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+134 -0)📝
src/lib/utils/index.ts(+5 -22)📄 Description
Pull Request Checklist
devfix:Changelog Entry
Description
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:
<details type="tool_calls">tagsreconstruct_tool_messages()to reconstruct OpenAI formatAdded
reconstruct_tool_messages()function inbackend/open_webui/utils/middleware.pyto parse<details type="tool_calls">tags and reconstruct proper OpenAI-compatible message structureChanged
removeAllDetails()insrc/lib/utils/index.ts: Added negative lookahead to preserve<details type="tool_calls">tagsprocessDetails()insrc/lib/utils/index.ts: Simplified to only removereasoningandcode_interpreterdetails, leavingtool_callsintactFixed
How It Works
<details type="tool_calls" id="..." name="..." arguments="..." result="...">in message contentreconstruct_tool_messages()tool_callsarraytool_call_idand result contentTesting Steps
Related Issues
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.