Comfy-Org/ComfyUI · error · ValueError

bboxes string input is not valid JSON: {exc}

Error message

bboxes string input is not valid JSON: {exc}

What it means

The compositor's `_bbox_list` accepts the bboxes input either as a Python list or as a JSON string. When a string is given, it is stripped and parsed with json.loads; if parsing fails (JSONDecodeError or ValueError) the parser re-raises with this message including the underlying parse error. Only a completely empty/whitespace string is treated as 'no boxes'.

Source

Thrown at comfy_extras/nodes_compositor.py:73

    w, h = _int(canvas[0], 0), _int(canvas[1], 0)
    return (w, h) if w > 0 and h > 0 else None


def _int(value, default: int) -> int:
    return int(value) if isinstance(value, (int, float)) and not isinstance(value, bool) else default


def _bbox_list(bboxes, canvas_width: int, canvas_height: int) -> list[dict]:
    if bboxes is None:
        return []
    if isinstance(bboxes, str):
        text = bboxes.strip()
        if not text:
            return []
        try:
            bboxes = json.loads(text)
        except (json.JSONDecodeError, ValueError) as exc:
            raise ValueError(f"bboxes string input is not valid JSON: {exc}") from exc
    probe = bboxes if isinstance(bboxes, list) else [bboxes]
    if probe and isinstance(probe[0], list):
        probe = probe[0]
    has_elements = any(
        isinstance(box, dict) and isinstance(box.get("bbox"), (list, tuple))
        for box in probe
    )
    if has_elements and (canvas_width <= 0 or canvas_height <= 0):
        raise ValueError(
            "normalized element boxes need canvas_width and canvas_height to resolve to pixels"
        )
    return boxes_from_input(bboxes, canvas_width, canvas_height)


def _item_mask_frame(mask, index: int) -> torch.Tensor | None:
    if not isinstance(mask, torch.Tensor):
        return None
    if mask.shape[0] == 1:

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Send strict JSON: double quotes, no trailing commas, complete brackets.
  2. Strip markdown fences and any surrounding prose so the string is pure JSON.
  3. Replace single-quoted Python reprs with properly serialized JSON (json.dumps on the Python side).
  4. If the widget content is optional, leave it empty rather than partially edited.

Example fix

// before
bboxes = "[[0, 0, 10, 10], [20, 20, 30, 30]]"  // or a truncated string
// after
bboxes = "[[0, 0, 10, 10], [20, 20, 30, 30]]"
Defensive patterns

Strategy: validation

Validate before calling

import json
def parse_bbox_string(s: str):
    s = s.strip()
    if s.startswith("```"):
        s = s.strip("`").lstrip("json").strip()
    if not s:
        return []
    return json.loads(s)  # let JSONDecodeError surface clearly

Type guard

def is_json_string(s) -> bool:
    if not isinstance(s, str) or not s.strip():
        return False
    try:
        json.loads(s)
        return True
    except (json.JSONDecodeError, ValueError):
        return False

Try / catch

try:
    boxes = json.loads(text)
except json.JSONDecodeError as exc:
    raise ValueError(f"model output was not valid JSON boxes: {exc}") from exc

Prevention

When it happens

Trigger: Wiring a text widget or LLM/text output into bboxes that is not valid JSON, e.g. "[[10, 10, 50, 50]," (truncated), "(10, 10, 50, 50)" (Python repr, not JSON), or text with leading prose like 'Here are the boxes: [...]'.

Common situations: Pasting Python-style lists with single quotes ('[[0,0,10,10]]' is invalid JSON because of quote style); truncated API responses; agent-generated text that wraps JSON in markdown fences or commentary instead of raw JSON.

Related errors


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