Policies
The building blocks of guardrail-sim
Policies
A policy is a named collection of rules that define what discounts are allowed in B2B pricing.
Policy Structure
Required Fields
- id: Unique identifier for the policy
- name: Human-readable name
- rules: Array of rules to enforce
Policy Rules
Each rule uses the json-rules-engine format with conditions and events:
Example Rule
Default Policy
The default policy includes three rules:
Custom Policies
Create custom policies with your own rules:
Rule Conditions
Conditions use facts, operators, and values:
| Operator | Description |
|---|---|
equal | Exact match |
notEqual | Not equal |
lessThan | Less than value |
lessThanInclusive | Less than or equal |
greaterThan | Greater than value |
greaterThanInclusive | Greater than or equal |
in | Value in array |
notIn | Value not in array |
contains | Array contains value |
Available Facts
The policy engine provides these facts for conditions:
| Fact | Description |
|---|---|
order_value | Total order value in dollars |
quantity | Total units in order |
product_margin | Base margin (0.40 = 40%) |
proposed_discount | Requested discount (0.15 = 15%) |
calculated_margin | Margin after discount |
customer_segment | Customer tier (gold, silver, etc.) |
Best Practices
- Name rules clearly: Use descriptive names like
margin_floornotrule1 - Set priorities: Higher priority rules run first
- Provide messages: Include helpful violation messages
- Test thoroughly: Use multiple test scenarios