[PR #20745] [CLOSED] fix: Decode HTML entities in tool call results before sending to LLM (#20600) #41388

Closed
opened 2026-04-25 13:38:33 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/20745
Author: @YuriNachos
Created: 1/17/2026
Status: Closed

Base: mainHead: fix-tool-call-html-entities-decoding


📝 Commits (5)

  • f84aad5 fix: handle None value for model capabilities in builtin_tools check
  • 0d4898f fix: handle None value for model capabilities in file_context check
  • 9772be0 fix: handle None value for capabilities in get_model_capability helper
  • 3d404ff fix: URL-encode OAuth client secrets to handle special characters
  • 3079444 fix: Decode HTML entities in tool call results before sending to LLM

📊 Changes

4 files changed (+13 additions, -14 deletions)

View changed files

📝 backend/open_webui/config.py (+6 -6)
📝 backend/open_webui/utils/middleware.py (+4 -6)
📝 backend/open_webui/utils/tools.py (+1 -1)
📝 src/lib/utils/index.ts (+2 -1)

📄 Description

Summary

Fixes #20600

When tool call results contain HTML entities like ", &, ',
they are not decoded before being sent to the LLM in subsequent conversation turns.

Root Cause

  1. Tool results are stored with HTML-escaped content in the database
  2. Messages retrieved from DB still contain HTML entities
  3. processDetails() in src/lib/utils/index.ts inserts the escaped content directly without decoding

Example: A tool result containing "{"results": ...} is sent to the LLM as-is instead of being decoded to "{"results": ...}

Changes

  • Modified src/lib/utils/index.ts
  • In processDetails() function (line 875-876), applied unescapeHtml() to tool call results before inserting them into messages
  • The unescapeHtml() function already existed in the file and uses DOMParser to decode HTML entities

Test

The fix ensures HTML entities are properly decoded:

  • ""
  • &&
  • ''
  • ''

Tool call results in multi-turn conversations now contain clean JSON instead of HTML-escaped content.

Checklist

  • Minimal fix focused on the issue
  • No new dependencies added (using existing unescapeHtml function)
  • Backward compatible
  • Fix matches the solution suggested in the issue

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/20745 **Author:** [@YuriNachos](https://github.com/YuriNachos) **Created:** 1/17/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix-tool-call-html-entities-decoding` --- ### 📝 Commits (5) - [`f84aad5`](https://github.com/open-webui/open-webui/commit/f84aad5f141ab769d4b75628f576c89c9ff88db9) fix: handle None value for model capabilities in builtin_tools check - [`0d4898f`](https://github.com/open-webui/open-webui/commit/0d4898fa40798e396c4deb2f9cc71b0b7d54baf4) fix: handle None value for model capabilities in file_context check - [`9772be0`](https://github.com/open-webui/open-webui/commit/9772be02cc1d4b4153a76fd15a12d07d47f8eb66) fix: handle None value for capabilities in get_model_capability helper - [`3d404ff`](https://github.com/open-webui/open-webui/commit/3d404ff87cac3d257c56ed1ef198ed5b8c142ecf) fix: URL-encode OAuth client secrets to handle special characters - [`3079444`](https://github.com/open-webui/open-webui/commit/3079444ab2f03123a9a7a4e0dc0e7fe135ea7452) fix: Decode HTML entities in tool call results before sending to LLM ### 📊 Changes **4 files changed** (+13 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/config.py` (+6 -6) 📝 `backend/open_webui/utils/middleware.py` (+4 -6) 📝 `backend/open_webui/utils/tools.py` (+1 -1) 📝 `src/lib/utils/index.ts` (+2 -1) </details> ### 📄 Description ## Summary Fixes #20600 When tool call results contain HTML entities like `&quot;`, `&amp;`, `&#x27;`, they are not decoded before being sent to the LLM in subsequent conversation turns. ## Root Cause 1. Tool results are stored with HTML-escaped content in the database 2. Messages retrieved from DB still contain HTML entities 3. `processDetails()` in src/lib/utils/index.ts inserts the escaped content directly without decoding Example: A tool result containing `&quot;{&quot;results&quot;: ...}` is sent to the LLM as-is instead of being decoded to `"{"results": ...}` ## Changes - Modified `src/lib/utils/index.ts` - In `processDetails()` function (line 875-876), applied `unescapeHtml()` to tool call results before inserting them into messages - The `unescapeHtml()` function already existed in the file and uses DOMParser to decode HTML entities ## Test The fix ensures HTML entities are properly decoded: - `&quot;` → `"` - `&amp;` → `&` - `&#x27;` → `'` - `&#x27;` → `'` Tool call results in multi-turn conversations now contain clean JSON instead of HTML-escaped content. ## Checklist - [x] Minimal fix focused on the issue - [x] No new dependencies added (using existing unescapeHtml function) - [x] Backward compatible - [x] Fix matches the solution suggested in the issue --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 13:38:33 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#41388