From 833b62ca71d7c407abdda6a6abebd5aee7e98803 Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Mon, 4 May 2026 17:50:13 +0530 Subject: [PATCH] fix: remove duplicate import and guard empty-string mapping for None tool names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove the duplicate `restore_openai_tool_name_for_user` import in streaming_chunk_builder_utils.py - Only store the sanitized→original name mapping when the original name is non-empty; when `fn["name"]` is None the generated placeholder (e.g. `litellm_unnamed_tool_0`) is kept as-is on the response path instead of being replaced with an empty string Co-authored-by: Cursor --- litellm/litellm_core_utils/streaming_chunk_builder_utils.py | 3 --- litellm/utils.py | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/litellm/litellm_core_utils/streaming_chunk_builder_utils.py b/litellm/litellm_core_utils/streaming_chunk_builder_utils.py index 149bdef7491..26347c85a72 100644 --- a/litellm/litellm_core_utils/streaming_chunk_builder_utils.py +++ b/litellm/litellm_core_utils/streaming_chunk_builder_utils.py @@ -9,9 +9,6 @@ from litellm.types.llms.openai import ( ChatCompletionAssistantContentValue, ChatCompletionAudioDelta, ) -from litellm.litellm_core_utils.openai_tool_name_mapping import ( - restore_openai_tool_name_for_user, -) from litellm.types.utils import ( ChatCompletionAudioResponse, ChatCompletionMessageToolCall, diff --git a/litellm/utils.py b/litellm/utils.py index 8ba9f80db66..c140584132d 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -7918,13 +7918,13 @@ def _maybe_fix_openai_function_tool_name( if tool_type is not None and tool_type != "function": return raw = fn.get("name") - raw_original = str(raw) if raw is not None else "" + raw_original = str(raw) if raw is not None else None base = _sanitize_openai_function_tool_name( str(raw) if raw is not None else "", index ) unique = _make_unique_openai_tool_name(base, used_names) fn["name"] = unique - if unique != raw_original: + if raw_original and unique != raw_original: store_openai_tool_name_mapping(unique, raw_original)