Rules
CEL-based hard rules for deterministic, sub-millisecond decisions.
Rules are the fastest stage of the decision pipeline. They evaluate in sub-millisecond time using the Common Expression Language (CEL) and produce deterministic, explainable outcomes.
How Rules Work
Rules are evaluated before the ML classifier. If any rule matches the input, the decision is returned immediately — no ML inference needed.
Each rule specifies:
| Field | Description |
|---|---|
name | Human-readable identifier |
condition | CEL expression evaluated against ctx (the input data) |
then | The decision to return if the condition is true |
reason_code | Why this decision was made |
priority | Lower numbers evaluate first (1 = highest priority) |
Writing CEL Expressions
All input fields are available under the ctx namespace:
// Simple comparison
ctx.amount > 10000
// String matching
ctx.action_type == "delete"
// Combining conditions
ctx.user_verified == true && ctx.risk_score < 0.3
// List operations
ctx.tags.exists(t, t == "urgent")
// Nested access
ctx.metadata.source == "api"Rule Evaluation Order
Rules are evaluated in priority order (lowest number first). The first rule that matches wins.
[
{
"name": "block_high_risk",
"condition": "ctx.risk_score > 0.95",
"then": "block",
"reason_code": "extreme_risk",
"priority": 1
},
{
"name": "auto_approve_verified",
"condition": "ctx.user_verified == true && ctx.amount < 100",
"then": "approve",
"reason_code": "trusted_user",
"priority": 2
}
]If no rules match, the decision falls through to the ML classifier.
When to Use Rules vs ML
| Use Rules When | Use ML When |
|---|---|
| The logic is simple and deterministic | The decision requires nuance or pattern recognition |
| You need guaranteed outcomes for specific conditions | Edge cases are hard to enumerate manually |
| Compliance requires exact, auditable logic | The decision should improve over time with data |
| Sub-millisecond latency is critical | Sub-100ms is fast enough |
Rules and ML work together — rules handle the obvious cases instantly, and the ML classifier handles everything else.
Validation
Rules are validated at creation time:
- CEL syntax must be valid
- The
thenvalue must match one of the decision type's options - The
reason_codemust match one of the allowed reason codes