rohitg00/ai-engineering-from-scratch · error · ValueError
unknown risk classification
Error message
unknown risk classification
What it means
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.
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
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at certifications/claude/lessons/06-governance-safety-and-responsible-use/code/main.py:16 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26).
Data as JSON: /api/errors/09604de66cc6e4db.
Report an issue: GitHub.
Appendix: source
Thrown at certifications/claude/lessons/06-governance-safety-and-responsible-use/code/main.py:16
"""Companion code for:
certifications/claude/lessons/06-governance-safety-and-responsible-use/docs/en.md
It scores governance controls and computes a deterministic review threshold.
Confidence never overrides consequence, authority, or reversibility in the runner.
"""
from __future__ import annotations
import json
from pathlib import Path
from typing import Any
def review_required(consequence: str, reversible: bool, ambiguity: str = "low") -> bool:
if consequence not in {"low", "medium", "high"} or ambiguity not in {"low", "medium", "high"}:
raise ValueError("unknown risk classification")
return consequence == "high" or not reversible or ambiguity == "high"
def validate_control_map(packet: dict[str, Any]) -> list[str]:
errors: list[str] = []
for field in ("useCaseId", "approvedPurpose", "affectedPeople", "retentionRule", "incidentOwner"):
if not isinstance(packet.get(field), str) or not packet[field].strip():
errors.append(f"{field} is required")
if packet.get("automationMode") not in {"assist", "bounded-automation", "redesign", "reject"}:
errors.append("automationMode is invalid")
if not isinstance(packet.get("dataClasses"), list) or not packet["dataClasses"]:
errors.append("dataClasses are required")
if not isinstance(packet.get("prohibitedActions"), list) or not packet["prohibitedActions"]:
errors.append("prohibitedActions are required")
confidence = packet.get("analysisConfidence")
if not isinstance(confidence, (int, float)) or isinstance(confidence, bool) or not 0 <= confidence <= 1:
errors.append("analysisConfidence must be between zero and one")
risks = packet.get("risks")View on GitHub (pinned to 39ea8a1c6d)