From 3e504e7ec99f95e8de664ef90d1808cf45245668 Mon Sep 17 00:00:00 2001 From: TSKVenkat Date: Fri, 28 Aug 2026 23:48:39 +0530 Subject: [PATCH] fix(prometheus): type the custom-label helpers as Mapping so TypedDicts are accepted The combination helpers took `dict | None`, but their callers hold TypedDicts: the fallback emitters and the proxy failure hook pass a StandardLoggingMetadata, and set_llm_deployment_failure_metrics passes a StandardLoggingPayload. A TypedDict is not assignable to a bare `dict`, so basedpyright reported four reportArgumentType errors. That rule is at its ceiling in basedpyright-code-budget.json, so the lint job failed. Both helpers only read - `.get()` and `.items()` - so `Mapping[str, object]` is the honest contract and accepts TypedDicts, plain dicts and the payload types alike. The isinstance guards check Mapping to match, which keeps the same runtime behaviour for non-mapping input. reportArgumentType in this file is back to the base count of 22, and both gates pass locally: `type_discipline_gate.py` reports every LIT rule within its ceiling. --- litellm/integrations/prometheus.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.py index 9b878d524f4..24e6ebab82b 100644 --- a/litellm/integrations/prometheus.py +++ b/litellm/integrations/prometheus.py @@ -4264,7 +4264,7 @@ def get_custom_labels_from_metadata(metadata: dict) -> dict[str, str]: def _get_combined_custom_metadata_from_standard_logging_payload( - standard_logging_payload: dict | None, + standard_logging_payload: Mapping[str, object] | None, ) -> dict[str, object]: """ Combine the metadata sources that can supply custom Prometheus labels. @@ -4274,19 +4274,19 @@ def _get_combined_custom_metadata_from_standard_logging_payload( via custom_prometheus_metadata_labels configuration. """ return _get_combined_custom_metadata_from_standard_logging_metadata( - standard_logging_payload.get("metadata") if isinstance(standard_logging_payload, dict) else None + standard_logging_payload.get("metadata") if isinstance(standard_logging_payload, Mapping) else None ) def _get_combined_custom_metadata_from_standard_logging_metadata( - standard_logging_metadata: dict | None, + standard_logging_metadata: Mapping[str, object] | None, ) -> dict[str, object]: """ Same combination, for emitters holding the standard logging metadata itself rather than a whole payload: the fallback emitters and the proxy failure hook build it with StandardLoggingPayloadSetup.get_standard_logging_metadata. """ - if not isinstance(standard_logging_metadata, dict): + if not isinstance(standard_logging_metadata, Mapping): return {} requester_metadata: Final = standard_logging_metadata.get("requester_metadata")