mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-09 05:19:20 -05:00
[PR #21983] [CLOSED] fix: graceful error handling for malformed tool call arguments #42007
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/21983
Author: @sxu75374
Created: 2/28/2026
Status: ❌ Closed
Base:
main← Head:fix/graceful-malformed-tool-args📝 Commits (1)
bdcafe9fix(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:
json.JSONDecodeErrorduring tool argument parsingtool_args_parse_errorflag to skip tool executionChanges
backend/open_webui/utils/middleware.py: Add parse error flag, guard tool execution, return descriptive error to LLMbackend/open_webui/test/utils/test_tool_call_parsing.py: 11 unit tests covering malformed JSON, truncated args, valid args, and edge casesTesting
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.