{"record":{"id":"4810f802fed2136c","repo":"Comfy-Org/ComfyUI","slug":"bboxes-element-bbox-must-contain-four-numbers","errorCode":null,"errorMessage":"bboxes element 'bbox' must contain four numbers","messagePattern":"bboxes element 'bbox' must contain four numbers","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_bounding_boxes.py","lineNumber":217,"sourceCode":"    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\n\n\ndef boxes_from_input(data, width: int, height: int) -> list:\n    if data is None:","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_bounding_boxes.py#L199-L235","documentation":"After confirming bbox is a 4-item sequence, elements_to_boxes converts each entry with float(v)/1000.0; if any entry is None, a non-numeric string, or a nested list, float() raises TypeError/ValueError which is caught and re-raised as this clearer message.","triggerScenarios":"bbox = [0, 0, 'n/a', 500]; bbox containing None (common in JSON with missing optional fields); bbox = [[0],[0],[1],[1]] nested lists; strings with units like '50px'.","commonSituations":"Hand-written or LLM-generated bbox JSON with nulls for undetected coordinates; scraped data where coordinates are strings with whitespace/units.","solutions":["Sanitize bbox entries: replace None/invalid with 0 or drop the element before conversion","Coerce strings to floats upstream ([float(v) if str else v]) or strip units","Validate each element's bbox numerics before passing to elements_to_boxes"],"exampleFix":"// before\n{\"bbox\": [0, 0, null, 500]}\n\n// after\n{\"bbox\": [0, 0, 0, 500]}","handlingStrategy":"validation","validationCode":"def bbox_numbers_ok(el: dict) -> bool:\n    b = el.get('bbox')\n    if not (isinstance(b, (list, tuple)) and len(b) == 4):\n        return False\n    return all(isinstance(v, (int, float)) and not isinstance(v, bool) for v in b)","typeGuard":"def has_numeric_bbox(el: dict) -> bool:\n    b = el.get('bbox', ())\n    return len(b) == 4 and all(isinstance(v, (int, float)) for v in b)","tryCatchPattern":"try:\n    boxes = elements_to_boxes(elements, w, h)\nexcept ValueError as e:\n    if 'must contain four numbers' in str(e):\n        for el in elements:\n            el['bbox'] = [float(v) if not isinstance(v, bool) else 0 for v in el.get('bbox', [0,0,0,0])]\n        boxes = elements_to_boxes(elements, w, h)\n    else:\n        raise","preventionTips":["Coerce or drop None/non-numeric coordinates before conversion","Validate numeric types at the JSON ingest boundary","Strip units from coordinate strings upstream"],"tags":["json","bounding-box","type-coercion"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}