{"record":{"id":"27190e18493e540e","repo":"invoke-ai/InvokeAI","slug":"either-bounding-box-or-points-must-be-provided","errorCode":null,"errorMessage":"Either bounding_box or points must be provided","messagePattern":"Either bounding_box or points must be provided","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/image_util/segment_anything/shared.py","lineNumber":48,"sourceCode":"    negative = -1\n    neutral = 0\n    positive = 1\n\n\nclass SAMPoint(BaseModel):\n    x: int = Field(..., description=\"The x-coordinate of the point\")\n    y: int = Field(..., description=\"The y-coordinate of the point\")\n    label: SAMPointLabel = Field(..., description=\"The label of the point\")\n\n\nclass SAMInput(BaseModel):\n    bounding_box: BoundingBox | None = Field(None, description=\"The bounding box to use for segmentation\")\n    points: list[SAMPoint] | None = Field(None, description=\"The points to use for segmentation\")\n\n    @model_validator(mode=\"after\")\n    def check_input(self):\n        if not self.bounding_box and not self.points:\n            raise ValueError(\"Either bounding_box or points must be provided\")\n        return self\n","sourceCodeStart":30,"sourceCodeEnd":50,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/image_util/segment_anything/shared.py#L30-L50","documentation":"SAMInput is a pydantic model that must contain at least one segmentation prompt: a bounding_box or a list of points. The model_validator `check_input` raises this error when both are None/empty. SAM cannot run without at least one prompt indicating where to segment.","triggerScenarios":"Constructing SAMInput() with neither field set, passing points=[] (empty list is falsy), passing bounding_box=None and omitting points, or deserializing JSON that omits both keys.","commonSituations":"Building the request programmatically where a UI selection was empty, conditionally assembling a payload and dropping both prompt fields, or an upstream API returning null for the region of interest.","solutions":["Provide a bounding_box, e.g. SAMInput(bounding_box=BoundingBox(x_min=..., x_max=..., y_min=..., y_max=...)).","Or provide at least one SAMPoint, e.g. SAMInput(points=[SAMPoint(x=..., y=..., label=SAMPointLabel.positive)]).","If the prompt comes from user input, validate that a selection exists before constructing SAMInput and surface a user-facing message instead."],"exampleFix":"// before\nSAMInput()  # or SAMInput(bounding_box=None, points=[])\n// after\nSAMInput(points=[SAMPoint(x=250, y=180, label=SAMPointLabel.positive)])","handlingStrategy":"validation","validationCode":"def validate_sam_input(payload: dict) -> dict | None:\n    if not payload.get(\"bounding_box\") and not payload.get(\"points\"):\n        return None\n    return payload","typeGuard":"def has_prompt(s: SAMInput) -> bool:\n    return bool(s.bounding_box) or bool(s.points)","tryCatchPattern":"try:\n    sam_input = SAMInput(**payload)\nexcept ValueError as e:\n    raise UserInputError(\"Please select a region or at least one point before running segmentation.\") from e","preventionTips":["In UI-driven flows, disable the segment action until a bounding box or point selection exists.","Never pass an empty points list as a valid prompt — falsy check treats [] as missing.","Require at least one positive SAMPoint when constructing points manually."],"tags":["validation","pydantic","segmentation","missing-argument"],"backgroundTag":"missing-required-prompt","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}