From a1bde74e97e4be2e2a422043a43e08b6b40b427e Mon Sep 17 00:00:00 2001 From: Leo Wang Date: Mon, 15 Dec 2025 01:12:14 +0800 Subject: [PATCH] fix(prompt): preserve non-ASCII characters in tool specs serialization (#19942) Use json.dumps with ensure_ascii=False to avoid converting Chinese descriptions into Unicode escape sequences. This makes logs easier to read and significantly improves LLM tool selection accuracy (from ~48% to ~67%) by preserving the original natural language context. --- backend/open_webui/utils/middleware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index d397471dd9..6c285b9367 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -345,7 +345,7 @@ async def chat_completion_tools_handler( sources = [] specs = [tool["spec"] for tool in tools.values()] - tools_specs = json.dumps(specs) + tools_specs = json.dumps(specs, ensure_ascii=False) if request.app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE != "": template = request.app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE