# Risk rules

An application's risk rules decide which changed files the review of a session's pull request
flags as **High risk** or **Medium risk**, and which it never flags. Each
[application](/user-guide/engineering/applications) starts with the default rules, and you change
them on its **Risk rules** tab.

<Availability permission="Applications: Read to see an application's risk rules. Applications: Update to add, edit, delete or reset them." />

## Working with risk rules

### To see an application's risk rules

1. Open the application and choose **Risk rules**.

The tab lists the rules in three groups, each with how many rules it holds. In the review of a session's pull request, a changed file
that matches a **High risk** rule is flagged **High risk**, and one that matches a **Medium risk**
rule and no **High risk** rule is flagged **Medium risk**. A file that matches a **Never flagged**
rule is never flagged, whatever else it matches: tests, documentation and lockfiles start there.
Point at the **?** beside a group's name for what it does to a file. Each rule is one line, with
what it matches on beside its name; choose the rule to see each of its conditions. A rule matches a
file when any one of its conditions does.

The badge at the top says **Default rules** while the application uses the default rules, and
**Custom rules** once it has rules of its own. Beside it is what editing does, or what changed
from the defaults. The rules you edited or added are marked **Edited** or **Added**.

### To check how a file would be flagged

1. Open the application and choose **Risk rules**.
2. In the box that says **Try by typing a path**, enter the file's path from the repository's
   root, for example `src/auth/login.ts`.

Below the path is how the review would flag a file there, and which rules decide it. In the groups,
the rules it matches open and are marked, along with the patterns and words that matched. Only the path is
checked: a rule's **Diff contains** and **Changes at least** conditions need the changes of a real
pull request.

### To add a risk rule

1. Open the application and choose **Risk rules**.
2. In the group the rule belongs in, **High risk**, **Medium risk** or **Never flagged**, choose
   the **+** beside its name.
3. Enter a **Name**. The review shows it as the reason a file is flagged.
4. Enter at least one condition:
   - **Path matches**, one pattern per line, from the repository's root. `*` matches within a
     folder, `**` across folders, and `{yml,yaml}` either alternative. A pattern without a `/`, such
     as `*.sql`, matches the file name in any folder.
   - **Path has word**, separated by commas: whole words of a folder or file name, letters and
     digits only. `signin` matches `SignIn.tsx`, and `auth` doesn't match `authorName.ts`.
   - **Diff contains**, one per line: text that an added or removed line contains as whole words,
     such as `alter table`.
   - **Changes at least**: the lines added plus the lines removed.
5. Choose **Add rule**.

The rule appears at the end of its group. The first rule you add, edit or delete gives the
application its own copy of the rules, and the badge at the top then says **Custom rules**.

### To edit or delete a risk rule

1. Open the application and choose **Risk rules**.
2. Point at the rule. To edit it, choose **Edit rule** (the pencil), change its name, **Flag as** or
   conditions, and choose **Save rule**. To delete it, choose **Delete rule** (the trash icon), then
   **Delete rule** again to confirm.

A review that is open picks up the change the next time it loads the pull request's files.

### To reset the risk rules to the defaults

1. Open the application and choose **Risk rules**.
2. Choose **Reset to defaults**, then **Reset to defaults** again to confirm.

The application uses the default rules again, and the badge at the top says **Default rules**.

:::caution
Resetting replaces the application's own rules with the default ones. Your changes to the rules
can't be brought back.
:::

## How risk rules behave

**Risk rules start as the defaults.** An application uses the default risk rules until someone
changes them. When the default rules improve, an application that still uses them gets the
improvement; an application with its own copy keeps its rules until you reset them. A pull request
is reviewed with the rules of the application its repository was attached from, and with the
default rules when it was attached without one.

## Permissions

| To | You need |
| --- | --- |
| See an application's risk rules | **Applications: Read** |
| Add, edit, delete or reset risk rules | **Applications: Update** |

## Limits

| Limit | Value |
| --- | --- |
| Risk rules per application | 100 |
| Risk rule name | 60 characters |
| **Path matches** patterns, **Path has word** words and **Diff contains** texts per risk rule | 50, 100 and 50 |

## Related topics

- [Applications](/user-guide/engineering/applications)
- [Pull requests and reviews](/user-guide/sessions/pull-requests)
