From 7e8a0779da6e96c84ab2d006fadc28b90a1c6317 Mon Sep 17 00:00:00 2001 From: Mateo Wang <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 14 May 2026 00:54:16 +0000 Subject: [PATCH] fix(bugbot): simplify rate-limit label coercion + guard None detail - prometheus.py _extract_rate_limit_labels: RateLimitError.__init__ already normalizes category/rate_limit_type to plain str, so the getattr(.value) + isinstance dance was dead code. Reduce to str(value) if not None. - proxy_rate_limit_error.py _coerce_message: short-circuit None to '' instead of falling through to str(None) = 'None', which produced the literal message 'litellm.RateLimitError: None'. --- litellm/integrations/prometheus.py | 7 +------ litellm/proxy/common_utils/proxy_rate_limit_error.py | 2 ++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.py index 4c4d4c7dab9..f919bc7705d 100644 --- a/litellm/integrations/prometheus.py +++ b/litellm/integrations/prometheus.py @@ -2697,12 +2697,7 @@ class PrometheusLogger(CustomLogger): return None, None def _coerce(value: Any) -> Optional[str]: - if value is None: - return None - inner = getattr(value, "value", None) - if isinstance(inner, str): - return inner - return str(value) + return str(value) if value is not None else None return ( _coerce(getattr(exception, "category", None)), diff --git a/litellm/proxy/common_utils/proxy_rate_limit_error.py b/litellm/proxy/common_utils/proxy_rate_limit_error.py index 14c8977dce6..1c057c5e6e1 100644 --- a/litellm/proxy/common_utils/proxy_rate_limit_error.py +++ b/litellm/proxy/common_utils/proxy_rate_limit_error.py @@ -67,6 +67,8 @@ def map_v3_rate_limit_type( def _coerce_message(detail: Any) -> str: """Best-effort, JSON-friendly stringification of an HTTPException-style detail.""" + if detail is None: + return "" if isinstance(detail, str): return detail if isinstance(detail, Mapping):