Write prompt_gate(payload) — the check every prompt payload passes
before anything is sent.
payload is a dict: {"id": str, "source": str, "text": str}.
Build a reasons list in this order:
- Provenance first: if
payload["source"]is not inAPPROVED, append"unapproved source: {source}". - Then the phrase scan: lowercase the text, then for each
category in
NEVER(dict order) and each phrase in its list (list order), append"{category}: {phrase}"for every phrase found as a substring.
Return ("BLOCK", reasons) if reasons is non-empty, else
("ALLOW", []).
Four payloads run through the report loop (provided). Expected output:
P1: ALLOW
P2: BLOCK — unapproved source: hris-export
P3: BLOCK — medical: diagnosis; medical: accommodation
P4: BLOCK — unapproved source: er-notes; er: grievance