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.
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.
## 📋 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>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/22400
Author: @Tattooed-Geek
Created: 3/8/2026
Status: ❌ Closed
Base:
dev← Head:fix-21888-rag-thinking-models📝 Commits (1)
52edb0efix: 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
devbranch.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
</think>) from model responses before attempting JSON parsing in RAG query processingAdditional 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.