roboflow/supervision · error · ValueError

Number of ref tags ({len(label_segments)}) and det tags ({le

Error message

Number of ref tags ({len(label_segments)}) and det tags ({len(detection_segments)}) in the result must be equal.

What it means

Error "Number of ref tags ({len(label_segments)}) and det tags ({len(detection_segments)}) in the result must be equal." thrown in roboflow/supervision.

Source

Thrown at src/supervision/detection/vlm.py:466

        resolution_wh: Tuple (width, height) to which we scale the box coordinates.
        classes: Optional list of valid class names. If provided, boxes and labels not
            in this list are filtered out.

    Returns:
        A tuple of `(xyxy, class_id, class_name)` where `xyxy` is an array of
            shape `(n, 4)` in format `[x1, y1, x2, y2]`, `class_id` is an
            optional array of shape `(n,)` with class indices, and `class_name`
            is an array of shape `(n,)` with class labels. When the input
            contains no detections (or all are filtered by `classes`), returns
            `(np.empty((0, 4)), np.empty(0), np.empty(0))`.
    """  # noqa: E501

    width, height = resolution_wh
    label_segments = re.findall(r"<\|ref\|>(.*?)<\|/ref\|>", result, flags=re.S)
    detection_segments = re.findall(r"<\|det\|>(.*?)<\|/det\|>", result, flags=re.S)

    if len(label_segments) != len(detection_segments):
        raise ValueError(
            f"Number of ref tags ({len(label_segments)}) "
            f"and det tags ({len(detection_segments)}) in the result must be equal."
        )

    xyxy_list: list[list[float]] = []
    class_name_list: list[str] = []
    for label, detection_blob in zip(label_segments, detection_segments):
        current_class_name = label.strip()
        for box in re.findall(r"\[(.*?)\]", detection_blob):
            x1, y1, x2, y2 = map(float, box.strip("[]").split(","))
            xyxy_list.append(
                [
                    (x1 / 999 * width),
                    (y1 / 999 * height),
                    (x2 / 999 * width),
                    (y2 / 999 * height),
                ]
            )

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Ensure the model output contains an equal number of <ref> and <det> tag pairs; regenerate or repair the prompt/response.
  2. If parsing a custom output, align each reference label segment with exactly one detection segment before calling the parser.

When it happens

Trigger: Thrown at src/supervision/detection/vlm.py:466 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15). Data as JSON: /api/errors/8a5d86c30871d9d8. Report an issue: GitHub.