Sparkient Docs
Core Concepts

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:

FieldDescription
nameHuman-readable identifier
conditionCEL expression evaluated against ctx (the input data)
thenThe decision to return if the condition is true
reason_codeWhy this decision was made
priorityLower numbers evaluate first (1 = highest priority)

Writing CEL Expressions

All input fields are available under the ctx namespace:

CEL expressions
// 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.

Example rules
[
  {
    "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 WhenUse ML When
The logic is simple and deterministicThe decision requires nuance or pattern recognition
You need guaranteed outcomes for specific conditionsEdge cases are hard to enumerate manually
Compliance requires exact, auditable logicThe decision should improve over time with data
Sub-millisecond latency is criticalSub-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 then value must match one of the decision type's options
  • The reason_code must match one of the allowed reason codes

On this page