invoke-ai/InvokeAI · error · ValueError

Invalid mask filter: {self.mask_filter}

Error message

Invalid mask filter: {self.mask_filter}

What it means

_filter_masks applies a masking/filtering mode chosen by mask_filter (e.g. highest-score bounding box). If mask_filter holds a value the implementation does not recognize, it falls through to a ValueError instead of silently applying no filter.

Source

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

        if self.mask_filter == "all":
            return masks
        elif self.mask_filter == "largest":
            # Find the largest mask.
            return [max(masks, key=lambda x: float(x.sum()))]
        elif self.mask_filter == "highest_box_score":
            assert bounding_boxes is not None, (
                "Bounding boxes must be provided to use the 'highest_box_score' mask filter."
            )
            assert len(masks) == len(bounding_boxes)
            # Find the index of the bounding box with the highest score.
            # Note that we fallback to -1.0 if the score is None. This is mainly to satisfy the type checker. In most
            # cases the scores should all be non-None when using this filtering mode. That being said, -1.0 is a
            # reasonable fallback since the expected score range is [0.0, 1.0].
            max_score_idx = max(range(len(bounding_boxes)), key=lambda i: bounding_boxes[i].score or -1.0)
            return [masks[max_score_idx]]
        else:
            raise ValueError(f"Invalid mask filter: {self.mask_filter}")

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Set mask_filter to a valid current option in the Segment Anything node UI.
  2. Re-create the node (or re-export) so the workflow stores the new enum value.
  3. When importing old workflows, review the Segment Anything node's mask_filter and update it.
  4. If calling via API, send a recognized mask_filter literal.

Example fix

// before
"mask_filter": "top_score"   // removed option
// after
"mask_filter": "single_highest_score"
Defensive patterns

Strategy: validation

Validate before calling

VALID_MASK_FILTERS = {"single_highest_score"}  # current node enum
if node.mask_filter not in VALID_MASK_FILTERS:
    node.mask_filter = "single_highest_score"

Type guard

null

Try / catch

try:
    result = invoke(context)
except ValueError as e:
    if e.args[0].startswith("Invalid mask filter"):
        node.mask_filter = default_mask_filter()
        retry(context)
    else:
        raise

Prevention

When it happens

Trigger: mask_filter contains a stale/unknown enum value — e.g. a workflow JSON saved with an old mask_filter option that was later removed or renamed, or an invalid string set programmatically.

Common situations: Upgrading InvokeAI after mask_filter options changed; importing workflows from other versions; bypassing UI enum validation with API-crafted node payloads.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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