{"record":{"id":"fbe50cb5144783ae","repo":"invoke-ai/InvokeAI","slug":"invalid-mask-filter-self-mask-filter","errorCode":null,"errorMessage":"Invalid mask filter: {self.mask_filter}","messagePattern":"Invalid mask filter: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/segment_anything.py","lineNumber":217,"sourceCode":"\n        if self.mask_filter == \"all\":\n            return masks\n        elif self.mask_filter == \"largest\":\n            # Find the largest mask.\n            return [max(masks, key=lambda x: float(x.sum()))]\n        elif self.mask_filter == \"highest_box_score\":\n            assert bounding_boxes is not None, (\n                \"Bounding boxes must be provided to use the 'highest_box_score' mask filter.\"\n            )\n            assert len(masks) == len(bounding_boxes)\n            # Find the index of the bounding box with the highest score.\n            # Note that we fallback to -1.0 if the score is None. This is mainly to satisfy the type checker. In most\n            # cases the scores should all be non-None when using this filtering mode. That being said, -1.0 is a\n            # reasonable fallback since the expected score range is [0.0, 1.0].\n            max_score_idx = max(range(len(bounding_boxes)), key=lambda i: bounding_boxes[i].score or -1.0)\n            return [masks[max_score_idx]]\n        else:\n            raise ValueError(f\"Invalid mask filter: {self.mask_filter}\")\n","sourceCodeStart":199,"sourceCodeEnd":218,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/segment_anything.py#L199-L218","documentation":"_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.","triggerScenarios":"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.","commonSituations":"Upgrading InvokeAI after mask_filter options changed; importing workflows from other versions; bypassing UI enum validation with API-crafted node payloads.","solutions":["Set mask_filter to a valid current option in the Segment Anything node UI.","Re-create the node (or re-export) so the workflow stores the new enum value.","When importing old workflows, review the Segment Anything node's mask_filter and update it.","If calling via API, send a recognized mask_filter literal."],"exampleFix":"// before\n\"mask_filter\": \"top_score\"   // removed option\n// after\n\"mask_filter\": \"single_highest_score\"","handlingStrategy":"validation","validationCode":"VALID_MASK_FILTERS = {\"single_highest_score\"}  # current node enum\nif node.mask_filter not in VALID_MASK_FILTERS:\n    node.mask_filter = \"single_highest_score\"","typeGuard":"null","tryCatchPattern":"try:\n    result = invoke(context)\nexcept ValueError as e:\n    if e.args[0].startswith(\"Invalid mask filter\"):\n        node.mask_filter = default_mask_filter()\n        retry(context)\n    else:\n        raise","preventionTips":["Re-export workflows after upgrading InvokeAI","Avoid hand-writing mask_filter values in API payloads","Diff imported workflow enums against the current schema"],"tags":["validation","enum","segment-anything"],"backgroundTag":"invalid-enum-value","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}