Getting Started
Set up guardrail-sim in your project
Getting Started
Install guardrail-sim and evaluate your first policy in 5 minutes.
Installation
# Core policy engine
npm install @guardrail-sim/policy-engine
# MCP server for AI agent integration
npm install @guardrail-sim/mcp-server
# Optional: UCP types for TypeScript
npm install @guardrail-sim/ucp-types
# Optional: Policy insights and health checks
npm install @guardrail-sim/insightsYour First Policy Evaluation
The policy engine evaluates discount requests against rules:
import { PolicyEngine, defaultPolicy } from '@guardrail-sim/policy-engine';
import type { Order } from '@guardrail-sim/policy-engine';
// Create engine with default policy
const engine = new PolicyEngine(defaultPolicy);
// Define an order
const order: Order = {
order_value: 5000, // $5,000 order
quantity: 100, // 100 units
product_margin: 0.4, // 40% base margin
customer_segment: 'gold',
};
// Evaluate a 12% discount request
const result = await engine.evaluate(order, 0.12);
console.log(result);
// {
// approved: true,
// violations: [],
// applied_rules: ['margin_floor', 'max_discount', 'volume_tier'],
// calculated_margin: 0.28
// }Default Policy Rules
The default policy includes these rules:
| Rule | Description | Limit |
|---|---|---|
margin_floor | Minimum margin after discount | 15% |
max_discount | Maximum allowed discount | 25% |
volume_tier | Volume-based discount limits | 10% base, 15% for 100+ units |
Custom Policies
Create your own policy with custom rules:
import { PolicyEngine } from '@guardrail-sim/policy-engine';
import type { Policy } from '@guardrail-sim/policy-engine';
const customPolicy: Policy = {
id: 'holiday-2026',
name: 'Holiday Sale Policy',
description: 'Special limits for holiday promotions',
rules: [
{
id: 'holiday-max',
name: 'Holiday Max Discount',
priority: 1,
conditions: { all: [] },
event: {
type: 'max_discount',
params: { limit: 0.3 }, // 30% max
},
},
],
};
const engine = new PolicyEngine(customPolicy);Using with MCP
For AI agent integration, run the MCP server:
# Start the MCP server
npx @guardrail-sim/mcp-serverAdd to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"guardrail-sim": {
"command": "npx",
"args": ["@guardrail-sim/mcp-server"]
}
}
}The MCP server exposes 12 tools:
Policy
evaluate_policy- Evaluate discount against policyget_policy_summary- Get human-readable policy rulesget_max_discount- Calculate maximum allowed discount
UCP discounts
validate_discount_code- UCP-aligned pre-validationsimulate_checkout_discount- Full checkout simulation
Simulation
run_simulation- Run adversarial buyer personas, deterministicallyanalyze_simulation- Run a simulation and surface policy health insights
UCP checkout
create_checkout- Create a checkout sessionget_checkout- Retrieve a session by idupdate_checkout- Update a session and re-evaluate discountscomplete_checkout- Complete a session, producing an order referencecancel_checkout- Cancel a session
Next Steps
- Learn about Policies in depth
- Explore the MCP Tools reference
- See real-world examples
- Check Policy Insights for health checks