From 14f747129e2004de8f8a837281e504f3a4659d80 Mon Sep 17 00:00:00 2001 From: TSKVenkat Date: Fri, 28 Aug 2026 22:59:00 +0530 Subject: [PATCH 1/4] fix(prometheus): populate custom metadata labels on failure and fallback metrics custom_prometheus_metadata_labels was honoured only by async_log_success_event and async_log_failure_event. PrometheusMetricLabels.get_labels() appends the configured labels to the declared label set of every metric, so the label existed on the failure and fallback series too - it was just never filled, and exported the literal string "None" on exactly the metrics an operator reaches for when calls start failing. Four emitters were missing it: async_post_call_failure_hook litellm_proxy_failed_requests_metric litellm_proxy_total_requests_metric set_llm_deployment_failure_metrics litellm_deployment_failure_responses litellm_deployment_total_requests log_success_fallback_event litellm_deployment_successful_fallbacks log_failure_fallback_event litellm_deployment_failed_fallbacks set_llm_deployment_failure_metrics already holds the standard logging payload. Both fallback emitters already build standard_metadata via StandardLoggingPayloadSetup.get_standard_logging_metadata, so wrapping it as {"metadata": standard_metadata} resolves through the payload-shaped helper. async_post_call_failure_hook holds raw request metadata, which the helper does not flatten - the configured key sits under spend_logs_metadata - so it now builds standard metadata the same way the fallback emitters do. This is the tail of the migration in #27268, which moved async_log_failure_event onto the keyword-label factory but did not cover these four. Fixes #38660 --- litellm/integrations/prometheus.py | 15 ++ ...rometheus_custom_labels_failure_metrics.py | 134 ++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 tests/test_litellm/integrations/test_prometheus_custom_labels_failure_metrics.py diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.py index 467ec72dc4a..6f350b84e53 100644 --- a/litellm/integrations/prometheus.py +++ b/litellm/integrations/prometheus.py @@ -2397,6 +2397,7 @@ class PrometheusLogger(CustomLogger): model_id: Final = _metadata.get("model_info", {}).get("id") or request_data.get("model_info", {}).get("id") rate_limit_category, rate_limit_type = self._extract_rate_limit_labels(original_exception) api_provider: Final = self._extract_api_provider_from_request_data(request_data) + _standard_metadata: Final = StandardLoggingPayloadSetup.get_standard_logging_metadata(metadata=_metadata) enum_values: Final = UserAPIKeyLabelValues( end_user=user_api_key_dict.end_user_id, user=user_api_key_dict.user_id, @@ -2420,6 +2421,11 @@ class PrometheusLogger(CustomLogger): model_id=model_id, api_provider=api_provider, stream=(str(request_data.get("stream")) if litellm.prometheus_emit_stream_label else None), + custom_metadata_labels=get_custom_labels_from_metadata( + metadata=_get_combined_custom_metadata_from_standard_logging_payload( + {"metadata": _standard_metadata} + ) + ), ) _label_ctx: Final = PrometheusLabelFactoryContext(enum_values) PrometheusLogger._inc_labeled_counter( @@ -2645,6 +2651,9 @@ class PrometheusLogger(CustomLogger): tags=standard_logging_payload.get("request_tags", []), client_ip=client_ip, user_agent=user_agent, + custom_metadata_labels=get_custom_labels_from_metadata( + metadata=_get_combined_custom_metadata_from_standard_logging_payload(standard_logging_payload) + ), ) """ @@ -3195,6 +3204,9 @@ class PrometheusLogger(CustomLogger): exception_status=str(getattr(original_exception, "status_code", None)), exception_class=self._get_exception_class_name(original_exception), tags=_tags, + custom_metadata_labels=get_custom_labels_from_metadata( + metadata=_get_combined_custom_metadata_from_standard_logging_payload({"metadata": standard_metadata}) + ), ) PrometheusLogger._inc_labeled_counter( self, @@ -3236,6 +3248,9 @@ class PrometheusLogger(CustomLogger): exception_status=str(getattr(original_exception, "status_code", None)), exception_class=self._get_exception_class_name(original_exception), tags=_tags, + custom_metadata_labels=get_custom_labels_from_metadata( + metadata=_get_combined_custom_metadata_from_standard_logging_payload({"metadata": standard_metadata}) + ), ) PrometheusLogger._inc_labeled_counter( diff --git a/tests/test_litellm/integrations/test_prometheus_custom_labels_failure_metrics.py b/tests/test_litellm/integrations/test_prometheus_custom_labels_failure_metrics.py new file mode 100644 index 00000000000..19b30e5106a --- /dev/null +++ b/tests/test_litellm/integrations/test_prometheus_custom_labels_failure_metrics.py @@ -0,0 +1,134 @@ +""" +Unit tests for custom_prometheus_metadata_labels on the failure and fallback metrics. + +The configured labels were only populated by async_log_success_event and +async_log_failure_event. Every other emitter declared the label but never filled +it, so the series exported the literal string "None" on exactly the metrics an +operator reaches for when calls start failing. Issue #38660. +""" + +import pytest +from prometheus_client import REGISTRY + +import litellm +from litellm.integrations.prometheus import PrometheusLogger +from litellm.proxy._types import UserAPIKeyAuth + + +@pytest.fixture(scope="function") +def prometheus_logger(monkeypatch): + """ + The configured labels are baked into each metric's declared label set when the + logger is constructed, so the setting has to be in place before instantiation. + """ + monkeypatch.setattr("litellm.custom_prometheus_metadata_labels", ["caller"]) + for collector in list(REGISTRY._collector_to_names.keys()): + REGISTRY.unregister(collector) + return PrometheusLogger() + + +def _caller_labels(metric_name: str) -> list[str | None]: + """Every `caller` label value emitted on the named metric.""" + for metric in REGISTRY.collect(): + if metric.name == metric_name: + return [sample.labels.get("caller") for sample in metric.samples] + return [] + + +def _standard_logging_object() -> dict: + return { + "model_id": "resolved-deployment-id", + "model_group": "my-model-group", + "api_base": "https://example.com", + "metadata": {"spend_logs_metadata": {"caller": "my-task"}}, + } + + +class TestCustomLabelsOnDeploymentFailureMetrics: + def test_deployment_failure_responses_carries_custom_label(self, prometheus_logger): + prometheus_logger.set_llm_deployment_failure_metrics( + { + "model": "my-model", + "exception": Exception("upstream 503"), + "litellm_params": {"custom_llm_provider": "vertex_ai", "metadata": {}}, + "standard_logging_object": _standard_logging_object(), + } + ) + assert "my-task" in _caller_labels("litellm_deployment_failure_responses") + + def test_deployment_total_requests_carries_custom_label(self, prometheus_logger): + prometheus_logger.set_llm_deployment_failure_metrics( + { + "model": "my-model", + "exception": Exception("upstream 503"), + "litellm_params": {"custom_llm_provider": "vertex_ai", "metadata": {}}, + "standard_logging_object": _standard_logging_object(), + } + ) + assert "my-task" in _caller_labels("litellm_deployment_total_requests") + + def test_unset_custom_label_is_absent_rather_than_wrong(self, prometheus_logger): + """No spend_logs_metadata means no value to attribute; it must not invent one.""" + payload = _standard_logging_object() + payload["metadata"] = {} + prometheus_logger.set_llm_deployment_failure_metrics( + { + "model": "my-model", + "exception": Exception("upstream 503"), + "litellm_params": {"custom_llm_provider": "vertex_ai", "metadata": {}}, + "standard_logging_object": payload, + } + ) + assert "my-task" not in _caller_labels("litellm_deployment_failure_responses") + + +class TestCustomLabelsOnFallbackMetrics: + @pytest.mark.asyncio + async def test_successful_fallback_carries_custom_label(self, prometheus_logger): + await prometheus_logger.log_success_fallback_event( + original_model_group="my-model-group", + kwargs={ + "model": "fallback-model", + "metadata": {"spend_logs_metadata": {"caller": "my-task"}}, + }, + original_exception=Exception("upstream 503"), + ) + assert "my-task" in _caller_labels("litellm_deployment_successful_fallbacks") + + @pytest.mark.asyncio + async def test_failed_fallback_carries_custom_label(self, prometheus_logger): + await prometheus_logger.log_failure_fallback_event( + original_model_group="my-model-group", + kwargs={ + "model": "fallback-model", + "metadata": {"spend_logs_metadata": {"caller": "my-task"}}, + }, + original_exception=Exception("upstream 503"), + ) + assert "my-task" in _caller_labels("litellm_deployment_failed_fallbacks") + + +class TestCustomLabelsOnProxyFailureMetrics: + @pytest.mark.asyncio + async def test_proxy_failed_requests_carries_custom_label(self, prometheus_logger): + await prometheus_logger.async_post_call_failure_hook( + request_data={ + "model": "my-model", + "metadata": {"spend_logs_metadata": {"caller": "my-task"}}, + }, + original_exception=Exception("upstream 503"), + user_api_key_dict=UserAPIKeyAuth(token="test_token"), + ) + assert "my-task" in _caller_labels("litellm_proxy_failed_requests_metric") + + @pytest.mark.asyncio + async def test_proxy_total_requests_carries_custom_label(self, prometheus_logger): + await prometheus_logger.async_post_call_failure_hook( + request_data={ + "model": "my-model", + "metadata": {"spend_logs_metadata": {"caller": "my-task"}}, + }, + original_exception=Exception("upstream 503"), + user_api_key_dict=UserAPIKeyAuth(token="test_token"), + ) + assert "my-task" in _caller_labels("litellm_proxy_total_requests_metric") From 7b74685b043977d793407868ae679da858a53b46 Mon Sep 17 00:00:00 2001 From: TSKVenkat Date: Fri, 28 Aug 2026 23:07:26 +0530 Subject: [PATCH 2/4] test(prometheus): extend the mapped custom-label test file instead of a new one The repo's contributor guidelines ask that bug fixes extend the existing mapped test file rather than add a new one. These cases belong in test_prometheus_custom_metadata_label_counts.py in particular: that file covers async_log_failure_event and _set_virtual_key_rate_limit_metrics, the two emitters #27268 moved onto the keyword-label factory, and the four emitters fixed here are the tail of that same migration. Reuses the file's existing _create_prometheus_logger_with_custom_labels, _standard_logging_payload_with_requester_metadata and _metric_samples helpers, so the new cases assert the same labels the surrounding tests already use. No change to the fix itself. --- ...rometheus_custom_labels_failure_metrics.py | 134 ------------------ ...prometheus_custom_metadata_label_counts.py | 117 +++++++++++++++ 2 files changed, 117 insertions(+), 134 deletions(-) delete mode 100644 tests/test_litellm/integrations/test_prometheus_custom_labels_failure_metrics.py diff --git a/tests/test_litellm/integrations/test_prometheus_custom_labels_failure_metrics.py b/tests/test_litellm/integrations/test_prometheus_custom_labels_failure_metrics.py deleted file mode 100644 index 19b30e5106a..00000000000 --- a/tests/test_litellm/integrations/test_prometheus_custom_labels_failure_metrics.py +++ /dev/null @@ -1,134 +0,0 @@ -""" -Unit tests for custom_prometheus_metadata_labels on the failure and fallback metrics. - -The configured labels were only populated by async_log_success_event and -async_log_failure_event. Every other emitter declared the label but never filled -it, so the series exported the literal string "None" on exactly the metrics an -operator reaches for when calls start failing. Issue #38660. -""" - -import pytest -from prometheus_client import REGISTRY - -import litellm -from litellm.integrations.prometheus import PrometheusLogger -from litellm.proxy._types import UserAPIKeyAuth - - -@pytest.fixture(scope="function") -def prometheus_logger(monkeypatch): - """ - The configured labels are baked into each metric's declared label set when the - logger is constructed, so the setting has to be in place before instantiation. - """ - monkeypatch.setattr("litellm.custom_prometheus_metadata_labels", ["caller"]) - for collector in list(REGISTRY._collector_to_names.keys()): - REGISTRY.unregister(collector) - return PrometheusLogger() - - -def _caller_labels(metric_name: str) -> list[str | None]: - """Every `caller` label value emitted on the named metric.""" - for metric in REGISTRY.collect(): - if metric.name == metric_name: - return [sample.labels.get("caller") for sample in metric.samples] - return [] - - -def _standard_logging_object() -> dict: - return { - "model_id": "resolved-deployment-id", - "model_group": "my-model-group", - "api_base": "https://example.com", - "metadata": {"spend_logs_metadata": {"caller": "my-task"}}, - } - - -class TestCustomLabelsOnDeploymentFailureMetrics: - def test_deployment_failure_responses_carries_custom_label(self, prometheus_logger): - prometheus_logger.set_llm_deployment_failure_metrics( - { - "model": "my-model", - "exception": Exception("upstream 503"), - "litellm_params": {"custom_llm_provider": "vertex_ai", "metadata": {}}, - "standard_logging_object": _standard_logging_object(), - } - ) - assert "my-task" in _caller_labels("litellm_deployment_failure_responses") - - def test_deployment_total_requests_carries_custom_label(self, prometheus_logger): - prometheus_logger.set_llm_deployment_failure_metrics( - { - "model": "my-model", - "exception": Exception("upstream 503"), - "litellm_params": {"custom_llm_provider": "vertex_ai", "metadata": {}}, - "standard_logging_object": _standard_logging_object(), - } - ) - assert "my-task" in _caller_labels("litellm_deployment_total_requests") - - def test_unset_custom_label_is_absent_rather_than_wrong(self, prometheus_logger): - """No spend_logs_metadata means no value to attribute; it must not invent one.""" - payload = _standard_logging_object() - payload["metadata"] = {} - prometheus_logger.set_llm_deployment_failure_metrics( - { - "model": "my-model", - "exception": Exception("upstream 503"), - "litellm_params": {"custom_llm_provider": "vertex_ai", "metadata": {}}, - "standard_logging_object": payload, - } - ) - assert "my-task" not in _caller_labels("litellm_deployment_failure_responses") - - -class TestCustomLabelsOnFallbackMetrics: - @pytest.mark.asyncio - async def test_successful_fallback_carries_custom_label(self, prometheus_logger): - await prometheus_logger.log_success_fallback_event( - original_model_group="my-model-group", - kwargs={ - "model": "fallback-model", - "metadata": {"spend_logs_metadata": {"caller": "my-task"}}, - }, - original_exception=Exception("upstream 503"), - ) - assert "my-task" in _caller_labels("litellm_deployment_successful_fallbacks") - - @pytest.mark.asyncio - async def test_failed_fallback_carries_custom_label(self, prometheus_logger): - await prometheus_logger.log_failure_fallback_event( - original_model_group="my-model-group", - kwargs={ - "model": "fallback-model", - "metadata": {"spend_logs_metadata": {"caller": "my-task"}}, - }, - original_exception=Exception("upstream 503"), - ) - assert "my-task" in _caller_labels("litellm_deployment_failed_fallbacks") - - -class TestCustomLabelsOnProxyFailureMetrics: - @pytest.mark.asyncio - async def test_proxy_failed_requests_carries_custom_label(self, prometheus_logger): - await prometheus_logger.async_post_call_failure_hook( - request_data={ - "model": "my-model", - "metadata": {"spend_logs_metadata": {"caller": "my-task"}}, - }, - original_exception=Exception("upstream 503"), - user_api_key_dict=UserAPIKeyAuth(token="test_token"), - ) - assert "my-task" in _caller_labels("litellm_proxy_failed_requests_metric") - - @pytest.mark.asyncio - async def test_proxy_total_requests_carries_custom_label(self, prometheus_logger): - await prometheus_logger.async_post_call_failure_hook( - request_data={ - "model": "my-model", - "metadata": {"spend_logs_metadata": {"caller": "my-task"}}, - }, - original_exception=Exception("upstream 503"), - user_api_key_dict=UserAPIKeyAuth(token="test_token"), - ) - assert "my-task" in _caller_labels("litellm_proxy_total_requests_metric") diff --git a/tests/test_litellm/integrations/test_prometheus_custom_metadata_label_counts.py b/tests/test_litellm/integrations/test_prometheus_custom_metadata_label_counts.py index 99eb5abb7b5..28f5ff4ba98 100644 --- a/tests/test_litellm/integrations/test_prometheus_custom_metadata_label_counts.py +++ b/tests/test_litellm/integrations/test_prometheus_custom_metadata_label_counts.py @@ -157,3 +157,120 @@ def test_virtual_key_rate_limit_metrics_preserve_zero_remaining_values( assert any(sample.value == 0 for sample in token_samples) assert not any(sample.value == sys.maxsize for sample in request_samples) assert not any(sample.value == sys.maxsize for sample in token_samples) + + +def _request_metadata_with_custom_labels() -> dict: + """Raw request metadata carrying the configured labels under spend_logs_metadata.""" + return { + "spend_logs_metadata": { + "department": "engineering", + "environment": "production", + } + } + + +def _has_custom_labels(metric_name: str) -> bool: + return any( + sample.labels.get("metadata_department") == "engineering" + and sample.labels.get("metadata_environment") == "production" + for sample in _metric_samples(metric_name) + ) + + +def _deployment_failure_kwargs() -> dict: + payload = _standard_logging_payload_with_requester_metadata() + return { + "model": "gpt-4o-mini", + "exception": Exception("upstream 503"), + "litellm_params": {"custom_llm_provider": "openai", "metadata": {}}, + "standard_logging_object": payload, + } + + +def test_deployment_failure_metrics_accept_custom_metadata_labels( + monkeypatch: pytest.MonkeyPatch, +): + """ + set_llm_deployment_failure_metrics declared the configured labels but never + filled them, so both series it emits exported the literal string "None". + """ + prometheus_logger = _create_prometheus_logger_with_custom_labels(monkeypatch) + + prometheus_logger.set_llm_deployment_failure_metrics(_deployment_failure_kwargs()) + + assert _has_custom_labels("litellm_deployment_failure_responses_total") + assert _has_custom_labels("litellm_deployment_total_requests_total") + + +def test_deployment_failure_metrics_omit_custom_labels_when_absent( + monkeypatch: pytest.MonkeyPatch, +): + """Nothing supplies the labels, so none must be attributed.""" + prometheus_logger = _create_prometheus_logger_with_custom_labels(monkeypatch) + kwargs = _deployment_failure_kwargs() + kwargs["standard_logging_object"]["metadata"]["requester_metadata"] = None + + prometheus_logger.set_llm_deployment_failure_metrics(kwargs) + + assert not _has_custom_labels("litellm_deployment_failure_responses_total") + + +@pytest.mark.asyncio +async def test_success_fallback_event_accepts_custom_metadata_labels( + monkeypatch: pytest.MonkeyPatch, +): + prometheus_logger = _create_prometheus_logger_with_custom_labels(monkeypatch) + + await prometheus_logger.log_success_fallback_event( + original_model_group="gpt-4o-mini", + kwargs={ + "model": "gpt-4o-mini-fallback", + "metadata": _request_metadata_with_custom_labels(), + }, + original_exception=Exception("upstream 503"), + ) + + assert _has_custom_labels("litellm_deployment_successful_fallbacks_total") + + +@pytest.mark.asyncio +async def test_failure_fallback_event_accepts_custom_metadata_labels( + monkeypatch: pytest.MonkeyPatch, +): + prometheus_logger = _create_prometheus_logger_with_custom_labels(monkeypatch) + + await prometheus_logger.log_failure_fallback_event( + original_model_group="gpt-4o-mini", + kwargs={ + "model": "gpt-4o-mini-fallback", + "metadata": _request_metadata_with_custom_labels(), + }, + original_exception=Exception("upstream 503"), + ) + + assert _has_custom_labels("litellm_deployment_failed_fallbacks_total") + + +@pytest.mark.asyncio +async def test_post_call_failure_hook_accepts_custom_metadata_labels( + monkeypatch: pytest.MonkeyPatch, +): + """ + This hook holds raw request metadata, which the payload-shaped helper does not + flatten on its own, so both proxy-level series it emits missed the labels. + """ + from litellm.proxy._types import UserAPIKeyAuth + + prometheus_logger = _create_prometheus_logger_with_custom_labels(monkeypatch) + + await prometheus_logger.async_post_call_failure_hook( + request_data={ + "model": "gpt-4o-mini", + "metadata": _request_metadata_with_custom_labels(), + }, + original_exception=Exception("upstream 503"), + user_api_key_dict=UserAPIKeyAuth(token="test_token"), + ) + + assert _has_custom_labels("litellm_proxy_failed_requests_metric_total") + assert _has_custom_labels("litellm_proxy_total_requests_metric_total") From 8b7605fa38e9129eead2c99e45315a2129b6e4a2 Mon Sep 17 00:00:00 2001 From: TSKVenkat Date: Fri, 28 Aug 2026 23:25:18 +0530 Subject: [PATCH 3/4] refactor(prometheus): combine custom labels from standard metadata without a wrapper dict The three emitters that hold standard logging metadata rather than a whole payload were calling the payload-shaped helper with a {"metadata": ...} literal. That tripped the type-discipline gate's LIT002 ceiling (mutable-collection construction), which is already at its codebase limit, so the three new literals failed lint. Split the combination logic into a metadata-shaped helper and leave the payload-shaped one delegating to it, so those callers pass what they already hold and no wrapper dict is built. The delegation also drops the payload helper's own `or {}` and second guard, so this removes two more literals than it adds: LIT002 in this file goes 111 -> 109 against the merge base, and the gate reports every LIT rule within its ceiling. No behaviour change: a non-dict payload and a non-dict metadata both still yield {}. --- litellm/integrations/prometheus.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.py index 6f350b84e53..9b878d524f4 100644 --- a/litellm/integrations/prometheus.py +++ b/litellm/integrations/prometheus.py @@ -2422,9 +2422,7 @@ class PrometheusLogger(CustomLogger): api_provider=api_provider, stream=(str(request_data.get("stream")) if litellm.prometheus_emit_stream_label else None), custom_metadata_labels=get_custom_labels_from_metadata( - metadata=_get_combined_custom_metadata_from_standard_logging_payload( - {"metadata": _standard_metadata} - ) + metadata=_get_combined_custom_metadata_from_standard_logging_metadata(_standard_metadata) ), ) _label_ctx: Final = PrometheusLabelFactoryContext(enum_values) @@ -3205,7 +3203,7 @@ class PrometheusLogger(CustomLogger): exception_class=self._get_exception_class_name(original_exception), tags=_tags, custom_metadata_labels=get_custom_labels_from_metadata( - metadata=_get_combined_custom_metadata_from_standard_logging_payload({"metadata": standard_metadata}) + metadata=_get_combined_custom_metadata_from_standard_logging_metadata(standard_metadata) ), ) PrometheusLogger._inc_labeled_counter( @@ -3249,7 +3247,7 @@ class PrometheusLogger(CustomLogger): exception_class=self._get_exception_class_name(original_exception), tags=_tags, custom_metadata_labels=get_custom_labels_from_metadata( - metadata=_get_combined_custom_metadata_from_standard_logging_payload({"metadata": standard_metadata}) + metadata=_get_combined_custom_metadata_from_standard_logging_metadata(standard_metadata) ), ) @@ -4275,10 +4273,19 @@ def _get_combined_custom_metadata_from_standard_logging_payload( user_api_key_project_alias, user_api_key_team_alias) so they are accessible via custom_prometheus_metadata_labels configuration. """ - if not isinstance(standard_logging_payload, dict): - return {} + return _get_combined_custom_metadata_from_standard_logging_metadata( + standard_logging_payload.get("metadata") if isinstance(standard_logging_payload, dict) else None + ) - standard_logging_metadata: Final = standard_logging_payload.get("metadata") or {} + +def _get_combined_custom_metadata_from_standard_logging_metadata( + standard_logging_metadata: dict | 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): return {} From 3e504e7ec99f95e8de664ef90d1808cf45245668 Mon Sep 17 00:00:00 2001 From: TSKVenkat Date: Fri, 28 Aug 2026 23:48:39 +0530 Subject: [PATCH 4/4] 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")