From 0efd8fb4513d0855fe51658e03727175dd7fb42e Mon Sep 17 00:00:00 2001 From: karank2512 Date: Thu, 22 Oct 2026 12:22:25 -0500 Subject: [PATCH] fix(logging): keep string metadata.tags as a single tag --- litellm/litellm_core_utils/litellm_logging.py | 20 +++++-------------- .../test_background_cost_polling.py | 7 ++++--- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index 071a057b9a0..26149e60cf3 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -7087,15 +7087,6 @@ class StandardLoggingPayloadSetup: return header_tags if header_tags else None - @staticmethod - def _coerce_tags_to_list(tags: object) -> list[str]: - """Return a copy of caller-provided tags as a list; a bare string becomes a one-item list.""" - if isinstance(tags, str): - return [tags] - if isinstance(tags, (list, tuple, set)): - return cast(list[str], list(tags)) # cast-ok: tags are caller-provided - return [] - @staticmethod def get_request_tags( litellm_params: dict[str, object], @@ -7107,12 +7098,11 @@ class StandardLoggingPayloadSetup: litellm_metadata: Final = cast( # cast-ok: request metadata is caller-provided Mapping[str, object], litellm_params.get("litellm_metadata") or {} ) - metadata_tags: Final = metadata.get("tags", []) - litellm_metadata_tags: Final = litellm_metadata.get("tags", []) - if metadata_tags: - request_tags = StandardLoggingPayloadSetup._coerce_tags_to_list(metadata_tags) - elif litellm_metadata_tags: - request_tags = StandardLoggingPayloadSetup._coerce_tags_to_list(litellm_metadata_tags) + raw_tags: Final = metadata.get("tags", []) or litellm_metadata.get("tags", []) + if isinstance(raw_tags, str): + request_tags = [raw_tags] + elif raw_tags: + request_tags = cast(list[str], raw_tags).copy() # cast-ok: tags are caller-provided else: request_tags = [] user_agent_tags: Final = StandardLoggingPayloadSetup._get_user_agent_tags(proxy_server_request) diff --git a/tests/unit/interactions/test_background_cost_polling.py b/tests/unit/interactions/test_background_cost_polling.py index d55994dfb19..98ad8f73b71 100644 --- a/tests/unit/interactions/test_background_cost_polling.py +++ b/tests/unit/interactions/test_background_cost_polling.py @@ -484,11 +484,12 @@ async def test_schedule_registers_an_agent_only_create_that_names_no_model(): @pytest.mark.asyncio -async def test_schedule_registers_a_create_whose_tags_are_a_string_and_keeps_them_as_sent(): +async def test_schedule_registers_a_create_whose_tags_are_a_string_and_stores_them_as_a_list(): """ The regression: storing the create's context read string tags as a list and raised, so a create sent with a tags string answered with an error - after the provider had already started the interaction. + after the provider had already started the interaction. A string is now + read as a single tag. """ logging_obj = _logging_obj(litellm_params={"metadata": _create_metadata(tags="team-a,nightly-batch")}) store = InMemoryBackgroundSettlementStore() @@ -507,7 +508,7 @@ async def test_schedule_registers_a_create_whose_tags_are_a_string_and_keeps_the pending = await store.pending("interactions/bg-abc") assert pending is not None rebuilt = _rebuild_logging_obj(pending.create_context) - assert get_litellm_metadata_from_kwargs(kwargs=rebuilt.model_call_details)["tags"] == "team-a,nightly-batch" + assert get_litellm_metadata_from_kwargs(kwargs=rebuilt.model_call_details)["tags"] == ["team-a,nightly-batch"] @pytest.mark.asyncio