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

# Client rules

> Monitor clients, not only their transactions: rules that run when a client is created or updated and raise a Client Monitoring alert when the client matches.

A **client rule** checks a client instead of a transaction. It runs when a client is created or updated, evaluates the client as it is at that moment, and raises a **Client Monitoring** alert when the client matches. Use client rules for checks that belong to the client itself: onboarding screening, changes to a client's country or risk data, or logins from risky networks.

> [!NOTE]
>
> Client rules are rolled out per platform behind a feature flag. If you don't see the **Client** option when you create a rule, ask your Corsa contact to enable it. With client rules enabled, the **Transaction Monitoring** module is called **Monitoring Rules**.

***

## How client rules work

1. You create a rule and choose **Client** as what it applies to.
2. When an individual or corporate client is created or updated, Corsa evaluates the active client rules whose trigger matches the change. Evaluation runs asynchronously, right after the client write is stored.
3. The rule's conditions are checked against the client's current data: its profile, tags, lists, custom fields, latest session and transaction history.
4. When the rule matches, Corsa creates an alert with category `CLIENT_MONITORING`, linked to the client. Client Monitoring alerts are not linked to a transaction.

A transaction rule keeps working exactly as before: it still runs on every transaction and can check the sending or receiving client. Client rules are a separate kind of rule for checks that should run when the client changes, not when money moves.

***

## When a rule runs

Each client rule has a trigger:

| Run on | When it runs |
| - | - |
| **Client created** (default) | Once, when the client is created. |
| **Client created or updated** | When the client is created and on every update. |
| **Client updated** | On every update, not on creation. |

### Only when specific fields change

