Skip to main content

Overview

These examples show how to use Rules for real business scenarios. Each example includes the complete facts, rules, and output, with explanations of key patterns used.
Copy and customize: These are production-ready examples. Copy the entire facts and rules objects, then modify them for your specific business needs.

E-commerce: Checkout Pricing

Calculate final pricing for an e-commerce checkout with tiered discounts, shipping, and tax.

Business Context

An online store needs to:
  • Apply volume discounts (5% at $50, 10% at $100, 15% at $200)
  • Calculate shipping ($0 if order > $50, otherwise $7.99)
  • Apply state tax based on shipping location
  • Show formatted prices for display

Implementation

{
  "cartItems.value": [
    { "name": "Widget A", "price": 29.99, "quantity": 2 },
    { "name": "Widget B", "price": 49.99, "quantity": 1 },
    { "name": "Widget C", "price": 19.99, "quantity": 1 }
  ],
  "shippingState.value": "CA",
  "customerTier.value": "silver"
}

Key Patterns Used

  • Array processing with wildcards to calculate cart subtotal
  • Tiered discounts with conditional outcomes
  • Lookup tables for state tax rates
  • Conditional logic for free shipping threshold
  • String formatting for display values

CRM: Lead Scoring & Qualification

Score and qualify leads based on multiple criteria for sales prioritization.

Business Context

A B2B SaaS company needs to:
  • Score leads based on company size, industry, and engagement
  • Determine if lead is qualified (SQL - Sales Qualified Lead)
  • Assign priority level for follow-up
  • Calculate days until follow-up is needed

Implementation

{
  "companySize.value": "50-200",
  "industry.value": "technology",
  "jobTitle.value": "VP Engineering",
  "emailOpens.value": 5,
  "websiteVisits.value": 8,
  "pricingPageViews.value": 3,
  "demoRequested.value": true,
  "annualRevenue.value": 5000000,
  "createdDate.value": "2025-10-01T10:00:00Z"
}

Key Patterns Used

  • Weighted scoring from multiple criteria
  • Lookup tables for size and industry scores
  • String matching for job title evaluation
  • Multi-condition qualification with AND/OR logic
  • Priority assignment based on score thresholds
  • Date calculations for follow-up scheduling

Customer Support: Ticket Routing & Prioritization

Automatically route and prioritize support tickets based on content and customer data.

Business Context

A customer support team needs to:
  • Determine ticket priority based on urgency words and customer tier
  • Calculate SLA deadline
  • Route to appropriate team
  • Flag tickets requiring manager attention

Implementation

{
  "subject.value": "URGENT: Payment processing error on checkout",
  "description.value": "Our customers cannot complete purchases. This is blocking all sales. Please help immediately.",
  "customerTier.value": "enterprise",
  "accountValue.value": 50000,
  "issuesLast30Days.value": 1,
  "category.value": "technical",
  "createdDate.value": "2025-10-09T14:30:00Z"
}

Key Patterns Used

  • Text analysis with string matching for urgency detection
  • Weighted scoring from multiple factors
  • Priority calculation with threshold-based assignment
  • SLA deadline calculation with date operations
  • Dynamic routing based on ticket category
  • Automatic tagging with generateArray pattern

Marketing: Campaign Eligibility

Determine which marketing campaigns a customer is eligible for based on their profile and behavior.

Business Context

A marketing team needs to:
  • Check eligibility for multiple campaigns
  • Calculate discount offers
  • Generate personalized recommendations
  • Track campaign assignments

Implementation

{
  "customerId.value": "C12345",
  "totalPurchases.value": 8,
  "lifetimeValue.value": 1250,
  "daysSinceLastPurchase.value": 45,
  "emailEngagementRate.value": 0.35,
  "preferredCategory.value": "electronics",
  "hasAppInstalled.value": false,
  "birthdayMonth.value": 10,
  "currentMonth.value": 10
}

Key Patterns Used

  • Multi-criteria eligibility with boolean flags
  • Multiple campaign evaluation in parallel
  • Best offer selection using max operator
  • Dynamic list generation with generateArray
  • Personalized messaging with string templates
  • Product recommendations with category mapping

Financial: Loan Approval Decision

Evaluate loan applications based on credit score, income, and debt-to-income ratio.

Business Context

A lending institution needs to:
  • Calculate debt-to-income ratio
  • Determine approval status
  • Set interest rate based on risk profile
  • Calculate maximum loan amount
  • Specify required documentation

Implementation

{
  "applicantName.value": "John Smith",
  "annualIncome.value": 75000,
  "monthlyDebt.value": 1200,
  "creditScore.value": 720,
  "employmentYears.value": 5,
  "requestedAmount.value": 250000,
  "downPayment.value": 50000,
  "propertyValue.value": 300000,
  "hasCoApplicant.value": false
}

Key Patterns Used

  • Financial ratio calculations (DTI, LTV)
  • Multi-criteria approval with AND logic
  • Risk-based tiering with multiple conditions
  • Dynamic document requirements with generateArray
  • Conditional calculations for approved amounts
  • Validation with feedback showing decline reasons

Inventory Management: Stock Reorder Decision

Determine when to reorder inventory based on current stock, sales velocity, and lead times.

Business Context

A warehouse needs to:
  • Calculate days of inventory remaining
  • Determine if reorder is needed
  • Calculate optimal reorder quantity
  • Set priority level for procurement
  • Estimate next stockout date

Implementation

{
  "productId.value": "SKU-12345",
  "currentStock.value": 150,
  "avgDailySales.value": 12,
  "supplierLeadTimeDays.value": 14,
  "minStockLevel.value": 100,
  "maxStockLevel.value": 500,
  "orderCost.value": 50,
  "unitCost.value": 25,
  "isSeasonalItem.value": false,
  "supplierReliability.value": "high"
}

Key Patterns Used

  • Inventory calculations (days of inventory, reorder points)
  • Risk assessment with tiered thresholds
  • Dynamic reorder quantities based on min/max levels
  • Date projections for stockout estimation
  • Priority mapping for procurement urgency
  • Conditional recommendations with string templates

What’s Next?

Need Help? Visit our Help Center or join the Community for support.