The rules engine is what risk and fraud teams use to change how transactions are approved or blocked, without touching application code. Each rule is a small expression that runs on every transaction Tracer validates — “block this MCC for this segment”, “send anything over R$ 50k to manual review”, “deny if the account is suspended”. What changes in your operation: rule changes ship through an API endpoint, not through a release. An analyst can publish a new rule in the morning and see it evaluating real transactions within seconds. Every match is recorded, so a denied customer call six months later can be traced back to the exact rule that fired. Trade-off to be honest about: you have to think in CEL (Common Expression Language) instead of Go, Python, or Java. The learning curve is short — most rules are one line — but the team writing them is no longer your application developers. The upside is no deploys, full audit, and the people closest to the policy own the policy. The Tracer rules engine evaluates validation logic written in — a type-safe expression language from Google. Expressions are compiled at rule creation and run during every transaction validation; you change behavior by updating rules through the API, without redeploying code.Documentation Index
Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
Use this file to discover all available pages before exploring further.
Why use the rules engine
- Flexibility: Create and modify rules without code deploys
- Performance: Compiled expressions evaluate in under 1ms each
- Type safety: Expression syntax validated at rule creation
- Every active rule runs: All matching rules are evaluated so the audit trail records every trigger, not just the winning category
- Scope-based: Apply rules to specific segments, accounts, or transaction types
- Understand rule engine concepts and evaluation flow
- Create and test expression-based rules
- Manage the rule lifecycle (DRAFT, ACTIVE, INACTIVE, DELETED)
- Apply best practices for rule management
What is the rules engine
The rules engine is the Tracer component responsible for evaluating expressions during transaction validation. It enables fraud analysts and risk managers to configure business logic that executes in real time—without requiring code deployments or engineering support.
How it works

