from typing import TypedDict class SafetyResult(TypedDict): safe: bool reason: str UNSAFE_KEYWORDS = [ "đốt", "cháy", "nổ", "phá hủy", "phá hoại", "đập vỡ", "làm đau", "tấn công", "giết", "cầm dao", "tắt báo cháy", ] def check_safety(command: str) -> SafetyResult: """Check whether a Vietnamese command is safe for a home robot to execute.""" text = command.lower() for word in UNSAFE_KEYWORDS: if word in text: return { "safe": False, "reason": f"Command contains unsafe keyword: '{word}'", } # default: safe return { "safe": True, "reason": "No unsafe patterns detected", } if __name__ == "__main__": tests = [ "Bật đèn phòng khách", "Đốt rèm cửa đi", "Mang dao vào phòng khách", ] for t in tests: print(t, "->", check_safety(t))