> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fraudeg.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom rules

> Write your own rules on your fields, test them in shadow mode, and activate them when they deliver results

A custom rule **detects** a pattern specific to your business using the fields you send, and
**acts**: it alerts, opens a case, holds, or blocks. It's a good idea to **test it** in shadow
mode before letting it decide.

## Before you start

| | |
| - | - |
| **Where** | **Decision Engine › Custom rules** |
| **To view** | `RULES_VIEW` permission |
| **To create or edit** | `RULES_WRITE` permission |
| **Plan** | On the trial plan, you can't create or edit rules |
| **Requirements** | The fields the rule uses must be mapped, by [file](https://docs.fraudeg.com/en/manual/archivos-de-transacciones.md) or by [API](https://docs.fraudeg.com/en/manual/rt-inspector.md) |

## How it works

A rule in **Shadow** is evaluated on your real transactions and records when it would have
fired, without touching the decision. When its **Stats** convince you, you activate it. If an
active rule raises a decision, the response shows it with `custom_rule:<id>` in `reason`
(see [Decisions](https://docs.fraudeg.com/en/conceptos/decisiones.md)).

## Key concepts

| Concept | What it is |
| - | - |
| **Condition** | What must be true. Combine conditions with **AND** or **OR** groups, and use **Negate** to invert |
| **Action** | What it does when it fires: **Alert**, **Open case**, **Watch**, **Step-up**, **Hold**, or **Block** |
| **Status** | **Draft**, **Shadow**, **Active**, or **Disabled** |
| **Pending changes** | You edited an active rule. The previous version keeps running until you activate the changes |

## Create a rule

**1. Open the editor**

In **Custom rules**, click **New rule**. Fill in **Name** and **Description**.

**2. Write the condition**

In **Fields · click to add**, click a field to add it. Dimmed fields
aren't mapped yet. Use **+ Condition** and **+ Group** to combine, and **Negate**
to invert a group.

**3. Choose the action**

In **If the rule fires…**, choose what the rule does.

**4. Save and choose how to launch it**

Click **Save rule**. In **How do you want to launch it?**, choose **Leave in shadow**,
**Activate now**, or **Keep as draft**. If you haven't finished yet, use **Save draft**.

> [!TIP]
>
> Choose **Leave in shadow**. You see how many transactions it would catch and which ones, without
> blocking any good customer in the meantime.

## Shortcuts to get started

| Shortcut | What it does |
| - | - |
| **Ruler assistant** | Describe the rule in natural language and the assistant builds the condition. Review it before saving |
| **Fraudeg templates** | Ready-to-use rules. **Estimate** tells you how much it would catch with your data; **Clone** copies it to your rules so you can edit it |

## Write a good condition

A condition with a single field usually catches many good customers. Combine signals that,
together, describe only the pattern you're looking for.

| Too broad | Better |
| - | - |
| Card country different from shipping country | Card country different from shipping country **AND** amount higher than your usual high ticket |
| New customer | New customer **AND** first purchase in a category that is often resold |
| Email from a free domain | Email from a free domain **AND** shipping address different from billing address **AND** express shipping |
| Any purchase in the early morning hours | Purchase outside your business's usual hours **AND** recent change to the account details |

Start with **Alert** or **Watch**. Move up to **Hold** or **Block** only when the
shadow stats show it's accurate.

## Operate your rules

Each row in the list has its actions: **Edit**, **Stats**, **Backtest**, **Move to
shadow**, **Activate**, **Back to draft**, **Disable**, and **History**.

| If you see… | Do this |
| - | - |
| A rule in **Shadow** that is accurate | **Activate** |
| A rule in **Shadow** that catches good customers | **Edit** the condition, or **Back to draft** |
| An **Active** rule that started failing | **Move to shadow** while you tune it |
| An **Active** rule with **Pending changes** | Review the **Backtest** and activate the changes |
| A rule that is no longer useful | **Disable** |
| **No custom rules yet.** | Start with a template or with the **Ruler assistant** |

> [!NOTE]
>
> A rule that reads the [watchlist](https://docs.fraudeg.com/en/manual/listas-de-entidades.md) can only alert or
> open a case, and the **Backtest** can't replay it: today's list isn't the list from back then. Test it
> in **Shadow**.

## Related

> [card] [Rules](https://docs.fraudeg.com/en/manual/reglas.md)
>
> The Fraudeg rules that evaluate your transactions.

> [card] [Decisions](https://docs.fraudeg.com/en/conceptos/decisiones.md)
>
> How your rule appears in the API response.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.