@guardrail-sim/policy-engine
v0.2.1
Published
Deterministic policy evaluation engine using json-rules-engine for AI pricing governance
Maintainers
Readme
@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.
Install
npm install @guardrail-sim/policy-engineQuick Start
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.28The default policy ships with three rules: 15% margin floor, 25% discount cap, and volume-based tiers (10% base, 15% for 100+ units).
API
PolicyEngine(policy)— create an engine from a policy definitionengine.evaluate(order, discount)— check a proposed discount against the rulescalculateMaxDiscount(order)— find the highest discount an order can receivecalculateAllocations(amount, lineItems, method)— split a discount across line itemsdefaultPolicy— the built-in policy (good for testing and demos)
Docs
License
MIT
