File size: 977 Bytes
b5c0f10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import json

def assert_valid(data: dict, constraints_path: str):
    with open(constraints_path, "r", encoding="utf-8") as f:
        constraints = json.load(f)

    analytics_first = constraints.get("analytics_first", True)
    require_longitudinal = constraints.get("require_longitudinal", True)

    # Recommendations must be analytics/longitudinal, not generic ops,
    # if constraints say so.
    recs = [r.lower() for r in data.get("recommendations", [])]
    if analytics_first:
        banned = ["hire more staff", "seek funding", "generic scheduling"]
        if any(any(b in r for b in banned) for r in recs):
            raise ValueError("PolicyValidator: recommendations contain generic ops; expected analytics-first.")

    if require_longitudinal:
        if not any(("longitudinal" in r or "follow-up" in r or "risk" in r) for r in recs):
            raise ValueError("PolicyValidator: at least one recommendation must reference longitudinal risk/follow-up.")