From 227287b3b52a0d7fd3dfd97dd7a1e15f7b661a9d Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sun, 8 Nov 2026 23:47:26 +0100 Subject: [PATCH] fix: tool call arguments get extra spaces when sent back to the model (#33959) A tool call the model wrote as compact JSON, as most models do, was sent back to the model with a space added after every comma and colon, in every request after the tool ran. The model now gets its tool call arguments back exactly as it wrote them whenever they were valid JSON, so a model server that caches the model's earlier output can keep using that cache. Arguments that Open WebUI had to repair before the tool could run, such as JSON wrapped in a code block or written with Python-style True and None, still go back in their repaired form. Fixes #33958 --- backend/open_webui/utils/misc.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/open_webui/utils/misc.py b/backend/open_webui/utils/misc.py index 75d104871c..9801b9eb58 100644 --- a/backend/open_webui/utils/misc.py +++ b/backend/open_webui/utils/misc.py @@ -349,8 +349,16 @@ def get_provider_function(item: dict) -> dict: function = dict(function) if 'original_arguments' in function: function['arguments'] = function['original_arguments'] + raw_arguments = function.get('arguments') if error := prepare_tool_call(function): function['arguments'] = JSONCodec.dumps({'error': error}) + else: + try: + # A valid JSON object goes back as the model wrote it, so its cached output still matches. + if isinstance(JSONCodec.loads(raw_arguments), dict): + function['arguments'] = raw_arguments + except (TypeError, ValueError): + pass return { 'name': function.get('name', ''), 'arguments': function['arguments'],