Skip to main content
The content firewall validates every AI interaction against safety policies. It sits between your application and the AI model, blocking dangerous inputs before they reach the model and flagging harmful outputs before they reach your users.

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:
What gets blocked on input:
  • 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:
What gets flagged/blocked on 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):
Handling blocked requests in your application:

'log' — Record but allow

Good for output monitoring — you want to see violations but not disrupt the user experience:
Violations appear in the Firewall Logs page of your dashboard with full risk details.

'callback' — Custom handling

Full control — run your own logic when a violation is detected:
ViolationContext structure:

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

If the Firewall API is unreachable (network error, timeout, etc.), AI requests proceed normally. This fail-open design ensures your application stays available even if the Firewall is temporarily down. Errors are logged but never block your AI calls.

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