Medica_DecisionSupportAI / validators /policy_validator.py
Rajan Sharma
Create policy_validator.py
b5c0f10 verified
raw
history blame contribute delete
977 Bytes
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.")