{"article":{"title":"Custom DLP rules","breadcrumb":["Security","Custom DLP rules"],"body":"**What this solves**: Detect your own identifiers (employee numbers, project names, internal ticket formats) with rules you write, for the whole account or for a single key, and try them on sample text before saving.\n\nA custom rule is built from a fixed set of parts: one way to match, plus an optional checksum and optional context words. The parts and their limits come from one place, `GET /v1/dlp/capabilities`; the console form, the API and this page all read from it.\n\nCustom rules run only while data protection is on for the call (see [Data protection (DLP)](security)). They are added on top of the built-in types and the recommended rules; they do not replace them.\n\n### Where a rule applies\n\n| Scope | Applies to | Limit |\n|---|---|---|\n| `TENANT` | Every call of the account, including calls that go directly to a [Local Node](local-nodes) | 50 rules |\n| `KEY` | Calls made with that key only. The key must belong to your account | 20 rules per key |\n\nRules from both scopes run together on a key's calls. The scope is fixed when the rule is created.\n\nConsole: **Security** → **Custom rules**. The selector at the top switches between the whole account and one key.\n\n### Ways to match\n\n| `kind` | Fields | Notes |\n|---|---|---|\n| `KEYWORDS` | `keywords.words` (up to 100, each up to 64 characters), `keywords.wholeWord` | Always case-insensitive. With `wholeWord`, `Apollo` does not match inside `Apollos` |\n| `FORMAT` | `format.prefix`, `format.charset`, `format.length.min`/`max`, `format.boundary`, `format.suffix` | Prefix + characters of one set + bounded length. Prefix and suffix up to 32 characters, length up to 512, prefix plus minimum length at least 6 |\n| `REGEX` | `regex` (up to 500 characters) | Java regular expression syntax |\n\n`charset` is one of `ALNUM`, `UPPER_DIGIT`, `LOWER_DIGIT`, `HEX`, `DIGITS`, `B64URL`, `B64`. `boundary` is `WORD` (the match may not touch a letter, digit, `_` or `-` on either side) or `NONE`.\n\nA regular expression is checked when saved: it must compile, must not match empty text, and must stay fast on long input. Patterns that start with `.*` or nest repetition such as `(a+)+` are refused with the reason. At scan time a rule that runs out of its time budget fails the call instead of letting it through.\n\nKeywords and formats are compiled into a pattern that runs in linear time, so prefer them over a hand-written regex when they fit.\n\n### Checksum\n\n`checksum` keeps only matches whose digits pass a check. Separators (spaces and `-`) are ignored when checking.\n\n| Name | Check |\n|---|---|\n| `LUHN` | Luhn mod 10 (bank card numbers) |\n| `IBAN_MOD97` | IBAN mod 97 |\n| `CN_RESIDENT_ID` | China resident ID, GB 11643 |\n| `TW_NATIONAL_ID` | Taiwan national ID |\n| `TW_RESIDENT_CERT` | Taiwan resident certificate (old and new format) |\n| `TW_UBN` | Taiwan unified business number |\n\n### Context words\n\n`context` keeps only matches that have one of the words within `window` characters before or after them. Up to 20 words, each up to 32 characters, `window` from 1 to 200 (default 40). Words are compared case-insensitively.\n\nUse it for bare numbers: an 8-digit number is everywhere, an 8-digit number within 20 characters of \"member no.\" is not.\n\n### Action\n\n`action` is `MASK` (replace with a placeholder and continue), `BLOCK` (fail the call, not billed) or `ALERT` (forward unchanged, record and notify). The result of each is the same as for built-in types; see [Data protection (DLP)](security).\n\n### Rule schema\n\n```json\n{\n  \"id\": 12,\n  \"scope\": \"TENANT\",\n  \"keyId\": null,\n  \"name\": \"Member number\",\n  \"kind\": \"REGEX\",\n  \"regex\": \"\\\\b\\\\d{8}\\\\b\",\n  \"keywords\": null,\n  \"format\": null,\n  \"checksum\": null,\n  \"context\": { \"words\": [\"member no\", \"會員編號\"], \"window\": 20 },\n  \"action\": \"MASK\",\n  \"enabled\": true,\n  \"description\": \"Loyalty programme\",\n  \"updatedAt\": \"2026-11-20T14:02:11\"\n}\n```\n\nOnly the fields of the rule's `kind` are set. `name` is up to 64 characters and unique within its scope; `description` is up to 255 characters.\n\nWhen a rule blocks a call, the error returned to the caller says `CUSTOM_RULE` without the rule's name, so your rule names never reach the application that made the call. Test scans and the console show the name.\n\n### Endpoints\n\nConsole session: `/v1/dlp/...`. [Management key](management-key): the same paths under `/v1/manage/dlp/...`.\n\n| Method | Path | What it does |\n|---|---|---|\n| `GET` | `/v1/dlp/capabilities` | The parts, names and limits above |\n| `GET` | `/v1/dlp/rules?scope=TENANT` | Account rules. `scope=KEY&keyId=N` for one key, `scope=ALL` for both |\n| `POST` | `/v1/dlp/rules` | Create. Body: `scope`, `keyId` (for `KEY`), and the rule fields |\n| `PUT` | `/v1/dlp/rules/{id}` | Change. Fields you send replace the stored ones; `scope` and `keyId` cannot change |\n| `DELETE` | `/v1/dlp/rules/{id}` | Delete |\n| `POST` | `/v1/dlp/rules/test` | Test scan, nothing is saved |\n\nThe test scan takes `text` (up to 20,000 characters). With `rule` it runs only that draft rule. Without `rule` it runs everything in effect for `keyId` (or the account): built-in types, recommended rules and saved custom rules.\n\n```bash\ncurl -X POST https://tare.jamerly.ai/v1/dlp/rules/test \\\n  -H \"Authorization: Bearer $TOKEN\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"text\": \"Refund for member no 40271536, order 99812733\",\n    \"rule\": {\n      \"name\": \"Member number\",\n      \"kind\": \"REGEX\",\n      \"regex\": \"\\\\b\\\\d{8}\\\\b\",\n      \"context\": { \"words\": [\"member no\"], \"window\": 20 },\n      \"action\": \"MASK\"\n    }\n  }'\n```\n\n```json\n{\n  \"code\": 200,\n  \"data\": {\n    \"hits\": [{ \"label\": \"CUSTOM:Member number\", \"action\": \"MASK\", \"start\": 21, \"end\": 29, \"matched\": \"40271536\" }],\n    \"blocked\": false,\n    \"blockedLabel\": null,\n    \"maskedText\": \"Refund for member no [CUSTOM_REDACTED], order 99812733\"\n  }\n}\n```\n\n### More examples\n\nProject code names, whole words only:\n\n```json\n{ \"scope\": \"TENANT\", \"name\": \"Project names\", \"kind\": \"KEYWORDS\",\n  \"keywords\": { \"words\": [\"Apollo\", \"Gemini\", \"Artemis\"], \"wholeWord\": true }, \"action\": \"MASK\" }\n```\n\nAn internal token format on one key, blocked:\n\n```json\n{ \"scope\": \"KEY\", \"keyId\": 314, \"name\": \"Internal token\", \"kind\": \"FORMAT\",\n  \"format\": { \"prefix\": \"itk_\", \"charset\": \"B64URL\", \"length\": { \"min\": 32, \"max\": 40 }, \"boundary\": \"WORD\", \"suffix\": null },\n  \"action\": \"BLOCK\" }\n```\n\nCard numbers only next to the word \"card\", checked with Luhn, alert only:\n\n```json\n{ \"scope\": \"TENANT\", \"name\": \"Card near label\", \"kind\": \"REGEX\", \"regex\": \"\\\\b(?:\\\\d[ -]?){15}\\\\d\\\\b\",\n  \"checksum\": \"LUHN\", \"context\": { \"words\": [\"card\"], \"window\": 30 }, \"action\": \"ALERT\" }\n```\n\n### On a Local Node\n\nAccount rules also run on calls that go directly to your [Local Node](local-nodes). A node runs them through its DLP sidecar. A sidecar from before custom rules gained checksums and context words runs only the pattern part of such a rule, so it may catch more than the same rule does in Tare. Update the sidecar to the current release to get the same result on both paths.\n\n### Next steps\n\n- Built-in types and the order in which settings win: read [Data protection (DLP)](security).\n- Manage rules from your own product: read [Management key](management-key).\n- Get notified on `ALERT` hits: read [Alerts](alerts).\n"}}