Your First Rule
Let’s build a simple rule that calculates whether a customer qualifies for a discount. This tutorial will teach you the basics of facts, rules, and outcomes.What you’ll learn: By the end of this guide, you’ll understand how to create facts, write rules, and test your logic in the Flow Debugger.
Step 1: Understanding the Problem
Imagine you run an online store with this discount policy:- Orders over $100 get 10% off
- Orders under $100 get no discount
Step 2: Define Your Facts
Facts are your input data - the information your rules will evaluate. For our discount rule, we need to know the order total.Key concept: Facts are a flat key-value object. The keys (like
"orderTotal.value") are what you’ll reference in your rules using @fact:. The values can be static data or variable mapping expressions like "$.previous_step.data" to pull data from other steps in your flow.Facts with Variable Mapping
In a real flow, you’d typically map facts from previous steps using variable mapping:Step 3: Write Your Rule
Now let’s create a rule that checks if the order qualifies for a discount:Breaking Down the Rule
1
Rule Name
qualifiesForDiscount.value - The full unique name for this rule. The .value suffix is just a naming convention to create unique keys2
Operator
>= means “greater than or equal to”3
Input
Compare
@fact:orderTotal.value (120) against 1004
Result
Returns
true if condition is met, false otherwiseStep 4: Add the Rules Step to Your Flow
- Open your flow in the Flow Builder
- Click Add Step
- Select Rules from the available steps
- Configure the step:
- Facts: Map from a previous step using
$.previous_step_idor paste your test facts - Rules: Paste the rule JSON above
- Facts: Map from a previous step using

Step 5: Test Your Rule
Use the Flow Debugger to test with different values:- Test Case 1: $120 Order
- Test Case 2: $75 Order
- Test Case 3: Exactly $100
Input Facts:Expected Output:✅ Order total is ≥ $100, so discount applies
Step 6: Calculate the Discount Amount
Now let’s extend our rule to calculate the actual discount amount using conditional logic:Notice how rules reference each other: The
discountAmount rule uses @fact:qualifiesForDiscount.value to check the outcome of the first rule. The .value is part of the rule’s unique name, not a special property.Understanding Conditional Rules
ThediscountAmount rule uses the conditional format - an array of condition/outcome pairs:
1
First condition
If
qualifiesForDiscount is true, calculate 10% of order total2
Default outcome
If no conditions match, return 0 (no discount)
Test the Complete Rule
Input:Common Patterns You Just Learned
Comparison
Using operators like
>=, <, = to compare valuesConditional Logic
If-then-else using condition/outcome arrays
Calculations
Math operations like
* and -Rule References
Rules can reference other rules with
@fact:ruleName.property where the property is part of the unique nameCommon Beginner Mistakes
What’s Next?
Core Concepts
Deep dive into facts, rules, operators, and how the engine works
Operations Reference
Explore all available operators by category
Rule Patterns
Learn common patterns like validation, lookups, and array processing
Examples Library
See complete examples for e-commerce, CRM, support, and more
Quick Reference
Simple Rule Structure
Conditional Rule Structure
Referencing Facts and Rules
.value, .formatted) is just part of the unique name - use different suffixes when you want multiple calculations from the same data.
Common Operators
| Operator | Purpose | Example |
|---|---|---|
= | Equals | {"operator": "=", "input": ["@fact:status.value", "active"]} |
>= | Greater than or equal | {"operator": ">=", "input": ["@fact:age.value", 18]} |
< | Less than | {"operator": "<", "input": ["@fact:price.value", 100]} |
+ | Addition | {"operator": "+", "input": [10, 20]} |
* | Multiplication | {"operator": "*", "input": ["@fact:price.value", 0.9]} |
and | Boolean AND | {"operator": "and", "input": [condition1, condition2]} |
or | Boolean OR | {"operator": "or", "input": [condition1, condition2]} |
Need Help? Visit our Help Center or join the Community for support.