Rajan Sharma commited on
Commit
b5c0f10
·
verified ·
1 Parent(s): 07c72fd

Create policy_validator.py

Browse files
Files changed (1) hide show
  1. validators/policy_validator.py +20 -0
validators/policy_validator.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ def assert_valid(data: dict, constraints_path: str):
4
+ with open(constraints_path, "r", encoding="utf-8") as f:
5
+ constraints = json.load(f)
6
+
7
+ analytics_first = constraints.get("analytics_first", True)
8
+ require_longitudinal = constraints.get("require_longitudinal", True)
9
+
10
+ # Recommendations must be analytics/longitudinal, not generic ops,
11
+ # if constraints say so.
12
+ recs = [r.lower() for r in data.get("recommendations", [])]
13
+ if analytics_first:
14
+ banned = ["hire more staff", "seek funding", "generic scheduling"]
15
+ if any(any(b in r for b in banned) for r in recs):
16
+ raise ValueError("PolicyValidator: recommendations contain generic ops; expected analytics-first.")
17
+
18
+ if require_longitudinal:
19
+ if not any(("longitudinal" in r or "follow-up" in r or "risk" in r) for r in recs):
20
+ raise ValueError("PolicyValidator: at least one recommendation must reference longitudinal risk/follow-up.")