Created
October 5, 2025 00:29
-
-
Save matthew-harper/ba986041b60960e05b5adbe31dc9ebaf to your computer and use it in GitHub Desktop.
Pattern 4 — Guardrails as Context Hygiene (shadow vs enforce)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| def run_guardrails_demo(prompt: str, shadow: bool = True) -> None: | |
| """Pattern 4: Guardrails as Context Hygiene""" | |
| print(f"\nInput: {prompt!r}") | |
| print(f"Mode: {'Shadow (logging only)' if shadow else 'Enforcement'}") | |
| if shadow: | |
| print("Shadow mode: logging only (no enforcement).") | |
| print(f"Response: {prompt}") | |
| print("(Would log to monitoring system: PII pattern detected)") | |
| else: | |
| redacted = re.sub(r"\b\d{3}-\d{2}-\d{4}\b", "<REDACTED-SSN>", prompt) | |
| print(f"Enforced response: {redacted}") | |
| if redacted != prompt: | |
| print("(PII detected and redacted)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment