From ca9e121eb67185debdf1af3dea64ab2e080f3df1 Mon Sep 17 00:00:00 2001 From: Yucheng Zhu Date: Mon, 31 Aug 2026 18:57:20 -0700 Subject: [PATCH] fix(guardrails): avoid mutable dict literal in guardrail metadata population --- litellm/proxy/hooks/proxy_track_cost_callback.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/hooks/proxy_track_cost_callback.py b/litellm/proxy/hooks/proxy_track_cost_callback.py index ca8341822e9..b78884f7d95 100644 --- a/litellm/proxy/hooks/proxy_track_cost_callback.py +++ b/litellm/proxy/hooks/proxy_track_cost_callback.py @@ -273,13 +273,16 @@ class _ProxyDBLogger(CustomLogger): # guardrail_information is missing from SLP. Populate it from post-call evals # before spend-log write so reports show accurate guardrail results. if sl_object is not None: + litellm_metadata: Final = kwargs.get("litellm_metadata") guardrail_info_from_hooks: Final = ( - kwargs.get("litellm_metadata", {}).get("standard_logging_guardrail_information") - if isinstance(kwargs.get("litellm_metadata"), dict) + litellm_metadata.get("standard_logging_guardrail_information") + if isinstance(litellm_metadata, dict) else None ) if guardrail_info_from_hooks is not None and not sl_object.get("guardrail_information"): - sl_object["guardrail_information"] = guardrail_info_from_hooks + sl_object["guardrail_information"] = ( + guardrail_info_from_hooks # mutable-ok: populate SLP before spend-log write + ) if response_cost is not None: user_api_key: Final = metadata.get("user_api_key", None)