Comfy-Org/ComfyUI · error · ValueError

bboxes items must be bounding boxes (x, y, width, height) or

Error message

bboxes items must be bounding boxes (x, y, width, height) or elements (with a 'bbox')

What it means

For list input, boxes_from_input dispatches on the first item: a list means corner boxes, a dict means elements or x/y/width/height boxes. A dict first item that has neither a bbox key nor all of x/y/width/height triggers this error (the per-item analogue of 837).

Source

Thrown at comfy_extras/nodes_bounding_boxes.py:268

        raise ValueError(
            "bboxes dict must be a bounding box (x, y, width, height) or an element (with a 'bbox')"
        )
    if not isinstance(data, list):
        raise ValueError(
            "bboxes input must be bounding boxes, elements, or a JSON string, "
            f"got {type(data).__name__}"
        )
    if not data:
        return []
    first = data[0]
    if isinstance(first, list):
        return normalize_incoming_boxes(data)
    if isinstance(first, dict):
        if _looks_like_element(first):
            return elements_to_boxes(data, width, height)
        if _looks_like_bbox(first):
            return normalize_incoming_boxes(data)
        raise ValueError(
            "bboxes items must be bounding boxes (x, y, width, height) or elements (with a 'bbox')"
        )
    raise ValueError(
        f"bboxes list must contain bounding boxes or elements, got {type(first).__name__}"
    )


def _norm_bbox(region: dict) -> list[int]:
    def grid(value: float) -> int:
        return max(0, min(1000, round(value * 1000)))

    x, y = region.get("x", 0.0), region.get("y", 0.0)
    w, h = region.get("w", 0.0), region.get("h", 0.0)
    ymin, xmin, ymax, xmax = grid(y), grid(x), grid(y + h), grid(x + w)
    if ymin > ymax:
        ymin, ymax = ymax, ymin
    if xmin > xmax:
        xmin, xmax = xmax, xmin

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Normalize every dict in the list to x/y/width/height or element+bbox schema, not just the first
  2. Filter out empty/malformed entries before passing the list
  3. Add a pre-validation pass that reports which indices fail the schema so fixes are targeted

Example fix

// before
[{"x1": 0, "y1": 0, "x2": 50, "y2": 50}, {"x": 0, "y": 0, "width": 10, "height": 10}]

// after
[{"x": 0, "y": 0, "width": 50, "height": 50}, {"x": 0, "y": 0, "width": 10, "height": 10}]
Defensive patterns

Strategy: validation

Validate before calling

def normalize_box_items(items):
    out = []
    for it in items:
        if isinstance(it, dict):
            if all(k in it for k in ('x', 'y', 'width', 'height')):
                out.append(it)
            elif isinstance(it.get('bbox'), (list, tuple)) and len(it['bbox']) == 4:
                out.append(it)
            # else: log and drop malformed entry
    return out

Type guard

def is_valid_box_item(it) -> bool:
    if not isinstance(it, dict):
        return False
    return all(k in it for k in ('x', 'y', 'width', 'height')) or (
        isinstance(it.get('bbox'), (list, tuple)) and len(it['bbox']) == 4)

Try / catch

try:
    boxes = boxes_from_input(data, w, h)
except ValueError as e:
    if 'must be bounding boxes' in str(e) or 'list must contain' in str(e):
        data = [it for it in data if is_valid_box_item(it)]
        boxes = boxes_from_input(data, w, h)
    else:
        raise

Prevention

When it happens

Trigger: A list of dicts using alternate key conventions ({'x1','y1','x2','y2'}, {'top','left',...}, {'w','h'}); mixed lists where only some entries are malformed; empty dict entries {} from filtered upstream data.

Common situations: Batch-converting another tool's bbox list where one or more entries use a different schema; LLM output lists with inconsistent keys across items.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/7a22ce87cf4c41c5. Report an issue: GitHub.