-
Notifications
You must be signed in to change notification settings - Fork 1
Rule definition language reference
ezrules
allows writing rules in expressive language, which can roughly be described as python with add-ons. Having python
backing the rule definition language, ezrules
allow writing logic of any complexity. Technically speaking, whatever python
can do, rules defined within ezrules can do too - complex conditional statements, loops, and any other language constructs.
To refer to a top-level event variable, one can use $
-notation. For example, if we have the following event defined:
{
"amount": 900,
"risk_score": 560
}
, then we can refer to those fields like this:
if $amount > 900 and $risk_score < 900:
return "RELEASE"
Note, that we use the return
statement to define what happens with the event if it matches the criteria in the rule definition.
Nested structures work too, one can write something like
if $customer["age"] > 25:
return "HOLD"
In the Lists
section of the Manager UI, one can define globally available lists. Those lists can later be referred to by their name and @
-notation, e.g.
if $origin_country in @NACountries:
return "HOLD"
Only outcomes mentioned in Outcomes
section are permitted in the return statements. If any other value is specified in the return, the rule will be rejected.
Technically, what ezrules does behind the door with a rule, is it wraps it into a function definition with a single input parameter t
. For example, if you wrote a rule of kind
if $amount > 900:
return "HOLD"
internally it will transformed into
def rule(t):
if t["amount"] > 900:
return "HOLD"