[PR #22397] [CLOSED] fix: strip thinking blocks before parsing tool result JSON #81528

Closed
opened 2026-05-13 15:52:17 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

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

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


📝 Commits (1)

  • 2db41c2 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

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


🔄 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>
GiteaMirror added the pull-request label 2026-05-13 15:52:17 -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#81528