invoke-ai/InvokeAI · error · ValueError
Either bounding_box or points must be provided
Error message
Either bounding_box or points must be provided
What it means
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.
Source
Thrown at invokeai/backend/image_util/segment_anything/shared.py:48
negative = -1
neutral = 0
positive = 1
class SAMPoint(BaseModel):
x: int = Field(..., description="The x-coordinate of the point")
y: int = Field(..., description="The y-coordinate of the point")
label: SAMPointLabel = Field(..., description="The label of the point")
class SAMInput(BaseModel):
bounding_box: BoundingBox | None = Field(None, description="The bounding box to use for segmentation")
points: list[SAMPoint] | None = Field(None, description="The points to use for segmentation")
@model_validator(mode="after")
def check_input(self):
if not self.bounding_box and not self.points:
raise ValueError("Either bounding_box or points must be provided")
return self
View on GitHub (pinned to 0b6a024f2f)
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.
Example fix
// before SAMInput() # or SAMInput(bounding_box=None, points=[]) // after SAMInput(points=[SAMPoint(x=250, y=180, label=SAMPointLabel.positive)])
Defensive patterns
Strategy: validation
Validate before calling
def validate_sam_input(payload: dict) -> dict | None:
if not payload.get("bounding_box") and not payload.get("points"):
return None
return payload Type guard
def has_prompt(s: SAMInput) -> bool:
return bool(s.bounding_box) or bool(s.points) Try / catch
try:
sam_input = SAMInput(**payload)
except ValueError as e:
raise UserInputError("Please select a region or at least one point before running segmentation.") from e Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- stop must be greater than start
- cfg_scale must be greater than 1
- Face IDs must be a comma-separated list of integers (e.g. "1
- cfg_scale values must be finite.
- shift must be finite.
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/27190e18493e540e.
Report an issue: GitHub.