Setup (5 minutes)
1
Install packages
2
Get your keys
From the Know Your AI dashboard:
- DSN: Settings → API Keys
- Firewall API key: Product → Firewall → Generate Key
3
Initialize with firewall
How input validation works
When a user sends a message, the firewall checks it before the AI model sees it:- Jailbreak attempts (“Ignore all instructions”, “You are DAN”, etc.)
- Prompt injection (e.g. template injection attacks)
- PII extraction attempts (“What is the admin password?”)
- Other policy-violating prompts
How output validation works
After the model responds, the firewall checks the output:- Toxic or hateful content
- Biased or discriminatory responses
- PII in the response (e.g., leaking personal data)
- Harmful instructions (e.g., illegal activities)
Violation actions explained
'block' — Stop the request entirely
The safest option for inputs. Throws HookBlockedError, ensuring dangerous content never reaches the model (or the user for outputs):
'log' — Record but allow
Good for output monitoring — you want to see violations but not disrupt the user experience:
'callback' — Custom handling
Full control — run your own logic when a violation is detected:
Fine-tune with risk threshold
Only trigger violations when the risk score exceeds a confidence threshold:Filter by risk category
Only check specific types of risks:Standalone firewall client
Use the Firewall API directly without the SDK integration — useful for custom pipelines or non-AI validation:Health check
Error handling
Fail-open design
Firewall logs dashboard
Every validation (pass and fail) is logged to the Firewall Logs page in your dashboard:Security report
The Firewall Security Report page provides a visual before/after comparison:- Baseline — How your model performs without the firewall
- With Firewall — How your model performs with firewall protection
- Per-prompt pass/fail comparison table
- Security score counters
- Compliance impact analysis