{"record":{"id":"1313959d9ac5427d","repo":"roboflow/supervision","slug":"the-number-of-line-zones-and-their-labels-must-mat","errorCode":null,"errorMessage":"The number of line zones and their labels must match.","messagePattern":"The number of line zones and their labels must match\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/line_zone.py","lineNumber":831,"sourceCode":"        line_zone_labels: list[str] | None = None,\n    ) -> npt.NDArray[np.uint8]:\n        \"\"\"\n        Draws a table with the number of objects of each class that crossed each line.\n\n        Args:\n            frame: The image on which the table will be drawn.\n            line_zones: The line zones to be annotated.\n            line_zone_labels: The labels, one for each line zone. If not\n                provided, the default labels will be used.\n\n        Returns:\n            The image with the table drawn on it.\n\n        \"\"\"\n        if line_zone_labels is None:\n            line_zone_labels = [f\"Line {i + 1}:\" for i in range(len(line_zones))]\n        if len(line_zones) != len(line_zone_labels):\n            raise ValueError(\"The number of line zones and their labels must match.\")\n\n        text_lines = [\"Line Crossings:\"]\n        for line_zone, line_zone_label in zip(line_zones, line_zone_labels):\n            text_lines.append(line_zone_label)\n            class_id_to_name = line_zone.class_id_to_name\n\n            for direction, count_per_class in [\n                (\"In\", line_zone.in_count_per_class),\n                (\"Out\", line_zone.out_count_per_class),\n            ]:\n                if not count_per_class:\n                    continue\n\n                text_lines.append(f\" {direction}:\")\n                for class_id, count in count_per_class.items():\n                    if self.force_draw_class_ids:\n                        class_name = str(class_id)\n                    elif class_id is None:","sourceCodeStart":813,"sourceCodeEnd":849,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/line_zone.py#L813-L849","documentation":"LineZoneAnnotator.annotate(frame, line_zones, line_zone_labels) requires one label per line zone; when explicit labels are provided their count must equal len(line_zones). Labels are zipped with zones to render per-zone crossing counts, so a mismatch means ambiguous output and is rejected.","triggerScenarios":"Passing 3 zones with 2 labels (e.g. reusing a hardcoded label list after adding a zone), or a label list generated from a different config section than the zones (['Entrance', 'Exit'] vs 4 configured zones).","commonSituations":"Zones defined in a config file and labels hardcoded in code, drifting out of sync; iterating a subset of zones but not the labels; adding a new zone during a demo without updating labels.","solutions":["Build labels from the zones themselves: line_zone_labels=[f'Zone {i+1}' for i in range(len(zones))] or omit them to get defaults.","Keep zones and labels in the same config block so they cannot diverge.","Add an assert len(line_zones) == len(labels) near where either is defined."],"exampleFix":"# before\n annotator.annotate(\n     frame=frame,\n     line_zones=zones,               # 3 zones\n     line_zone_labels=[\"In\", \"Out\"],  # 2 labels\n )\n\n# after\n annotator.annotate(\n     frame=frame,\n     line_zones=zones,\n     line_zone_labels=[f\"Zone {i + 1}\" for i in range(len(zones))],\n )","handlingStrategy":"validation","validationCode":"if line_zone_labels is not None:\n    assert len(line_zones) == len(line_zone_labels), (\n        f\"{len(line_zones)} zones vs {len(line_zone_labels)} labels\"\n    )\nannotator.annotate(frame=frame, line_zones=line_zones, line_zone_labels=line_zone_labels)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive labels from zones: [f'Zone {i+1}' for i in range(len(zones))].","Keep zones and labels in the same config block.","Omit labels entirely to get defaults when custom text is not needed."],"tags":["line-zone","annotator","length-mismatch","validation"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}