[PR #21983] [CLOSED] fix: graceful error handling for malformed tool call arguments #42007

Closed
opened 2026-04-25 14:03:40 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/21983
Author: @sxu75374
Created: 2/28/2026
Status: Closed

Base: mainHead: fix/graceful-malformed-tool-args


📝 Commits (1)

  • bdcafe9 fix(middleware): graceful error handling for malformed tool call arguments

📊 Changes

2 files changed (+138 additions, -3 deletions)

View changed files

backend/open_webui/test/utils/test_tool_call_parsing.py (+130 -0)
📝 backend/open_webui/utils/middleware.py (+8 -3)

📄 Description

What this PR does

When an LLM produces truncated or malformed JSON in tool call arguments (common with streaming or context-length limits), the SSE stream crashes with an unhandled exception.

This PR adds graceful error handling:

  • Catches json.JSONDecodeError during tool argument parsing
  • Sets a tool_args_parse_error flag to skip tool execution
  • Returns a descriptive error message back to the LLM so it can retry or explain
  • The chat stream continues normally instead of crashing

Changes

  • backend/open_webui/utils/middleware.py: Add parse error flag, guard tool execution, return descriptive error to LLM
  • backend/open_webui/test/utils/test_tool_call_parsing.py: 11 unit tests covering malformed JSON, truncated args, valid args, and edge cases

Testing

All 11 new tests pass. Manually verified with truncated JSON payloads — stream continues and LLM receives the error context.

Signed-off-by: sxu75374 imshuaixu@gmail.com


🔄 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/21983 **Author:** [@sxu75374](https://github.com/sxu75374) **Created:** 2/28/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/graceful-malformed-tool-args` --- ### 📝 Commits (1) - [`bdcafe9`](https://github.com/open-webui/open-webui/commit/bdcafe9d8f9c2c4881c59892f9a7748238b719b9) fix(middleware): graceful error handling for malformed tool call arguments ### 📊 Changes **2 files changed** (+138 additions, -3 deletions) <details> <summary>View changed files</summary> ➕ `backend/open_webui/test/utils/test_tool_call_parsing.py` (+130 -0) 📝 `backend/open_webui/utils/middleware.py` (+8 -3) </details> ### 📄 Description ## What this PR does When an LLM produces truncated or malformed JSON in tool call arguments (common with streaming or context-length limits), the SSE stream crashes with an unhandled exception. This PR adds graceful error handling: - Catches `json.JSONDecodeError` during tool argument parsing - Sets a `tool_args_parse_error` flag to skip tool execution - Returns a descriptive error message back to the LLM so it can retry or explain - The chat stream continues normally instead of crashing ## Changes - `backend/open_webui/utils/middleware.py`: Add parse error flag, guard tool execution, return descriptive error to LLM - `backend/open_webui/test/utils/test_tool_call_parsing.py`: 11 unit tests covering malformed JSON, truncated args, valid args, and edge cases ## Testing All 11 new tests pass. Manually verified with truncated JSON payloads — stream continues and LLM receives the error context. Signed-off-by: sxu75374 <imshuaixu@gmail.com> --- <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 14:03:40 -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#42007