Map an unrecognised classification reply to UNKNOWN 🟥

This commit is contained in:
Jun-te Kim 2026-05-22 14:55:01 +00:00
parent d0e5aa9e3f
commit 11a498ba4e
2 changed files with 21 additions and 1 deletions

View file

@ -33,6 +33,14 @@ class ChatGptPropertyTypeClassifier(PropertyTypeClassifier):
)
raw: dict[str, Any] = json.loads(reply)
return {
description: PropertyType(raw[description])
description: self._to_property_type(raw[description])
for description in descriptions
}
@staticmethod
def _to_property_type(value: Any) -> PropertyType:
"""Map a reply value to a PropertyType, defaulting to UNKNOWN."""
try:
return PropertyType(value)
except ValueError:
return PropertyType.UNKNOWN

View file

@ -31,3 +31,15 @@ def test_classifies_description_into_property_type() -> None:
# Assert
assert result == {"semi-detached": PropertyType.HOUSE}
def test_unrecognised_category_maps_to_unknown() -> None:
# Arrange
chat_gpt = _FakeChatGPT(reply='{"garden shed": "Shed"}')
classifier = ChatGptPropertyTypeClassifier(chat_gpt)
# Act
result = classifier.classify({"garden shed"})
# Assert
assert result == {"garden shed": PropertyType.UNKNOWN}