A rule that runs on updates can be narrowed to **only when these fields change**. List the client fields as dotted paths, as they appear in the [client API](https://docs.corsa.finance/api/data-ingestion.md) (for example, `address.country` or `address.city`). The rule runs on an update only when one of those fields changed:

* A field matches a change to itself or to anything below it: `address` matches a change to `address.city`.
* A change to a whole parent object matches the fields inside it.
* Other fields don't count: a rule on `address.city` doesn't run when only `address.country` changes.

> [!TIP]
>
> Updates that arrive close together are evaluated on the client's latest data. If a newer update has already been stored when an older one is processed, the older update is skipped and the newer one evaluates the client. A **Client created** rule still runs for every new client.

***

## What a client rule can check

The rule always checks the client that was created or updated, so you don't choose a sender or receiver.

| Data | Examples | Notes |
| - | - | - |
| **Client profile** | Risk tier, country, account status, KYC and screening status, onboarding dates | The same client properties as in [transaction rules](https://docs.corsa.finance/transaction-monitoring/conditions-reference.md#entities). |
| **Tags and custom fields** | `customFields.segment`, client tags | Custom fields follow the [custom field rules](https://docs.corsa.finance/transaction-monitoring/conditions-reference.md#custom-fields). |
| **Lists** | Client on a block, allow or watch list; client country on a country list | See [Lists](https://docs.corsa.finance/intelligence-hub/lists.md). |
| **Latest session** | Login IP, IP country, city, VPN, proxy, Tor, datacenter, device fingerprint, device type, browser, operating system | Read from the client's most recent [session](https://docs.corsa.finance/api/ingesting-sessions.md). |
| **Device and IP** | Device or IP on a list, device custom fields | From the client's most recent session. |
| **Transaction history** | Sum, count or average of the client's transactions over a time window | Aggregations over the client's own transactions. Choose **All of the client's transactions**, **Outgoing** or **Incoming**. |

Some conditions need a transaction in progress, so client rules don't offer them:

* transaction properties (amount, type, currency) outside an aggregation;
* wallet, bank account, payment account and merchant conditions;
* **include current transaction** on aggregations;
* conditions that match the current transaction's counterparty or wallet.

***

## Alerts

A client rule's only action is **Create alert**. Client rules can't halt transactions.

* **Category:** always `CLIENT_MONITORING`. Priority, assignee, sub-category and due date come from the rule's alert settings, as for transaction rules.
* **One alert per match:** by default, a rule alerts when a client starts matching. While the client keeps matching on later updates, no new alert is created. If the client stops matching and later matches again, the rule alerts again.
* **Alert on every match:** turn this on to create an alert every time the rule runs and matches.

Client Monitoring alerts appear in the [Alerts](https://docs.corsa.finance/case-management/alerts.md) queue with the client's details. You can filter, assign, escalate and resolve them like any other alert.

***

## Build a client rule in the dashboard

1. Go to **Monitoring Rules** → **Rules** and click **Create Rule**.
2. Choose **Client**. You can't change this after the rule is created.
3. **Define conditions.** The condition menu offers client, device and IP data. Aggregations let you choose the direction of the client's transactions.
4. **Configure the response:**
   * **Run on:** **Client created**, **Client created or updated**, or **Client updated**.
   * **Only when these fields change** (shown when the rule runs on updates): optional dotted client field paths.
   * **Alert on every match:** off by default.
   * Alert priority and routing, as for [transaction rules](https://docs.corsa.finance/transaction-monitoring/building-rules.md#step-2-configure-response).
5. **Test on a client.** Pick an individual or corporate client. Corsa evaluates the rule on that client's current data and shows whether it matches, with each condition's value. Testing creates no alert and stores nothing.
6. **Review and activate.**

The **Rules** list has an **Applies to** column and filter, so you can tell transaction and client rules apart.

***

## Manage client rules with the API

Client rules use the same [Rules API](https://docs.corsa.finance/transaction-monitoring/rules-api.md) as transaction rules, with three extra fields:

| Field | Applies to | Description |
| - | - | - |
| `baseEntity` | Create only | `client` for a client rule. Omit it, or send `transaction`, for a transaction rule. It can't be changed later. |
| `triggers` | Client rules | `events`: `["created"]` (default), `["updated"]`, or both. `updatedFields`: optional dotted client field paths; needs `updated` in `events`. |
| `alertOnEveryMatch` | Client rules | `false` (default) alerts when a client starts matching; `true` alerts on every match. |

### Create a client rule

```json REST API theme={null}
POST /v1/rules
Content-Type: application/json

{
  "name": "Client moved to a high-risk country",
  "description": "Alert when a client's address country changes to a high-risk jurisdiction",
  "baseEntity": "client",
  "triggers": {
    "events": ["created", "updated"],
    "updatedFields": ["address.country"]
  },
  "alertOnEveryMatch": false,
  "conditions": {
    "all": [
      {
        "entity": "client",
        "property": "country",
        "operator": "in",
        "value": ["IRN", "PRK"]
      }
    ]
  },
  "actions": [
    {
      "type": "CREATE_ALERT",
      "config": {
        "category": "CLIENT_MONITORING",
        "priority": "HIGH",
        "status": "NEW"
      }
    }
  ]
}
```

```typescript Javascript theme={null}
const rule = await corsa.rules.createRule({
  name: "Client moved to a high-risk country",
  description:
    "Alert when a client's address country changes to a high-risk jurisdiction",
  baseEntity: "client",
  triggers: {
    events: ["created", "updated"],
    updatedFields: ["address.country"],
  },
  alertOnEveryMatch: false,
  conditions: {
    all: [
      {
        entity: "client",
        property: "country",
        operator: "in",
        value: ["IRN", "PRK"],
      },
    ],
  },
  actions: [
    {
      type: "CREATE_ALERT",
      config: { category: "CLIENT_MONITORING", priority: "HIGH", status: "NEW" },
    },
  ],
});
```

```python Python theme={null}
from corsa_sdk.api.rules.create_rule import _get_kwargs
from corsa_sdk.models.create_rule_dto import CreateRuleDto

resp = http.request(**_get_kwargs(
    body=CreateRuleDto.from_dict({
        "name": "Client moved to a high-risk country",
        "description": "Alert when a client's address country changes to a high-risk jurisdiction",
        "baseEntity": "client",
        "triggers": {"events": ["created", "updated"], "updatedFields": ["address.country"]},
        "alertOnEveryMatch": False,
        "conditions": {"all": [
            {"entity": "client", "property": "country", "operator": "in", "value": ["IRN", "PRK"]},
        ]},
        "actions": [{"type": "CREATE_ALERT", "config": {"category": "CLIENT_MONITORING", "priority": "HIGH", "status": "NEW"}}],
    }),
))
rule = resp.json()
```

The rule is created as a draft. [Activate it](https://docs.corsa.finance/transaction-monitoring/rules-api.md#activate-a-rule) to start evaluating clients. The request is refused with `400` if client rules aren't enabled for your platform, if a condition needs a transaction, or if an action other than `CREATE_ALERT` is used.

### Change when a client rule runs

Send `triggers` or `alertOnEveryMatch` on [update](https://docs.corsa.finance/transaction-monitoring/rules-api.md#update-a-rule). Fields you omit keep their stored values.

```json REST API theme={null}
PUT /v1/rules/rule-uuid
Content-Type: application/json

{
  "triggers": { "events": ["updated"], "updatedFields": ["address.country", "address.city"] },
  "alertOnEveryMatch": true,
  "reason": "Also watch city changes"
}
```

```typescript Javascript theme={null}
const rule = await corsa.rules.updateRule("rule-uuid", {
  triggers: { events: ["updated"], updatedFields: ["address.country", "address.city"] },
  alertOnEveryMatch: true,
  reason: "Also watch city changes",
});
```

```python Python theme={null}
from corsa_sdk.api.rules.update_rule import _get_kwargs
from corsa_sdk.models.update_rule_dto import UpdateRuleDto

resp = http.request(**_get_kwargs(
    id="rule-uuid",
    body=UpdateRuleDto.from_dict({
        "triggers": {"events": ["updated"], "updatedFields": ["address.country", "address.city"]},
        "alertOnEveryMatch": True,
        "reason": "Also watch city changes",
    }),
))
rule = resp.json()
```

### List client rules

```bash REST API theme={null}
GET /v1/rules?filter.baseEntity=$eq:client
```

```typescript Javascript theme={null}
// listRules(page, limit, filterId, filterName, filterStatus, filterIsExternalRule, filterVendorName, filterBaseEntity, ...)
const rules = await corsa.rules.listRules(
  1, 20, undefined, undefined, undefined, undefined, undefined, ["$eq:client"]
);
```

```python Python theme={null}
from corsa_sdk.api.rules.list_rules import _get_kwargs

kwargs = _get_kwargs(limit=20, page=1)
kwargs["params"]["filter.baseEntity"] = ["$eq:client"]
resp = http.request(**kwargs)
rules = resp.json()
```

Rule responses include `baseEntity`, `triggers` and `alertOnEveryMatch`. A transaction rule returns `baseEntity: "transaction"` and `triggers: null`.

***

## What's next?

> [card] [Conditions reference](https://docs.corsa.finance/transaction-monitoring/conditions-reference.md)
>
> Operators, entities, aggregations and time windows.

> [card] [Lists](https://docs.corsa.finance/intelligence-hub/lists.md)
>
> Block, allow and watch lists your client rules can check.

> [card] [Ingesting sessions](https://docs.corsa.finance/api/ingesting-sessions.md)
>
> Send sessions so client rules can check the latest login.

> [card] [Alerts](https://docs.corsa.finance/case-management/alerts.md)
>
> Triage Client Monitoring alerts with the rest of your queue.


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