Deterministic policy evaluation engine using json-rules-engine for AI pricing governance
npm install @guardrail-sim/policy-engine

Rules engine for B2B pricing policies. Define margin floors, discount caps, and volume tiers — evaluate orders against them deterministically.
Built on json-rules-engine. Part of guardrail-sim.
``bash`
npm install @guardrail-sim/policy-engine
`typescript
import { PolicyEngine, defaultPolicy } from '@guardrail-sim/policy-engine';
const engine = new PolicyEngine(defaultPolicy);
const result = await engine.evaluate(
{ order_value: 5000, quantity: 100, product_margin: 0.4 },
0.12 // 12% proposed discount
);
result.approved; // true
result.violations; // [] — no violations
result.calculated_margin; // 0.28
`
The default policy ships with three rules: 15% margin floor, 25% discount cap, and volume-based tiers (10% base, 15% for 100+ units).
- PolicyEngine(policy) — create an engine from a policy definition
- engine.evaluate(order, discount) — check a proposed discount against the rules
- calculateMaxDiscount(order) — find the highest discount an order can receive
- calculateAllocations(amount, lineItems, method) — split a discount across line items
- defaultPolicy` — the built-in policy (good for testing and demos)
- Getting Started
- Policy Concepts
MIT