mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #22189] [CLOSED] fix: initialize streaming tool call arguments to '{}' instead of empty string #65397
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/22189
Author: @Jseals38
Created: 3/3/2026
Status: ❌ Closed
Base:
dev← Head:fix/empty-tool-call-arguments📝 Commits (1)
2004dd9fix: initialize streaming tool call arguments to '{}' instead of empty string📊 Changes
1 file changed (+1 additions, -1 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+1 -1)📄 Description
Pull Request Checklist
devbranch.fix:Changelog Entry
Description
setdefault("arguments", "")seeds the arguments field with an empty string. Bothast.literal_eval("")andjson.loads("")fail, producing "Tool call arguments could not be parsed" errors. Changing the seed to"{}"makes both parsers succeed, returning an empty dict{}.Added
Changed
Deprecated
Removed
Fixed
middleware.py: changedsetdefault("arguments", "")tosetdefault("arguments", "{}")so parameterless tool calls parse correctly on the first attempt instead of failing and requiring a model retry.Security
Breaking Changes
Additional Information
Root cause: During streaming, when a new tool call is encountered, the arguments field is initialized via
setdefault("arguments", ""). For parameterless tools where the model never sends argument content, this empty string becomes the final value. The downstream parser attool_call.get("function", {}).get("arguments", "{}")retrieves it (the.getdefault of"{}"only applies when the key is missing, but the key is present with value""), then bothast.literal_eval("")andjson.loads("")raise exceptions.Scope & safety:
setdefaultonly applies when the"arguments"key is absent from the first streaming chunk. When a model includes"arguments": ""explicitly (the standard behavior for tools that have parameters),setdefaultdoes not fire and behavior is completely unchanged.Edge case considered: If a model omitted the arguments key in the first chunk but then streamed argument content in subsequent chunks, the seeded
"{}"would prepend to the streamed JSON. However, in OpenAI-compatible streaming the first tool call chunk virtually always includes"arguments": ""explicitly, sosetdefaultnever activates in that path. This pattern is not observed in practice across OpenAI, Azure OpenAI, or other compatible providers.Screenshots or Videos
Before fix — parameterless tool call fails on first attempt:
Error: Tool call arguments could not be parsed. The model generated malformed or incomplete JSON for tool_call. Please try again.
Model retries with explicit
{}or{"key": {}}, wasting a round-trip.After fix — parameterless tool call succeeds on first attempt with no retry needed.
Contributor License Agreement
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.