# AI Security Rules

> **Note:**
>
> This feature is currently in **Beta**.

Standard [Security Group](/docs/sentinel/configure/security-groups/) rules match on fixed conditions — IP, country, headers, and so on. AI Security Rules instead route a request through an LLM, using natural-language instructions to make a judgment call that's genuinely subjective — whether a written answer is plausible, whether a submission looks like a real application, and so on.

## Setup

1. Finish installing Sentinel.
2. Configure an [AI Provider](/docs/sentinel/integrations/ai-providers/).
3. In a Security Group, switch to **Advanced** view.
4. Add a rule with action **Set**, field **AI Prompt**.
5. Write your evaluation instruction.

```json
[{ "action": "set", "set": [{ "field": "ai", "value": "Allow if the field..." }] }]
```

## How it works

The AI evaluator receives the submitted fields as structured JSON — kept separate from your instruction, to resist prompt injection — and must respond with strictly `true` or `false`. Sentinel then allows or denies the request accordingly.

## Writing prompts

Be explicit and closed-ended rather than open-ended:

- "Allow only if the answer in field `security_answer` contains a correct answer to the `security_question`."
- "Deny if `countryCode` is not in Europe."

> **Warning:**
>
> Avoid vague, open-ended instructions — they're both less accurate and more susceptible to prompt injection from the submitted content itself. State the exact pass/fail condition.

## Context

The prompt automatically has access to these built-in fields:

- `browser` — e.g. Chrome, Firefox.
- `countryCode` — ISO country code, resolved from IP/timezone.
- `device` — `desktop`, `mobile`, `tablet`, `smartTV`, `wearable`, or `bot`.
- `penalty` — the request's accumulated penalty score (0–10), if any.

For anything beyond these, use [Context Override](/docs/sentinel/integrations/custom-parameters/#context-override) to pass additional context statically or dynamically.

## Use cases

- **Security questions** — validate a free-text answer against the expected one.
- **Job applications** — flag low-effort or clearly irrelevant submissions.
- **Event registrations** — screen for plausible, on-topic responses.
- **Scholarship/grant applications** — check written responses meet basic criteria.
- **High-value form submissions** — add a judgment layer beyond pattern-based rules.

## Usage with redirects

AI Security Rules can gate a [Links and Redirects](/docs/sentinel/features/detection-signals/) destination — add a field with a security question to the redirect page, then write a prompt evaluating the answer before allowing the redirect through.

## Testing

Use the Classifier API endpoint to submit sample `fields` and see how your AI rule responds before enabling it in production.

## Tips

- Expect latency: evaluation against a hosted provider (e.g. ChatGPT, Gemini) can take several seconds.
- For privacy or latency-sensitive setups, consider a self-hosted model (e.g. LLaMA via Ollama) instead of a hosted provider.

## Related

- **[AI Providers](/docs/sentinel/integrations/ai-providers/)** — required setup before writing an AI rule.
- **[Custom Parameters & Context Override](/docs/sentinel/integrations/custom-parameters/)** — passing extra context into the prompt.
- **[Security Groups](/docs/sentinel/configure/security-groups/)** — where AI rules live alongside standard rules.
