{"record":{"id":"c08808161c58dd9d","repo":"BerriAI/litellm","slug":"label-error-message","errorCode":null,"errorMessage":"{label_error.message}","messagePattern":"\\{label_error\\.message\\}","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/prometheus.py","lineNumber":832,"sourceCode":"                    if self._validate_single_metric_name(metric_name) is None:\n                        label_filters[metric_name] = config.include_labels\n\n        return label_filters\n\n    def _validate_configured_metric_labels(self, metric_name: str, labels: list[str]):\n        \"\"\"\n        Ensure that all the configured labels are valid for the metric\n\n        Raises ValueError if the metric labels are invalid and pretty prints the error\n        \"\"\"\n        label_error: Final = self._validate_single_metric_labels(metric_name, labels)\n        if label_error:\n            self._pretty_print_invalid_labels_error(\n                metric_name=label_error.metric_name,\n                invalid_labels=label_error.invalid_labels,\n                valid_labels=label_error.valid_labels,\n            )\n            raise ValueError(label_error.message)\n\n        return True\n\n    #########################################################\n    # Pretty print functions\n    #########################################################\n\n    def _pretty_print_validation_errors(self, validation_results: ValidationResults) -> None:\n        \"\"\"Pretty print all validation errors using rich\"\"\"\n        try:\n            from rich.console import Console\n            from rich.panel import Panel\n            from rich.table import Table\n            from rich.text import Text\n\n            console: Final = Console()\n\n            # Create error panel title","sourceCodeStart":814,"sourceCodeEnd":850,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/prometheus.py#L814-L850","documentation":"Before a metric is registered, _valid_metric_labels runs _validate_single_metric_labels for the (metric_name, labels) pair; on mismatch it pretty-prints the invalid labels versus the valid set for that metric and raises ValueError with the generated label_error.message. This is the per-call guard that backs the aggregate config validation, so it typically fires from programmatic registration rather than env parsing.","triggerScenarios":"Calling the label-validation path with e.g. ['end_user'] for a metric that does not support end_user, a tag not enabled via custom_prometheus_metadata_labels / tags, or any label outside _all_defined_labels() for that metric.","commonSituations":"Custom code building label sets dynamically from request metadata; teams enabling new tags in traffic but not in config; metric label sets shrinking between litellm versions.","solutions":["Use the pretty-printed invalid-vs-valid label table printed above the raise to correct the pair","Restrict dynamic labels to the intersection with the metric's valid labels before registering","Register custom metadata labels globally so they count as valid everywhere","Pin the litellm version and re-verify label sets on upgrade"],"exampleFix":"# before\nlabels = ['end_user', 'random_tag']  # random_tag not registered -> ValueError\ntrack_metric('litellm_proxy_total_requests_metric', labels)\n\n# after\nvalid = callback._validate_single_metric_labels('litellm_proxy_total_requests_metric', labels)\nif valid is None:\n    labels = [l for l in labels if l in valid_labels_for_metric]  # keep only supported\ntrack_metric('litellm_proxy_total_requests_metric', labels)","handlingStrategy":"validation","validationCode":"err = callback._validate_single_metric_labels(metric_name, candidate_labels)\nif err is not None:\n    raise ValueError(f'labels {err.invalid_labels} invalid for {err.metric_name}; valid: {err.valid_labels}')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter dynamic label sets through the validator before registering metrics","Register custom metadata labels via litellm.custom_prometheus_metadata_labels first","Re-run label validation suites after litellm upgrades"],"tags":["prometheus","metrics","labels","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}