From aae99ff6f34a5599fd1c00cabae782c1d7af7026 Mon Sep 17 00:00:00 2001 From: jaideeppyne Date: Thu, 13 Aug 2026 08:41:42 +0530 Subject: [PATCH] fix: preserve adjacent inline data: URIs in OpenAPI tool results process_tool_result() iterated over tool_result while calling tool_result.remove(item) inside the loop. list.remove() shifts every later element down by one, so the iterator skipped the item immediately after each extracted data: URI. When an OpenAPI tool returned two or more adjacent inline data: URIs, only the first became an attachment; the second survived into the text payload and was json.dumps()'d into the model context as a raw base64 blob. Collect the non-data items into a new list and assign back in place instead of mutating during iteration. --- backend/open_webui/utils/middleware.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index a269843b73..cfed673bc6 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -1049,6 +1049,7 @@ async def process_tool_result( tool_response.append(resource.get('uri')) tool_result = tool_response[0] if len(tool_response) == 1 else tool_response else: # OpenAPI + kept_items = [] for item in tool_result: if isinstance(item, str) and item.startswith('data:'): tool_result_files.append( @@ -1057,7 +1058,9 @@ async def process_tool_result( 'content': item, } ) - tool_result.remove(item) + else: + kept_items.append(item) + tool_result[:] = kept_items if isinstance(tool_result, list): tool_result = {'results': tool_result}