{"record":{"id":"83910b46abc015a0","repo":"Comfy-Org/ComfyUI","slug":"bboxes-element-is-missing-a-valid-bbox-ymin-xm","errorCode":null,"errorMessage":"bboxes element is missing a valid 'bbox' [ymin, xmin, ymax, xmax]","messagePattern":"bboxes element is missing a valid 'bbox' \\[ymin, xmin, ymax, xmax\\]","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_bounding_boxes.py","lineNumber":213,"sourceCode":"\n\ndef _looks_like_element(box: dict) -> bool:\n    bbox = box.get(\"bbox\")\n    return isinstance(bbox, (list, tuple)) and len(bbox) == 4\n\n\ndef _looks_like_bbox(box: dict) -> bool:\n    return all(key in box for key in (\"x\", \"y\", \"width\", \"height\"))\n\n\ndef elements_to_boxes(elements: list, width: int, height: int) -> list:\n    boxes = []\n    for element in elements:\n        if not isinstance(element, dict):\n            continue\n        bbox = element.get(\"bbox\")\n        if not (isinstance(bbox, (list, tuple)) and len(bbox) == 4):\n            raise ValueError(\"bboxes element is missing a valid 'bbox' [ymin, xmin, ymax, xmax]\")\n        try:\n            ymin, xmin, ymax, xmax = (float(v) / 1000.0 for v in bbox)\n        except (TypeError, ValueError):\n            raise ValueError(\"bboxes element 'bbox' must contain four numbers\")\n        etype = \"text\" if element.get(\"type\") == \"text\" else \"obj\"\n        boxes.append({\n            \"x\": round(min(xmin, xmax) * width),\n            \"y\": round(min(ymin, ymax) * height),\n            \"width\": round(abs(xmax - xmin) * width),\n            \"height\": round(abs(ymax - ymin) * height),\n            \"metadata\": {\n                \"type\": etype,\n                \"text\": element.get(\"text\", \"\") if etype == \"text\" else \"\",\n                \"desc\": element.get(\"desc\", \"\"),\n                \"palette\": element.get(\"color_palette\", []) or [],\n            },\n        })\n    return boxes","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_bounding_boxes.py#L195-L231","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Normalize the upstream JSON so every element has bbox: [ymin, xmin, ymax, xmax] with 4 numeric values","Validate elements with a guard (all four numbers present, len==4) before passing them in","If the source uses dict coordinates, map them to the 4-list format before calling elements_to_boxes"],"exampleFix":"// before\n{\"type\": \"text\", \"text\": \"hi\", \"bbox\": {\"ymin\": 0, \"xmin\": 0, \"ymax\": 100, \"xmax\": 100}}\n\n// after\n{\"type\": \"text\", \"text\": \"hi\", \"bbox\": [0, 0, 100, 100]}","handlingStrategy":"validation","validationCode":"def has_valid_bbox(el: dict) -> bool:\n    b = el.get('bbox')\n    return isinstance(b, (list, tuple)) and len(b) == 4","typeGuard":"from typing import Any, Optional\n\ndef is_element(v: Any) -> bool:\n    return isinstance(v, dict) and isinstance(v.get('bbox'), (list, tuple)) and len(v['bbox']) == 4","tryCatchPattern":"try:\n    boxes = elements_to_boxes(elements, w, h)\nexcept ValueError as e:\n    if \"missing a valid 'bbox'\" in str(e):\n        elements = [el for el in elements if has_valid_bbox(el)]\n        boxes = elements_to_boxes(elements, w, h)\n    else:\n        raise","preventionTips":["Emit bbox as a 4-number list [ymin, xmin, ymax, xmax] from upstream producers","Validate each element's bbox shape before batch conversion","When generating JSON with an LLM, include a schema example with exact key names"],"tags":["json","bounding-box","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}