Skip to main content

What is the Rules Step?

The Rules step evaluates business logic using a declarative rule engine. Instead of writing code, you define facts (your data) and rules (how to process it), and the engine automatically calculates outcomes.

Think of it as...

A spreadsheet formula system on steroids - where you define rules once and they automatically evaluate based on your data, handling complex logic like nested conditions, array processing, and dynamic calculations.

When to Use the Rules Step

Pricing & Discounts

Calculate dynamic pricing, volume discounts, promotional offers

Eligibility Checks

Determine qualifications, access levels, approval workflows

Data Validation

Enforce business constraints, validate forms, check data quality

Conditional Routing

Route tickets, prioritize tasks, assign based on criteria

How It Works

The Rules step takes two inputs:
1

Facts

A flat JSON object containing your data. Keys are what you reference with @fact:, values are either static data or variable mapping expressions like "$.previous_step.property"
2

Rules

A JSON object defining the logic - what to calculate or decide based on the facts
3

Outcomes

The Rules step evaluates all rules and returns a flat object with outcomes for each rule

Quick Example

Here’s a simple rule that calculates if an order qualifies for free shipping: Facts (Input Data):
{
  "orderTotal.value": 75,
  "isPremiumMember.value": false
}
Rules (Logic):
{
  "qualifiesForFreeShipping.value": {
    "operator": "or",
    "input": [
      {
        "operator": ">=",
        "input": ["@fact:orderTotal.value", 50]
      },
      {
        "operator": "=",
        "input": ["@fact:isPremiumMember.value", true]
      }
    ]
  }
}
Output:
{
  "qualifiesForFreeShipping.value": true
}

Key Capabilities

Perform calculations with add, subtract, multiply, divide, round, and advanced math functions
Build complex if-then-else logic with comparison operators and boolean operations
Concatenate, format, search, and transform text data
Filter, sort, sum, and transform arrays of data with wildcard support
Calculate date differences, add/subtract time periods, format dates
Map values, perform lookups, create dynamic option lists
Control form field visibility based on other values
Enforce business constraints and data quality requirements

Real-World Example: E-commerce Pricing

Here’s how an online store uses Rules to calculate dynamic pricing with discounts:
{
  "cartItems.value": [
    { "price": 29.99, "quantity": 2 },
    { "price": 49.99, "quantity": 1 }
  ],
  "customerTier.value": "gold"
}
This example calculates cart total using jPath to extract prices from the array, applies the better of tier discount or volume discount, and computes the final price. Notice how rules reference each other using @fact:ruleName.property - the .value suffix is just part of the unique rule name. Learn more about variable mapping to see how to pull data from previous steps.

Rule Formats

Rules can be written in two formats:

Simple Format

Direct calculation without conditions:
"ruleName.value": {
  "operator": "operatorName",
  "input": [param1, param2]
}

Conditional Format

Array of condition/outcome pairs, evaluated top to bottom:
"ruleName.value": [
  {
    "condition": {
      "operator": "operatorName",
      "input": [...]
    },
    "outcome": value
  },
  {
    "outcome": defaultValue
  }
]

Common Use Cases

E-commerce

Dynamic pricing, shipping calculations, inventory checks, promotional eligibility

CRM & Sales

Lead scoring, qualification criteria, territory assignment, commission calculations

Customer Support

Ticket routing, priority scoring, SLA calculations, escalation rules

Marketing

Campaign eligibility, audience segmentation, A/B test assignment, personalization rules

Financial Services

Transaction validation, risk scoring, approval workflows, fee calculations

Healthcare

Patient eligibility, risk assessment, appointment scheduling, treatment pathways

What’s Next?

Quick Tips

Start Simple: Begin with basic calculations and comparisons before building complex multi-condition logic
Test Often: Use the Flow tester to test your rules with different input values
Reference Outputs: Rules can reference the outcomes of other rules using @fact:ruleName.property - the property name (like .value) is just part of the unique rule name
Multiple Outcomes: You can create multiple calculations from the same data by using different property names: orderTotal.value, orderTotal.formatted, orderTotal.withTax
Outcome Order Matters: Within a single rule, outcomes are evaluated top to bottom - the first matching condition wins. However, the order of rules within your rules object doesn’t matter; rules can reference each other’s outcomes regardless of position.
Need Help? Visit our Help Center or join the Community for support.