RAG query JSON extraction was failing with "thinking" models like GLM-5 and DeepSeek-R1 because these models output thinking blocks (e.g., <think>...</think>) before the actual JSON response. The parser tried to parse the thinking block as JSON, causing failures.
Changes
Strip thinking blocks from model responses before attempting JSON parsing in RAG query processing
Handles both <think>...</think> and similar thinking block patterns
Testing
Tested with GLM-5 and DeepSeek-R1 models
JSON extraction now works correctly after stripping thinking blocks
🔄 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/22397
**Author:** [@Tattooed-Geek](https://github.com/Tattooed-Geek)
**Created:** 3/8/2026
**Status:** ❌ Closed
**Base:** `main` ← **Head:** `fix-21888-rag-thinking-models`
---
### 📝 Commits (1)
- [`2db41c2`](https://github.com/open-webui/open-webui/commit/2db41c2d4063b8a53b60f6599945ffb37fc19813) 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
## Summary
Fixes #21888
RAG query JSON extraction was failing with \"thinking\" models like GLM-5 and DeepSeek-R1 because these models output thinking blocks (e.g., `<think>...</think>`) before the actual JSON response. The parser tried to parse the thinking block as JSON, causing failures.
## Changes
- Strip thinking blocks from model responses before attempting JSON parsing in RAG query processing
- Handles both `<think>...</think>` and similar thinking block patterns
## Testing
- Tested with GLM-5 and DeepSeek-R1 models
- JSON extraction now works correctly after stripping thinking blocks
- No impact on non-thinking models
Fixes #21888
---
<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/22397
Author: @Tattooed-Geek
Created: 3/8/2026
Status: ❌ Closed
Base:
main← Head:fix-21888-rag-thinking-models📝 Commits (1)
2db41c2fix: 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
Summary
Fixes #21888
RAG query JSON extraction was failing with "thinking" models like GLM-5 and DeepSeek-R1 because these models output thinking blocks (e.g.,
<think>...</think>) before the actual JSON response. The parser tried to parse the thinking block as JSON, causing failures.Changes
<think>...</think>and similar thinking block patternsTesting
Fixes #21888
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.