{"record":{"id":"4bbc68f4084d62a9","repo":"roboflow/supervision","slug":"precision-metric-requires-class-id-and-confiden","errorCode":null,"errorMessage":"Precision metric requires `class_id` and `confidence` on predictions.","messagePattern":"Precision metric requires `class_id` and `confidence` on predictions\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/metrics/precision.py","lineNumber":188,"sourceCode":"            prediction_size_mask = np.ones(len(predictions), dtype=bool)\n            target_size_mask = np.ones(len(targets), dtype=bool)\n            if size_category != ObjectSizeCategory.ANY:\n                if len(predictions) > 0:\n                    prediction_size_mask = (\n                        get_detection_size_category(predictions, self._metric_target)\n                        == size_category.value\n                    )\n                if len(targets) > 0:\n                    target_size_mask = (\n                        get_detection_size_category(targets, self._metric_target)\n                        == size_category.value\n                    )\n\n            if len(targets) == 0 and len(predictions) > 0:\n                # Only predictions are present (e.g. a background image); every\n                # prediction is a false positive.\n                if predictions.class_id is None or predictions.confidence is None:\n                    raise ValueError(\n                        \"Precision metric requires `class_id` and `confidence` \"\n                        \"on predictions.\"\n                    )\n                prediction_class_ids = np.asarray(predictions.class_id, dtype=np.int32)[\n                    prediction_size_mask\n                ]\n                prediction_confidence = np.asarray(\n                    predictions.confidence, dtype=np.float32\n                )[prediction_size_mask]\n                if len(prediction_class_ids) == 0:\n                    continue\n                stats.append(\n                    (\n                        np.zeros(\n                            (len(prediction_class_ids), iou_thresholds.size),\n                            dtype=np.bool_,\n                        ),\n                        np.zeros(","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/metrics/precision.py#L170-L206","documentation":"Error \"Precision metric requires `class_id` and `confidence` on predictions.\" thrown in roboflow/supervision.","triggerScenarios":"Thrown at src/supervision/metrics/precision.py:188 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure prediction Detections have both class_id and confidence set before computing Precision.","Populate class_id and confidence from your model outputs when constructing Detections."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}