JSON Decision Model (JDM) Schema Reference
PyRulesEngine acts as a direct structural interpretation of the standardized JSON rules schema. Configurations can be authored fluidly in both JSON and YAML.
Core Object Hierarchy
A workflow array expects top level Workflow definitions.
Rule Fields
Each Rule object represents a decision evaluation node.
| Field | Type | Description |
|---|---|---|
RuleName |
String | A unique name defining the node block in the workflow sequence. |
RuleExpressionType |
Enum | The execution evaluator format: "LambdaExpression", "Error". Default LambdaExpression. |
Operator |
Enum | Logical aggregator for child sub-rules. Options: And, AndAlso, Or, OrElse. Default: None |
Expression |
String | The actual CEL (Common Expression Language) conditional snippet. Required if Operator is omitted. Supports built-in math: abs, min, max, round. |
SuccessEvent |
String | A custom string returned in the payload upon successful evaluation mapping. |
ErrorMessage |
String | A custom string returned in the payload upon failure mapping. |
Enabled |
Boolean | True (default) evaluates the rule. False bypasses it proactively. |
Rules |
Array | Only used alongside an Operator wrapper to create multi-rule chains. |
LocalParams |
Array | Variable injection overriding or mapping specific inputs to shorter aliases. |
Actions |
Object | Triggers side effects OnSuccess or OnFailure. |
Google CEL Syntax Rule
PyRulesEngine expressions follow strictly Google's Common Expression Language (CEL) syntax. Key departures from legacy engines include:
- Case-Sensitive Booleans: Must be lowercase true or false.
- Logical Operators: Use && (and), || (or), and ! (not).
- Equality: Use == and !=.
- Built-in Functions:
- abs(x): Absolute value of a number.
- min(a, b, ...): Minimum of a sequence.
- max(a, b, ...): Maximum of a sequence.
- round(x): Rounds to nearest integer.
- Macros: Use .exists(), .all(), .filter(), and .map() for collection processing.
Actions
You can execute chained implementations natively upon rule resolution using the Actions array.
"Actions": {
"OnSuccess": {
"Name": "ExecuteWorkflow",
"Context": {
"WorkflowName": "NotificationFlow"
}
},
"OnFailure": {
"Name": "EvaluateRule",
"Context": {
"WorkflowName": "FallbackFlow",
"RuleName": "DefaultBehavior"
}
}
}
The system ships with two native actions:
* ExecuteWorkflow: Chute outputs and results into an entirely different file or defined Workflow schema recursively.
* EvaluateRule: Jump specifically into a targeted, named isolated Rule node from any registered workflow.
(Note: Custom plugins can be mapped by registering action classes derived from ActionBase to the engine's Action Registry).
Aggregator Operators (And, AndAlso, Or, OrElse)
When constructing branching logic, PyRulesEngine schemas act as a tree. The top-level Operator decides how to fold the Rules array.
And: Evaluates all rules, ensuring every single returning result isTrue.AndAlso: Identical toAnd, but instantly shorts out and skips future checks the moment any child rule evaluates toFalse.Or: Evaluates all rules, passing if at least one returnedTrue.OrElse: Identical toOr, but instantly short-circuits to pass the moment any child rule evaluates toTrue.
RuleName: "IsSafeToProceed"
Operator: "AndAlso"
SuccessEvent: "System Nomimal"
Rules:
- RuleName: "EnvironmentIsProd"
Expression: "config.env == 'production'"
- RuleName: "TokensAreValid"
Expression: "secret.validity > 0"
RuleExpressionType (LambdaExpression vs DecisionTable vs Switch)
LambdaExpression: (Default) Returns whatever mathematical/logical truth theExpressionreturns.
To act as an explicit "Blocker" or "Kill Switch", you would map a LambdaExpression with ErrorType: Error (which is the default). If True, the Rule Engine deliberately fails the rule.
{
"RuleName": "DenyBlacklistedIP",
"RuleExpressionType": "LambdaExpression",
"ErrorType": "Error",
"Expression": "network.ip in ['192.168.1.1', '10.0.0.5']",
"ErrorMessage": "IP is blacklisted. Access denied."
}
Parameter Aliasing (LocalParams)
Useful for avoiding deeply nested schema repetitions in Lambda expressions. Instead of referencing invoice.payment.gateway.status, define a local alias.