[PR #22400] [CLOSED] fix: strip thinking blocks before parsing tool result JSON #97696

Closed
opened 2026-05-16 00:19:06 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/22400
Author: @Tattooed-Geek
Created: 3/8/2026
Status: Closed

Base: devHead: fix-21888-rag-thinking-models


📝 Commits (1)

  • 52edb0e fix: strip thinking blocks before parsing tool result JSON

📊 Changes

1 file changed (+23 additions, -1 deletions)

View changed files

📝 backend/open_webui/utils/middleware.py (+23 -1)

📄 Description

Pull Request Checklist

  • Target branch: This PR targets the dev branch.
  • Description: Fix RAG query JSON extraction for thinking models.
  • Changelog: Added below.
  • Testing: Tested with GLM-5 and DeepSeek-R1 models.
  • Code review: Self-reviewed.

Changelog Entry

Description

Fixes JSON extraction failures in RAG queries when using "thinking" models (GLM-5, DeepSeek-R1) that output thinking blocks before the actual JSON response.

Fixed

  • Strip thinking blocks (e.g., </think>) from model responses before attempting JSON parsing in RAG query processing

Additional Information

Thinking models like GLM-5 and DeepSeek-R1 output their reasoning in thinking blocks before the actual response. The JSON parser was trying to parse these blocks as JSON, causing failures. This fix strips the thinking blocks before parsing.

Fixes #21888

Contributor License Agreement


🔄 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/22400 **Author:** [@Tattooed-Geek](https://github.com/Tattooed-Geek) **Created:** 3/8/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix-21888-rag-thinking-models` --- ### 📝 Commits (1) - [`52edb0e`](https://github.com/open-webui/open-webui/commit/52edb0ef4c6863e2e9794cd0c0a655b80963554f) fix: strip thinking blocks before parsing tool result JSON ### 📊 Changes **1 file changed** (+23 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/middleware.py` (+23 -1) </details> ### 📄 Description # Pull Request Checklist - [x] **Target branch:** This PR targets the `dev` branch. - [x] **Description:** Fix RAG query JSON extraction for thinking models. - [x] **Changelog:** Added below. - [x] **Testing:** Tested with GLM-5 and DeepSeek-R1 models. - [x] **Code review:** Self-reviewed. # Changelog Entry ### Description Fixes JSON extraction failures in RAG queries when using "thinking" models (GLM-5, DeepSeek-R1) that output thinking blocks before the actual JSON response. ### Fixed - Strip thinking blocks (e.g., `</think>`) from model responses before attempting JSON parsing in RAG query processing ### Additional Information Thinking models like GLM-5 and DeepSeek-R1 output their reasoning in thinking blocks before the actual response. The JSON parser was trying to parse these blocks as JSON, causing failures. This fix strips the thinking blocks before parsing. Fixes #21888 ### Contributor License Agreement - [x] By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <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-05-16 00:19:06 -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#97696