from __future__ import annotations from collections.abc import Iterable # The fixed v0 governance classification set (ADR 0011). This is a platform invariant, # not source config: source config decides *which* of these to apply to a table, but the # valid universe is fixed here so a typo or an arbitrary label in source.yaml cannot flow # into governance metadata. Keep this in sync with # docs/adr/0011-v0-starts-with-a-small-governance-classification-set.md. GOVERNANCE_CLASSIFICATIONS: frozenset[str] = frozenset( { "public", "internal", "confidential", "restricted", "pii", "financial", "customer_data", "operational_sensitive", } ) def validate_classifications(classifications: Iterable[str], *, context: str = "") -> list[str]: """Return the classifications as a list, raising if any is outside the ADR-0011 set. ``context`` is included in the error message to point at the offending source (e.g. ``"table account"``). """ result = list(classifications) unknown = sorted({c for c in result if c not in GOVERNANCE_CLASSIFICATIONS}) if unknown: where = f" ({context})" if context else "" raise ValueError( f"unknown governance classification(s){where}: {unknown}; " f"allowed set (ADR 0011): {sorted(GOVERNANCE_CLASSIFICATIONS)}" ) return result