{"record":{"id":"d9d45a3702cd4137","repo":"roboflow/supervision","slug":"the-provided-detections-do-not-contain-confidence","errorCode":null,"errorMessage":"The provided detections do not contain confidence values. Please provide `custom_values` or ensure that the detections contain confidence values (e.g. by using a different model).","messagePattern":"The provided detections do not contain confidence values\\. Please provide `custom_values` or ensure that the detections contain confidence values \\(e\\.g\\. by using a different model\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/annotators/core.py","lineNumber":2976,"sourceCode":"            )\n        elif position == Position.CENTER_RIGHT:\n            return (cx, cy - height // 2), (cx + width, cy + height // 2)\n        elif position == Position.BOTTOM_LEFT:\n            return (cx - width, cy), (cx, cy + height)\n        elif position == Position.BOTTOM_CENTER:\n            return (cx - width // 2, cy), (cx + width // 2, cy + height)\n        elif position == Position.BOTTOM_RIGHT:\n            return (cx, cy), (cx + width, cy + height)\n        raise ValueError(f\"Unsupported position: {position}\")\n\n    @staticmethod\n    def _validate_custom_values(\n        custom_values: npt.NDArray[np.float64] | list[float] | None,\n        detections: Detections,\n    ) -> None:\n        if custom_values is None:\n            if detections.confidence is None:\n                raise ValueError(\n                    \"The provided detections do not contain confidence values. \"\n                    \"Please provide `custom_values` or ensure that the detections \"\n                    \"contain confidence values (e.g. by using a different model).\"\n                )\n\n        else:\n            if not isinstance(custom_values, (np.ndarray, list)):\n                raise TypeError(\n                    \"custom_values must be either a numpy array or a list of floats.\"\n                )\n\n            if len(custom_values) != len(detections):\n                raise ValueError(\n                    \"The length of custom_values must match the number of detections.\"\n                )\n\n            if not all(0 <= value <= 1 for value in custom_values):\n                raise ValueError(\"All values in custom_values must be between 0 and 1.\")","sourceCodeStart":2958,"sourceCodeEnd":2994,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/annotators/core.py#L2958-L2994","documentation":"Raised by `PercentageBarAnnotator._validate_custom_values` when `custom_values` is None and the detections lack a `confidence` array. The annotator draws a 0-1 bar per detection, defaulting to confidence scores; with neither custom values nor confidence there is nothing valid to render, so it fails before drawing.","triggerScenarios":"Constructing `sv.Detections(xyxy=..., class_id=...)` with no `confidence` and calling `sv.PercentageBarAnnotator().annotate(scene, detections)`; annotating outputs of a model/connector that does not populate confidence; class-agnostic or hand-assembled detections in tests.","commonSituations":"Prototyping with hand-built Detections fixtures that skip confidence; pipelines using annotators on tracker outputs from a path that strips confidence; models whose connector maps only boxes and class ids.","solutions":["Pass `custom_values` explicitly: a NumPy array or list with one 0-1 value per detection, e.g. normalized class scores.","Ensure the model output you build Detections from includes confidence (most `from_*` connectors map it).","If bars should show something other than confidence (e.g. speed), supply it via custom_values."],"exampleFix":"# before\nannotator = sv.PercentageBarAnnotator()\ndetections = sv.Detections(xyxy=boxes, class_id=ids)  # no confidence\nannotator.annotate(scene, detections)  # ValueError\n\n# after\nannotator = sv.PercentageBarAnnotator()\ndetections = sv.Detections(xyxy=boxes, class_id=ids, confidence=scores)\n# or: annotator.annotate(scene, detections, custom_values=normalized_scores)","handlingStrategy":"type-guard","validationCode":"if detections.confidence is None and custom_values is None:\n    custom_values = np.ones(len(detections))  # or compute real scores\nannotator.annotate(scene, detections, custom_values=custom_values)","typeGuard":"def can_draw_percentage_bars(detections, custom_values=None) -> bool:\n    return custom_values is not None or detections.confidence is not None","tryCatchPattern":null,"preventionTips":["Ensure Detections built by hand include confidence.","Supply custom_values whenever confidence is absent."],"tags":["annotators","validation","detections"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}