- Load rules fetches all active rules from cache (or database on cache miss)
- Evaluate expressions runs all CEL expressions against the transaction context
- Collect matches gathers all rules that matched and determines the decision
Evaluation pattern
All active rules are evaluated against every transaction. There is no priority ordering or short-circuit evaluation. This ensures:- Complete audit trail (all matching rules recorded)
- No information loss (analysts can see all triggers)
- Simple logic (no priority conflicts)
- DENY — any matching
DENYrule wins outright. - Limit exceeded — if no DENY rule matched but any applicable limit is exceeded, the decision is DENY (rule precedence applies first; limits come in only when no DENY rule matched).
- REVIEW — if no DENY rule matched and no limit was exceeded, any matching
REVIEWrule wins. - ALLOW — if only
ALLOWrules matched, the decision is ALLOW. - Default — if no rule matched at all, Tracer returns the configured
DEFAULT_DECISION_WHEN_NO_MATCH(ALLOWunless explicitly set toDENYfor fail-closed deployments).
matchedRuleIds in the response contains every rule that matched, regardless of the winning category, so audit consumers can see all triggers.
Why DENY beats REVIEW beats ALLOW. Precedence is fixed and not configurable, on purpose: it removes the “which DENY rule wins?” ambiguity at runtime and makes audit trivial — the response always identifies the strictest action that fired. The cost is that you can’t write “ALLOW rules that override DENYs”; if you need that pattern, the right answer is to make the DENY rule more specific instead.
Tracer returns decisions; it does not block transactions directly. Your system receives the decision and is responsible for taking the appropriate action (e.g., blocking, allowing, or queuing for review).
Core concepts
Before creating rules, understand the foundational elements.
Rules
A rule is a unit of business logic composed of:- Expression - A type-safe expression that evaluates to true or false
- Action - What decision to return when the expression is true
- Scopes - Which transactions the rule applies to
- Status - The rule’s lifecycle state
Expressions
Expressions are written in CEL (Common Expression Language), a type-safe language that evaluates transaction context and returns a boolean value (true or false). CEL provides compile-time validation, so syntax errors are caught when you create the rule—not when transactions are being processed. Example expressions:merchant.category is the 4-digit ISO 18245 MCC code — "7995" is the MCC for betting/casino. Both merchant.category and merchant["category"] are accepted; the production examples use bracket notation by convention. If you need to match on a string label like "gambling", store it in metadata and match on that instead.)
Expressions have access to the full validation request context. The most commonly used variables are listed below. For the complete catalog of every nested field type and edge case (UUID format, enum values, omitempty behavior), see the ValidationRequest schema in the API reference.
| Variable | Type | What you typically match on |
|---|---|---|
amount | number | Decimal value converted to float64 for CEL evaluation (max ±2^53). |
transactionType | string | One of CARD, WIRE, PIX, CRYPTO. |
subType | string | Free-form (e.g., "international", "debit"). Empty string when not provided. |
currency | string | ISO 4217 code (e.g., "BRL"). |
account.status | string | One of active, suspended, closed. |
merchant.category | string | ISO 18245 MCC code, 4 digits. |
merchant.country | string | ISO 3166-1 alpha-2 (e.g., "BR"). |
segment.segmentId | string UUID | Segment scope of the transaction. |
metadata.<key> | any | Custom fields your integration passes in the request payload. |
segmentId and portfolioId live on the top-level segment and portfolio variables, not on account. To match by segment, use segment.segmentId == "...", not account.segmentId == "...". The segment, portfolio, and merchant maps are only present when the request includes them — guard with has(segment) if your rule must run even when the request doesn’t carry one.Expression evaluation is bounded by
CEL_COST_LIMIT (default 10000). Expressions exceeding this cost are rejected at activation time with TRC-0085 / TRC-0088.Expression examples by use case
Here are practical examples organized by business scenario:Amount-based rules
Merchant-based rules
Account-based rules
Combined conditions
Using metadata
Metadata fields are provided by your integration. Design your payload to include the context your rules need.
Actions
Actions determine the decision when an expression evaluates to true:| Action | Description |
|---|---|
ALLOW | Allow the transaction |
DENY | Deny the transaction |
REVIEW | Route to manual review |
Scopes
Scopes define which transactions a rule applies to. A rule with noscopes is global and evaluates against every transaction. A rule with one or more scope objects evaluates only when the transaction matches at least one of them (OR semantics across scope objects).
Within a single scope object, the supported fields are:
segmentId- Match transactions from a specific segmentportfolioId- Match transactions from a specific portfolioaccountId- Match transactions from a specific accountmerchantId- Match transactions to a specific merchanttransactionType- Match specific transaction types (CARD, WIRE, PIX, CRYPTO)subType- Match specific subtypes (debit, credit, instant, etc.)
- Within one scope object: fields combine with AND. A field that is not specified is treated as a wildcard (matches any value). At least one field must be set — empty scope objects (
{}) are rejected with TRC-0111. - Across multiple scope objects on the same rule: they combine with OR. The rule matches if any scope object matches the transaction.
transactionType: CARD and another targeting transactionType: PIX — runs for both card and PIX transactions. A single scope with both segmentId AND accountId requires the transaction to match the segment AND the account.
Rule lifecycle
Rules progress through a defined lifecycle to ensure safe deployment.

