{"record":{"id":"09604de66cc6e4db","repo":"rohitg00/ai-engineering-from-scratch","slug":"unknown-risk-classification","errorCode":null,"errorMessage":"unknown risk classification","messagePattern":"unknown risk classification","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/06-governance-safety-and-responsible-use/code/main.py","lineNumber":16,"sourceCode":"\"\"\"Companion code for:\ncertifications/claude/lessons/06-governance-safety-and-responsible-use/docs/en.md\nIt scores governance controls and computes a deterministic review threshold.\nConfidence never overrides consequence, authority, or reversibility in the runner.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport json\nfrom pathlib import Path\nfrom typing import Any\n\n\ndef review_required(consequence: str, reversible: bool, ambiguity: str = \"low\") -> bool:\n    if consequence not in {\"low\", \"medium\", \"high\"} or ambiguity not in {\"low\", \"medium\", \"high\"}:\n        raise ValueError(\"unknown risk classification\")\n    return consequence == \"high\" or not reversible or ambiguity == \"high\"\n\n\ndef validate_control_map(packet: dict[str, Any]) -> list[str]:\n    errors: list[str] = []\n    for field in (\"useCaseId\", \"approvedPurpose\", \"affectedPeople\", \"retentionRule\", \"incidentOwner\"):\n        if not isinstance(packet.get(field), str) or not packet[field].strip():\n            errors.append(f\"{field} is required\")\n    if packet.get(\"automationMode\") not in {\"assist\", \"bounded-automation\", \"redesign\", \"reject\"}:\n        errors.append(\"automationMode is invalid\")\n    if not isinstance(packet.get(\"dataClasses\"), list) or not packet[\"dataClasses\"]:\n        errors.append(\"dataClasses are required\")\n    if not isinstance(packet.get(\"prohibitedActions\"), list) or not packet[\"prohibitedActions\"]:\n        errors.append(\"prohibitedActions are required\")\n    confidence = packet.get(\"analysisConfidence\")\n    if not isinstance(confidence, (int, float)) or isinstance(confidence, bool) or not 0 <= confidence <= 1:\n        errors.append(\"analysisConfidence must be between zero and one\")\n    risks = packet.get(\"risks\")","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/06-governance-safety-and-responsible-use/code/main.py#L1-L34","documentation":"Fails-closed enum guard in review_required: consequence (or ambiguity) was not one of 'low'/'medium'/'high'. The governance rule refuses to guess a review threshold for an unclassified risk, so it raises instead of silently defaulting to no review.","triggerScenarios":"Thrown at certifications/claude/lessons/06-governance-safety-and-responsible-use/code/main.py:16 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Normalize consequence/ambiguity inputs to the low/medium/high vocabulary before calling","Map or reject free-text risk labels at the boundary of the control map","Treat the raised error as an upstream data defect to fix, never silence it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}