Open Source · MIT LicenseUCP-Ready

guardrail-sim

Policy simulation for agentic commerce. Test discount rules, validate AI agent requests, and enforce pricing guardrails before they hit production.

npm install @guardrail-sim/policy-enginebyJeff Green

Real Questions, Real Answers

Stop guessing. Start simulating.

Discount Stacking

Can a 20% coupon combine with a site-wide sale?

evaluate(policy, {
  discounts: [
    { type: 'coupon', value: 20 },
    { type: 'sale', value: 15 },
  ],
})

Agent Discount Validation

Should we allow this AI-negotiated discount?

// UCP-compatible validation
validate_discount_code({
  code: 'AGENT-DEAL-15',
  order: { value: 5000, margin: 0.4 },
})
// { valid: false, error_code: 'discount_code_user_ineligible' }

Time Windows

Is this Black Friday deal still active?

evaluate(policy, scenario, {
  context: {
    currentTime: new Date(),
  },
})

Why guardrail-sim?

Declarative Policies

Define rules as data, not code. Version, test, and deploy with confidence.

Instant Simulation

Test scenarios in milliseconds. No database, no side effects.

Catch Edge Cases

Discover stacking bugs, constraint conflicts, and policy gaps before customers do.

MCP Integration

Use with Claude and other AI assistants. Natural language policy testing.

UCP Compatible

Built for Universal Commerce Protocol. Standard error codes, allocations, and checkout flows.

MCP Tools

Twelve tools for testing policies conversationally with AI assistants.

evaluate_policy

Evaluate a proposed discount against the active pricing policy

get_policy_summary

Get a human-readable summary of the active policy rules

get_max_discount

Calculate the maximum allowed discount for a given order

validate_discount_code

Validate a discount code and get a UCP-compatible error code

simulate_checkout_discount

Simulate a UCP checkout with discount codes and allocations applied

run_simulation

Run adversarial buyer personas against the policy, deterministically

analyze_simulation

Run a simulation and surface policy health insights from the results

create_checkout

Create a UCP checkout session

get_checkout

Retrieve a UCP checkout session by id

update_checkout

Update a session and re-evaluate its discounts

complete_checkout

Complete a session, producing an order reference

cancel_checkout

Cancel a UCP checkout session

Define. Simulate. Ship.

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.15  // 15% discount request
);

// result.approved: true
// result.calculated_margin: 0.25

Why I built this

E-commerce discount logic is deceptively complex. Every rule has exceptions, every exception has edge cases.

I've seen teams accidentally stack discounts that cost thousands, or block legitimate promotions because the rules conflicted. Testing these scenarios manually is tedious and error-prone.

guardrail-sim lets you define policies declaratively and simulate outcomes before they hit production. Think of it as unit tests for your business rules.

JG
Built byJeff GreenProduct Engineer