invoke-ai/InvokeAI · error · ValueError

If both point_lists and bounding_boxes are provided, they mu

Error message

If both point_lists and bounding_boxes are provided, they must have the same length.

What it means

This is a pydantic model_validator on the Segment Anything invocation: when both point_lists and bounding_boxes are supplied they are consumed as parallel per-prompt lists, so unequal lengths are invalid and validation fails before invoke runs.

Source

Thrown at invokeai/app/invocations/segment_anything.py:87

    )
    point_lists: list[SAMPointsField] | None = InputField(
        default=None,
        description="The list of point lists to prompt the model with. Each list of points represents a single object.",
    )
    apply_polygon_refinement: bool = InputField(
        description="Whether to apply polygon refinement to the masks. This will smooth the edges of the masks slightly and ensure that each mask consists of a single closed polygon (before merging).",
        default=True,
    )
    mask_filter: Literal["all", "largest", "highest_box_score"] = InputField(
        description="The filtering to apply to the detected masks before merging them into a final output.",
        default="all",
    )

    @model_validator(mode="after")
    def validate_points_and_boxes_len(self):
        if self.point_lists is not None and self.bounding_boxes is not None:
            if len(self.point_lists) != len(self.bounding_boxes):
                raise ValueError("If both point_lists and bounding_boxes are provided, they must have the same length.")
        return self

    @torch.no_grad()
    def invoke(self, context: InvocationContext) -> MaskOutput:
        # The models expect a 3-channel RGB image.
        image_pil = context.images.get_pil(self.image.image_name, mode="RGB")

        if (not self.bounding_boxes or len(self.bounding_boxes) == 0) and (
            not self.point_lists or len(self.point_lists) == 0
        ):
            combined_mask = torch.zeros(image_pil.size[::-1], dtype=torch.bool)
        else:
            masks = self._segment(context=context, image=image_pil)
            masks = self._filter_masks(masks=masks, bounding_boxes=self.bounding_boxes)

            # masks contains bool values, so we merge them via max-reduce.
            combined_mask, _ = torch.stack(masks).max(dim=0)

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Make point_lists and bounding_boxes the same length (pad or trim entries).
  2. If you only want points, clear the bounding_boxes input entirely (and vice versa).
  3. Re-check the node inputs in the workflow editor after copy/paste or batch edits.

Example fix

// before
point_lists=[[10,10],[50,50]], bounding_boxes=[bbox_a]
// after
point_lists=[[10,10],[50,50]], bounding_boxes=[bbox_a, bbox_b]
Defensive patterns

Strategy: validation

Validate before calling

pts, bbs = node.point_lists, node.bounding_boxes
if pts is not None and bbs is not None and len(pts) != len(bbs):
    raise ValueError("point_lists and bounding_boxes must be the same length")

Type guard

null

Try / catch

try:
    node.validate_inputs()
except ValueError as e:
    if "same length" in str(e):
        align_point_and_box_lengths(node)
    else:
        raise

Prevention

When it happens

Trigger: Providing N point_lists but M bounding_boxes (N != M) on the Segment Anything node; e.g. editing one list in the workflow UI without updating the other.

Common situations: Duplicating a node and editing only one input; programmatically generating node inputs with mismatched array lengths; removing an entry from one list only.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/f27aac2fcdc1d727. Report an issue: GitHub.