States
| State | Description |
|---|---|
DRAFT | Not evaluated; expression can be modified freely |
ACTIVE | Evaluated during validations; expression is immutable |
INACTIVE | Not evaluated; preserved for audit trail; can be reactivated. The expression is still immutable in this state — to edit it, move the rule back to DRAFT via POST /v1/rules/{id}/draft. |
DELETED | Soft-deleted; not returned by listings and cannot be recovered through the API, but the row is preserved in the database for audit trail. |
Transitions
| Transition | From | To | Description |
|---|---|---|---|
activate | DRAFT, INACTIVE | ACTIVE | Start evaluation (validates expression) |
deactivate | ACTIVE | INACTIVE | Stop evaluation |
draft | INACTIVE | DRAFT | Re-edit a previously deactivated rule before reactivating |
delete | DRAFT, INACTIVE | DELETED | Permanent removal (cannot delete ACTIVE rules) |
Active rules must be deactivated before deletion. This prevents accidental removal of rules that are currently being evaluated.
Create a rule
Create rules using
POST /v1/rules. Rules are created in DRAFT status by default.
A rule requires:
- name: A unique, descriptive name
- expression: A CEL expression that evaluates to true or false
- action: The decision to return when the expression matches (ALLOW, DENY, or REVIEW)
- scopes (optional): Limit which transactions the rule applies to
Activate and deactivate rules
After creating a rule, activate it to start evaluation. Deactivate rules to stop evaluation without deleting them.
| Operation | Endpoint | Description |
|---|---|---|
| Activate | POST /v1/rules/{id}/activate | Start evaluating this rule |
| Deactivate | POST /v1/rules/{id}/deactivate | Stop evaluating (preserves for audit) |
Deactivating a rule preserves it for audit purposes. Use delete only when you want to permanently remove a rule.
List and query rules
Query rules for management and auditing using
GET /v1/rules.
Query parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Filter by name (case-insensitive partial match) |
status | string | Filter by status (DRAFT, ACTIVE, INACTIVE). DELETED is not a valid filter value. |
action | string | Filter by action (ALLOW, DENY, REVIEW) |
account_id | UUID | Filter by scope: account ID |
segment_id | UUID | Filter by scope: segment ID |
portfolio_id | UUID | Filter by scope: portfolio ID |
merchant_id | UUID | Filter by scope: merchant ID |
transaction_type | string | Filter by scope: transaction type (CARD, WIRE, PIX, CRYPTO) |
sub_type | string | Filter by scope: subtype (e.g., debit, credit) |
limit | integer | Items per page (default: 10, max: 100) |
cursor | string | Pagination cursor from previous response |
sort_by | string | Sort field: created_at, updated_at, name, status (default: created_at) |
sort_order | string | Sort direction: ASC, DESC (default: DESC) |
Get a specific rule
UseGET /v1/rules/{id} to retrieve the full rule definition including expression and scopes.
Update a rule
Update rules using
PATCH /v1/rules/{id}. Rules can be updated in any status, with one important restriction:
Delete a rule
Delete rules that are no longer needed. Only DRAFT and INACTIVE rules can be deleted. ACTIVE rules must be deactivated first.
Best practices
Follow these practices for effective, maintainable rules.
Naming
- Use descriptive names - The name should clearly state what the rule does
- Include context - Mention the scenario or transaction type
- Avoid abbreviations - Prefer clarity over brevity
| Less clear | More clear |
|---|---|
Rule 1 | Block night transactions above BRL 5,000 |
Block high | Deny high-value weekend transactions |
PIX rule | Review PIX transfers to new recipients |
Expression design
- Keep expressions simple - Complex logic is harder to maintain
- Use scopes for filtering - Don’t repeat scope conditions in expressions
- Test edge cases - Consider boundary values and null fields
Lifecycle management
- Start in DRAFT - Test before activating
- Return to DRAFT before editing the expression - The expression is immutable in ACTIVE and INACTIVE; move the rule to DRAFT via
POST /v1/rules/{id}/draftto edit, then reactivate - Archive unused rules - Keep audit trail intact
- Delete only when certain - Deletion is permanent
Monitoring
- Review matched rules - Check which rules are triggering
- Monitor DENY rates - High deny rates may indicate overly aggressive rules
- Audit regularly - Ensure rules still align with business requirements
Quick reference
Key endpoints, actions, and status information.
Endpoints
| Operation | Method | Endpoint |
|---|---|---|
| Create rule | POST | /v1/rules |
| List rules | GET | /v1/rules |
| Get rule | GET | /v1/rules/{id} |
| Update rule | PATCH | /v1/rules/{id} |
| Delete rule | DELETE | /v1/rules/{id} |
| Activate rule | POST | /v1/rules/{id}/activate |
| Deactivate rule | POST | /v1/rules/{id}/deactivate |
| Draft rule | POST | /v1/rules/{id}/draft |
Statuses
| Status | Evaluated | Editable | Can delete |
|---|---|---|---|
DRAFT | No | Yes | Yes |
ACTIVE | Yes | Partial (expression immutable) | No (deactivate first) |
INACTIVE | No | Partial (expression immutable; return to DRAFT first) | Yes |
DELETED | No | No | N/A |

