{"record":{"id":"f27aac2fcdc1d727","repo":"invoke-ai/InvokeAI","slug":"if-both-point-lists-and-bounding-boxes-are-provide","errorCode":null,"errorMessage":"If both point_lists and bounding_boxes are provided, they must have the same length.","messagePattern":"If both point_lists and bounding_boxes are provided, they must have the same length\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/segment_anything.py","lineNumber":87,"sourceCode":"    )\n    point_lists: list[SAMPointsField] | None = InputField(\n        default=None,\n        description=\"The list of point lists to prompt the model with. Each list of points represents a single object.\",\n    )\n    apply_polygon_refinement: bool = InputField(\n        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).\",\n        default=True,\n    )\n    mask_filter: Literal[\"all\", \"largest\", \"highest_box_score\"] = InputField(\n        description=\"The filtering to apply to the detected masks before merging them into a final output.\",\n        default=\"all\",\n    )\n\n    @model_validator(mode=\"after\")\n    def validate_points_and_boxes_len(self):\n        if self.point_lists is not None and self.bounding_boxes is not None:\n            if len(self.point_lists) != len(self.bounding_boxes):\n                raise ValueError(\"If both point_lists and bounding_boxes are provided, they must have the same length.\")\n        return self\n\n    @torch.no_grad()\n    def invoke(self, context: InvocationContext) -> MaskOutput:\n        # The models expect a 3-channel RGB image.\n        image_pil = context.images.get_pil(self.image.image_name, mode=\"RGB\")\n\n        if (not self.bounding_boxes or len(self.bounding_boxes) == 0) and (\n            not self.point_lists or len(self.point_lists) == 0\n        ):\n            combined_mask = torch.zeros(image_pil.size[::-1], dtype=torch.bool)\n        else:\n            masks = self._segment(context=context, image=image_pil)\n            masks = self._filter_masks(masks=masks, bounding_boxes=self.bounding_boxes)\n\n            # masks contains bool values, so we merge them via max-reduce.\n            combined_mask, _ = torch.stack(masks).max(dim=0)\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/segment_anything.py#L69-L105","documentation":"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.","triggerScenarios":"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.","commonSituations":"Duplicating a node and editing only one input; programmatically generating node inputs with mismatched array lengths; removing an entry from one list only.","solutions":["Make point_lists and bounding_boxes the same length (pad or trim entries).","If you only want points, clear the bounding_boxes input entirely (and vice versa).","Re-check the node inputs in the workflow editor after copy/paste or batch edits."],"exampleFix":"// before\npoint_lists=[[10,10],[50,50]], bounding_boxes=[bbox_a]\n// after\npoint_lists=[[10,10],[50,50]], bounding_boxes=[bbox_a, bbox_b]","handlingStrategy":"validation","validationCode":"pts, bbs = node.point_lists, node.bounding_boxes\nif pts is not None and bbs is not None and len(pts) != len(bbs):\n    raise ValueError(\"point_lists and bounding_boxes must be the same length\")","typeGuard":"null","tryCatchPattern":"try:\n    node.validate_inputs()\nexcept ValueError as e:\n    if \"same length\" in str(e):\n        align_point_and_box_lengths(node)\n    else:\n        raise","preventionTips":["Edit point_lists and bounding_boxes together as paired entries","Review both inputs after duplicating Segment Anything nodes","Validate workflow JSON programmatically before enqueueing batch runs"],"tags":["validation","pydantic","segment-anything"],"backgroundTag":"input-validation-failed","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}