Comfy-Org/ComfyUI · error · ValueError

bboxes element is missing a valid 'bbox' [ymin, xmin, ymax,

Error message

bboxes element is missing a valid 'bbox' [ymin, xmin, ymax, xmax]

What it means

elements_to_boxes converts UI 'element' dicts into pixel boxes. Each element must carry a 'bbox' key holding a list/tuple of exactly 4 numbers (normalized 0-1000 order ymin, xmin, ymax, xmax). If bbox is absent, not a list/tuple, or has a length other than 4, this ValueError fires.

Source

Thrown at comfy_extras/nodes_bounding_boxes.py:213


def _looks_like_element(box: dict) -> bool:
    bbox = box.get("bbox")
    return isinstance(bbox, (list, tuple)) and len(bbox) == 4


def _looks_like_bbox(box: dict) -> bool:
    return all(key in box for key in ("x", "y", "width", "height"))


def elements_to_boxes(elements: list, width: int, height: int) -> list:
    boxes = []
    for element in elements:
        if not isinstance(element, dict):
            continue
        bbox = element.get("bbox")
        if not (isinstance(bbox, (list, tuple)) and len(bbox) == 4):
            raise ValueError("bboxes element is missing a valid 'bbox' [ymin, xmin, ymax, xmax]")
        try:
            ymin, xmin, ymax, xmax = (float(v) / 1000.0 for v in bbox)
        except (TypeError, ValueError):
            raise ValueError("bboxes element 'bbox' must contain four numbers")
        etype = "text" if element.get("type") == "text" else "obj"
        boxes.append({
            "x": round(min(xmin, xmax) * width),
            "y": round(min(ymin, ymax) * height),
            "width": round(abs(xmax - xmin) * width),
            "height": round(abs(ymax - ymin) * height),
            "metadata": {
                "type": etype,
                "text": element.get("text", "") if etype == "text" else "",
                "desc": element.get("desc", ""),
                "palette": element.get("color_palette", []) or [],
            },
        })
    return boxes

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Normalize the upstream JSON so every element has bbox: [ymin, xmin, ymax, xmax] with 4 numeric values
  2. Validate elements with a guard (all four numbers present, len==4) before passing them in
  3. If the source uses dict coordinates, map them to the 4-list format before calling elements_to_boxes

Example fix

// before
{"type": "text", "text": "hi", "bbox": {"ymin": 0, "xmin": 0, "ymax": 100, "xmax": 100}}

// after
{"type": "text", "text": "hi", "bbox": [0, 0, 100, 100]}
Defensive patterns

Strategy: validation

Validate before calling

def has_valid_bbox(el: dict) -> bool:
    b = el.get('bbox')
    return isinstance(b, (list, tuple)) and len(b) == 4

Type guard

from typing import Any, Optional

def is_element(v: Any) -> bool:
    return isinstance(v, dict) and isinstance(v.get('bbox'), (list, tuple)) and len(v['bbox']) == 4

Try / catch

try:
    boxes = elements_to_boxes(elements, w, h)
except ValueError as e:
    if "missing a valid 'bbox'" in str(e):
        elements = [el for el in elements if has_valid_bbox(el)]
        boxes = elements_to_boxes(elements, w, h)
    else:
        raise

Prevention

When it happens

Trigger: Passing elements whose 'bbox' is a dict ({'ymin':..}), a string like '0,0,1,1', a 5-value array, or omitted entirely; LLM-generated element JSON that omits bbox on some entries.

Common situations: Feeding vision-model/LLM JSON output into the boxes pipeline where bbox formatting drifts (extra confidence field first, dict-style coordinates, or 3 values after rounding).

Related errors


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