> For the complete documentation index, see [llms.txt](https://help.nightfall.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.nightfall.ai/detection_platform/create_detection_rules.md). Agents can also search and read this documentation through its [MCP server](https://help.nightfall.ai/~gitbook/mcp).

# Create detection rules

Learn the process of creating detection rules in Nightfall.

A detection rule tells Nightfall which detectors to run and when their matches count as a finding. Detectors do not scan anything on their own: you add detectors to a detection rule, and then add the detection rule to a policy. The policy decides where Nightfall scans, and the detection rule decides what Nightfall looks for.

## What you will learn in this topic

By the end of this topic, you will know:

* The purpose of a detection rule and how it connects detectors to policies.
* The steps to create a detection rule from the **Configure Detection Rule** panel.
* The way to set **Scan**, **Confidence**, and **Findings** for each detector.
* How to predict when a detection rule flags a finding.
* How to try Nightfall detectors in the Nightfall Playground.

***

## Before you begin

Make a note of the following before you create detection rules:

* Make sure that any custom detectors you want to use are already created. For more information, see [Creating Custom Detectors](https://help.nightfall.ai/detection_platform/custom_detectors.md).

***

## Understand detection rules

A detection rule can hold any mix of Nightfall detectors and custom detectors. For each detector, you choose what part of the data it scans, how confident a match must be, and how many matches it needs. You then choose whether one detector is enough to flag a finding, or whether every detector must match.

You can split detection across several detection rules or combine it in one. For example, you can create one detection rule with the **API key** detector to catch API key leaks and another with the **Password** detector to catch password leaks. You can also put both detectors in a single detection rule.

The **Detection** page also lists **Nightfall Rules**: detection rules Nightfall provides for secure, compliant operations, such as **Finance - Banking IDs**, **PCI - Credit Cards**, and **PHI - Health Data**. You can add these to policies or use them as a starting point for your own detection rules.

{% hint style="info" %}
**Note**:

For guidance on which detectors to include in your detection rules, see [Detection Rules](https://help.nightfall.ai/nightfall_policy_templates/detection_rules.md).
{% endhint %}

***

## Navigate the Detection page

Navigate to **Configuration** → **Detection** to view your detection rules and detectors.

<figure><img src="https://2214688951-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mg3wgFIu8T7XAT1u-f_%2Fuploads%2FMi46epO7aZrS9MbtW4LZ%2Fnightfall_detection_rules_navigation.png?alt=media&amp;token=6d201f32-916c-43ed-948f-874f5fd0a071" alt=""><figcaption><p>Nightfall Detection</p></figcaption></figure>

### Key components of the Detection page

<table><thead><tr><th width="230.2265625">Attribute</th><th>Description</th></tr></thead><tbody><tr><td><strong>Detection rules</strong> tab</td><td>Lists your detection rules and the <strong>Nightfall Rules</strong>, with the total count. Each rule shows its name, description, and detectors.</td></tr><tr><td><strong>Detectors</strong> tab</td><td>Lists the Nightfall detectors and custom detectors that you can add to detection rules. For more information, see <a href="https://help.nightfall.ai/detection_platform/detectors.md">Detectors</a>.</td></tr><tr><td><strong>Search</strong></td><td>Searches the detection rules on the page.</td></tr><tr><td><strong>New Detection Rule</strong></td><td>Opens the <strong>Configure Detection Rule</strong> panel.</td></tr></tbody></table>

***

## Create a detection rule

You create a detection rule in the **Configure Detection Rule** slide-out panel. The left side of the panel lists **Available Detectors**, and the right side shows the detectors **In this rule** with their settings.

<figure><img src="https://2214688951-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mg3wgFIu8T7XAT1u-f_%2Fuploads%2FBHf65AutrpLGuWnPsWzd%2Fnightfall_detection_rules_create_flowchart.png?alt=media&amp;token=28b90210-6c5f-4f75-bdba-f50f01d1b581" alt=""><figcaption><p>Nightfall Detection Rule Creation Flow</p></figcaption></figure>

To create a detection rule, complete the following steps:

### Step 1: Start a new detection rule

1. Navigate to **Configuration** → **Detection** → **Detection rules** tab.
2. Click **+ New Detection Rule**.

### Step 2: Name the detection rule

1. Specify a name in the **Name** field.
2. (Optional) Click **Add description** and describe what the detection rule detects.

### Step 3: Add detectors

Until you add a detector, the panel shows **No detectors added**. Under **Available Detectors**, use either tab:

* **Detectors**: Click **+** next to each detector you want. Use **Search detectors...** to find a detector by name. To show only detectors belonging to a specific category or only custom detectors, use the **Filter** drop-down.
* **From a rule**: Select an existing detection rule to add every detector in it.

Each detector you add appears as a card under **In this rule**. The counter next to **In this rule** shows the number of detectors in the rule out of the number allowed, for example, **2 of 50**. To remove a detector, click the **Delete** icon on its card.

### Step 4: Configure each detector

Each detector card has three settings: **Scan**, **Confidence**, and **Findings**. Set them on each card, or use **Apply to all** at the top of the list to set **Scan** or **Confidence** for every detector at once. For information on what each setting does, see [Detection rule settings](#detection-rule-settings).

### Step 5: Choose when the detection rule flags a finding

Under **Flag as finding when triggered by**, select **Any Detector** or **All Detectors**. For how each option behaves, see [How a detection rule flags a finding](#how-a-detection-rule-flags-a-finding).

### Step 6: Save the detection rule

Click **Save Detection Rule**. To discard your changes, click **Cancel**.

<figure><img src="https://2214688951-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mg3wgFIu8T7XAT1u-f_%2Fuploads%2F1jW5jz6Adt4D8DXarHRa%2Fnightfall_detection_rules_creation.png?alt=media&amp;token=dcec7394-a393-456c-9885-58c9c709795a" alt=""><figcaption><p>Detection Rule Creation</p></figcaption></figure>

The detection rule now appears on the **Detection rules** tab. To start scanning with it, add it to a policy. For more information, see [Creating Policies](https://help.nightfall.ai/detection_platform/policies.md).

***

## Detection rule settings

This section describes the settings on each detector card and the **Apply to all** controls.

### Scan

**Scan** sets which part of the data the detector checks.

<table><thead><tr><th width="178.19140625">Option</th><th>What the Detector Scans</th></tr></thead><tbody><tr><td><strong>Content</strong></td><td>The contents of the file or message, not the file name</td></tr><tr><td><strong>File name</strong></td><td>The name of the file only</td></tr><tr><td><strong>Both</strong></td><td>The file name and the contents of the file</td></tr></tbody></table>

For example, if the **API key** detector scans a Google Drive file with **Scan** set to **File name**, it checks only whether the file name contains an API key.

{% hint style="info" %}
**Note**:

Messages that are not files, such as direct messages and group messages in Slack or Microsoft Teams, count as content. If **Scan** is set to **File name**, the detector finds no violations in them. Use **Content** or **Both**.
{% endhint %}

### Confidence

**Confidence** sets the lowest confidence level at which a match counts. Matches below this level are ignored.

<table><thead><tr><th width="205.3828125">Option</th><th>Chance That the Match Is an Actual Data Leak</th></tr></thead><tbody><tr><td><strong>Possible</strong></td><td>40% to 75%</td></tr><tr><td><strong>Likely</strong></td><td>75% to 90%</td></tr><tr><td><strong>Very likely</strong></td><td>90% to 100%</td></tr></tbody></table>

A higher level means fewer false positives but a greater chance of missing real data. When the detector finds a violation, Nightfall logs it on the [Data Detection and Response Events](https://help.nightfall.ai/dashboard/sdp_events.md) page with the confidence level you set here.

### Findings

**Findings** sets how many matches the detector needs before they count as a violation. For example, if you set **Findings** to `10`, the detection rule ignores the first 9 matches and treats the 10th and every later match as a violation. Use a higher number for data that matters only in bulk, such as lists of names and phone numbers.

### Apply to all

The **Apply to all** controls change a setting for every detector in the detection rule at once:

* **Scan**: Sets **Scan** on every detector card.
* **Confidence**: Sets **Confidence** on every detector card.

When the detectors use different values, the control shows **Custom**.

***

## How a detection rule flags a finding

Each detector meets its settings when it finds at least the **Findings** number of matches, at or above its **Confidence** level, in the part of the data its **Scan** option covers. **Flag as finding when triggered by** then decides what the detection rule needs:

* **Any Detector**: The detection rule flags a finding when at least one detector meets its settings.
* **All Detectors**: The detection rule flags a finding only when every detector meets its settings.

A detection rule with a single detector flags a finding whenever that detector meets its settings.

<figure><img src="https://2214688951-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mg3wgFIu8T7XAT1u-f_%2Fuploads%2FtNC9MbMwOoPdMgKhb5AW%2Fnightfall_detection_rules_trigger_flowchart.png?alt=media&amp;token=8c323104-84f3-4efe-9fee-0868d7eb204e" alt=""><figcaption><p>Nightfall Finding Detection Flow</p></figcaption></figure>

### Example

The following detection rule is set to **Any Detector** and contains two detectors.

| Detector               | Scan     | Confidence      | Findings |
| ---------------------- | -------- | --------------- | -------- |
| **Credit card number** | **Both** | **Very likely** | `1`      |
| **Credit Card Image**  | **Both** | **Likely**      | `5`      |

With these settings:

* Both detectors check the file name and the contents of the file.
* One **Credit card number** match at **Very likely** is enough for that detector to meet its settings.
* **Credit Card Image** needs at least 5 matches at **Likely** or higher.
* Because the rule uses **Any Detector**, either detector meeting its settings flags a finding. With **All Detectors**, both detectors would have to meet their settings.

***

## Try Nightfall detectors in the Nightfall Playground

The [Nightfall Playground](https://playground.nightfall.ai/) shows how Nightfall detectors respond to sample data. It does not run the detection rules you save in the Nightfall console. Use it to compare detectors and confidence levels before you build a detection rule.

<figure><img src="https://2214688951-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mg3wgFIu8T7XAT1u-f_%2Fuploads%2F5q3eqQ9uheOR1LGMjW6X%2Fnightfall_detection_rules_playground.png?alt=media&amp;token=d6baa5fb-d72a-4269-9996-0a7c89ddce61" alt=""><figcaption><p>Nightfall Playground</p></figcaption></figure>

1. Navigate to the [Nightfall Playground](https://playground.nightfall.ai/).
2. Select a category of sensitive data: **Secrets and Credentials**, **PII - US ID Numbers**, **PCI - Credit Card Numbers**, **PHI - Protected Health Information**, **Finance - Banking ID Numbers**, **Hardware / Network**, or **PII - Common Entities**.
3. Under **Detector Settings**, select the detectors to try.
4. Move the **Minimum Confidence** slider to **Possible**, **Likely**, or **Very Likely**.
5. Under **Input Data**, keep **Auto-generate sample data** selected to scan sample data that Nightfall generates. To scan your own text, clear **Auto-generate sample data** checkbox and specify the text.
6. Review the results under **Findings**. Each finding shows the detector, its confidence level, and where the match appears in the input data.

{% hint style="info" %}
**Note**:

Do not enter real sensitive data in the Playground. For test data, see [Sample Datasets](https://help.nightfall.ai/nightfall_policy_templates/sample_data.md).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.nightfall.ai/detection_platform/create_detection_rules.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
