Skip to content

Commit 91b1ea6

Browse files
committed
Validate classifications
1 parent a1f310f commit 91b1ea6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

libs/labelbox/src/labelbox/schema/tool_building/prompt_issue_tool.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ def __post_init__(self):
4848
if self.name.strip() == "":
4949
raise ValueError("Name cannot be empty")
5050

51+
if not self._validate_classifications(self.classifications):
52+
raise ValueError("Only one checklist classification is supported")
53+
54+
def __setattr__(self, name, value):
55+
if name == "classifications" and not self._validate_classifications(
56+
value
57+
):
58+
raise ValueError("Classifications are immutable")
59+
object.__setattr__(self, name, value)
60+
61+
def _validate_classifications(
62+
self, classifications: List[Classification]
63+
) -> bool:
64+
if (
65+
len(classifications) != 1
66+
or classifications[0].class_type != Classification.Type.CHECKLIST
67+
):
68+
return False
69+
return True
70+
5171
def asdict(self) -> Dict[str, Any]:
5272
return {
5373
"tool": self.type.value,

0 commit comments

Comments
 (0)