Skip to content

Commit fbd3b33

Browse files
authored
[PLT-2011] Vb/fix prompt issue classification update plt 2011 (#1917)
1 parent dc041b6 commit fbd3b33

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class _BaseStepReasoningTool(ABC):
7676
schema_id: Optional[str] = None
7777
feature_schema_id: Optional[str] = None
7878
color: Optional[str] = None
79-
required: bool = False
79+
required: bool = False # This attribute is for consistency with other tools and backend, default is False
8080

8181
def __post_init__(self):
8282
if not self.name.strip():

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class PromptIssueTool:
3636

3737
name: str
3838
type: ToolType = field(default=ToolType.PROMPT_ISSUE, init=False)
39-
required: bool = False
39+
required: bool = False # This attribute is for consistency with other tools and backend, default is False
4040
schema_id: Optional[str] = None
4141
feature_schema_id: Optional[str] = None
4242
color: Optional[str] = None
@@ -64,11 +64,20 @@ def _validate_classifications(
6464
if (
6565
len(classifications) != 1
6666
or classifications[0].class_type != Classification.Type.CHECKLIST
67+
or len(classifications[0].options) < 1
6768
):
6869
return False
6970
return True
7071

7172
def asdict(self) -> Dict[str, Any]:
73+
classifications_valid = self._validate_classifications(
74+
self.classifications
75+
)
76+
if not classifications_valid:
77+
raise ValueError(
78+
"Classifications for Prompt Issue Tool are invalid"
79+
)
80+
7281
return {
7382
"tool": self.type.value,
7483
"name": self.name,

libs/labelbox/tests/integration/test_ontology.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
import pytest
55

6-
from labelbox import MediaType, OntologyBuilder, Tool
6+
from labelbox import MediaType, OntologyBuilder, OntologyKind, Tool
77
from labelbox.orm.model import Entity
8-
from labelbox.schema.tool_building.classification import Classification
8+
from labelbox.schema.tool_building.classification import Classification, Option
99
from labelbox.schema.tool_building.fact_checking_tool import (
1010
FactCheckingTool,
1111
)
@@ -488,3 +488,33 @@ def test_prompt_issue_ontology(chat_evaluation_ontology):
488488
classification = prompt_issue_tool.classifications[0]
489489
assert classification.class_type == Classification.Type.CHECKLIST
490490
assert len(classification.options) == 3 # Check number of options
491+
492+
493+
def test_invalid_prompt_issue_ontology(client):
494+
tool = PromptIssueTool(name="Prompt Issue Tool")
495+
496+
option1 = Option(value="value")
497+
radio_class = Classification(
498+
class_type=Classification.Type.RADIO,
499+
name="radio-class",
500+
options=[option1],
501+
)
502+
text_class = Classification(
503+
class_type=Classification.Type.TEXT, name="text-class"
504+
)
505+
506+
tool.classifications.append(radio_class)
507+
tool.classifications.append(text_class)
508+
509+
builder = OntologyBuilder(
510+
tools=[tool],
511+
)
512+
with pytest.raises(
513+
ValueError, match="Classifications for Prompt Issue Tool are invalid"
514+
):
515+
client.create_ontology(
516+
name="plt-1710",
517+
media_type=MediaType.Conversational,
518+
ontology_kind=OntologyKind.ModelEvaluation,
519+
normalized=builder.asdict(),
520+
)

libs/labelbox/tests/unit/test_unit_prompt_issue_tool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def test_as_dict():
5353
}
5454
assert tool_dict == expected_dict
5555

56+
57+
def test_classification_validation():
58+
tool = PromptIssueTool(name="Prompt Issue Tool")
5659
with pytest.raises(ValueError):
5760
tool.classifications = [
5861
Classification(Classification.Type.TEXT, "prompt_issue")

0 commit comments

Comments
 (0)