Constraints
Rules that policies enforce
Constraints
In guardrail-sim, constraints are implemented as policy rules using json-rules-engine. Each rule defines conditions that must be satisfied for a discount to be approved.
Default Constraints
The default policy includes these constraint rules:
Margin Floor
Ensures minimum margin is maintained after discount.
Maximum Discount
Caps the total discount percentage.
Volume Tier
Requires minimum quantity for larger discounts.
Creating Custom Constraints
Add new constraint rules to your policy:
Condition Logic
ALL Conditions (AND)
All conditions must be true for the rule to trigger:
ANY Conditions (OR)
At least one condition must be true:
Nested Conditions
Combine ALL and ANY for complex logic:
Available Operators
| Operator | Description | Example |
|---|---|---|
equal | Exact match | { fact: 'segment', operator: 'equal', value: 'gold' } |
notEqual | Not equal | { fact: 'segment', operator: 'notEqual', value: 'new' } |
lessThan | Less than | { fact: 'margin', operator: 'lessThan', value: 0.15 } |
lessThanInclusive | Less than or equal | { fact: 'discount', operator: 'lessThanInclusive', value: 0.25 } |
greaterThan | Greater than | { fact: 'quantity', operator: 'greaterThan', value: 100 } |
greaterThanInclusive | Greater than or equal | { fact: 'value', operator: 'greaterThanInclusive', value: 5000 } |
in | Value in array | { fact: 'segment', operator: 'in', value: ['gold', 'platinum'] } |
notIn | Value not in array | { fact: 'category', operator: 'notIn', value: ['clearance'] } |
contains | Array contains value | { fact: 'tags', operator: 'contains', value: 'vip' } |
Constraint Evaluation Order
Constraints are evaluated by rule priority (higher numbers first). Use priorities to:
- Fail fast: Check time/eligibility constraints first
- Layer logic: Apply volume tiers before final caps
- Ensure order: Run margin checks before stacking rules