Skip to main content

Overview

This technical reference documents the Rules step’s input/output format, data types, and behavior specifications. Use this as a reference when building integrations or debugging rule execution.

Input Schema

The Rules step accepts two required inputs: facts and rules.

Facts Input

Type: Object<string, any> A flat key-value object where keys are fact identifiers and values are either static data or variable mapping expressions.
Example:
Constraints:
  • Keys must be valid JSON strings
  • Keys are case-sensitive
  • Duplicate keys will be overwritten (last one wins)
  • Values can be any valid JSON type or variable mapping expression

Rules Input

Type: Object<string, Rule> An object where each key is a rule name (the output key) and each value defines how to calculate that rule.

Simple Rule Format

Direct calculation without conditions:
Example:

Conditional Rule Format

Array of condition/outcome pairs evaluated top-to-bottom:
Example:
Constraints:
  • At least one outcome object required
  • Last outcome typically has no condition (default case)
  • First matching condition determines the result
  • Conditions evaluated strictly in order

Output Schema

The Rules step returns a flat object with outcomes for each rule. Type: Object<string, any>
Example Input:
Example Output:

Data Types

The Rules engine works with standard JSON data types and performs automatic type coercion where appropriate.

Supported Types

Floating-point numbers following JSON number specification.Examples:
Operations: All math operatorsCoercion: Strings containing numbers are auto-converted in math operations
UTF-8 text strings.Examples:
Operations: String operators, comparison operatorsNote: Empty string "" is truthy in boolean context
True or false values.Examples:
Operations: Logic operators, comparison operatorsCoercion:
  • Truthy: true, non-zero numbers, non-empty strings, non-empty arrays, objects
  • Falsy: false, 0, null, undefined
Represents absence of value.Example:
Behavior:
  • Falsy in boolean context
  • Treated as 0 in numeric operations
  • Treated as empty string in string operations
Ordered collection of values.Examples:
Operations: Array operators, aggregation functionsNote: Empty array [] is truthy
Key-value collections.Examples:
Operations: Lookup operators, JSON operatorsNote: Empty object {} is truthy

Fact Referencing

Reference facts in rules using the @fact: prefix followed by the exact fact key.

Syntax

Examples:

Resolution Order

  1. Check facts object - Look for exact key match in facts
  2. Check prior rules - If not found in facts, check rule outcomes
  3. Error if not found - Undefined references cause rule evaluation to fail

Nested References

Rules can reference other rules, creating a dependency chain:
The engine automatically determines the correct evaluation order: subtotaltaxtotal

Operator Input Types

Different operators expect different input formats.

Single Value

Operators that work on one value:

Two Values

Binary operators:

Multiple Values

Operators accepting variable arguments:

Array Input

Operators that process arrays:
Or extracted from facts:

Nested Operations

Operators can be nested as input values:

Evaluation Process

Understanding how the Rules engine processes your rules:
1

1. Variable Mapping Resolution

All facts containing variable mapping expressions (starting with $) are resolved by fetching data from previous steps in the flow
2

2. Dependency Analysis

The engine analyzes which rules reference which facts and other rules, building a dependency graph
3

3. Topological Sort

Rules are ordered so dependencies are evaluated before dependents (rules that need them)
4

4. Rule Evaluation

Each rule is evaluated in dependency order:
  • For simple rules: operator is applied to inputs
  • For conditional rules: conditions checked top-to-bottom until match found
5

5. Output Generation

All rule outcomes are collected into a flat output object with keys matching rule names

Circular Dependencies

The engine detects circular dependencies and will fail with an error: Invalid (circular):
Error: Circular dependency detected: a.value → b.value → a.value

Performance Characteristics

Understanding performance implications of rule design:

Time Complexity

Best Practices

Minimize Conditions

Use between operator instead of multiple >= conditions when possible

Reuse Calculations

Calculate once and reference multiple times rather than recalculating

Limit Nesting

Deep nesting reduces readability and debuggability - break into multiple rules

Optimize Array Operations

Extract array values once with jPath, then reuse the extracted arrays

Memory Considerations

  • Facts: Stored in memory during execution
  • Intermediate results: Each rule outcome stored for potential reuse
  • Arrays: Large arrays (>10,000 elements) may impact performance

Error Handling

Common error scenarios and their meanings:

Undefined Reference

Error: Undefined fact reference: @fact:nonexistent.value Cause: Referenced a fact or rule that doesn’t exist Solution: Check spelling, ensure fact is defined, or that dependent rule is defined

Invalid Operator

Error: Unknown operator: invalidOp Cause: Used an operator name that doesn’t exist Solution: Check Operations Reference for valid operators

Type Mismatch

Error: Type error: cannot perform 'add' on string and number Cause: Operator received incompatible types Solution: Ensure operands are correct types or use type conversion operators

Circular Dependency

Error: Circular dependency detected: rule1 → rule2 → rule1 Cause: Rules reference each other in a loop Solution: Restructure rules to eliminate circular references

Malformed Rule

Error: Invalid rule format for 'ruleName.value' Cause: Rule doesn’t match simple or conditional format Solution: Ensure rule has operator and input fields, or is an array of condition/outcome objects

Debugging Tips

The Flow Debugger shows:
  • Input facts after variable mapping resolution
  • Each rule’s outcome
  • Evaluation order
  • Errors with context
Test rules incrementally, adding one at a time.
Break complex rules into smaller steps:Hard to debug:
Easy to debug:
Ensure variable mapping expressions in facts are valid:
  • Use correct $.step_id.property syntax
  • Referenced step must execute before Rules step
  • Property path must exist in step output
Test variable mapping separately before adding to rules.
Common type issues:
  • Strings that should be numbers: "100" vs 100
  • Null/undefined values in calculations
  • Empty arrays in aggregations
Add validation rules to check input types.
Test with boundary values:
  • Empty arrays []
  • Zero values 0
  • Null values null
  • Empty strings ""
  • Large numbers
  • Negative numbers
Ensure rules handle all cases gracefully.

Integration Patterns

Using Rules Step Output

Access rule outcomes in subsequent flow steps using variable mapping:

Passing Arrays

When passing arrays to subsequent steps, the entire array is available: Rules output:
Next step can access:

Conditional Flow Routing

Use rule outcomes to determine flow paths:
Then in a subsequent condition step:

Limits & Constraints

Be aware of these limitations:
Exceeding these limits may cause performance degradation or execution failures. Break large rule sets into multiple Rules steps if needed.

What’s Next?

Getting Started

Build your first rule with step-by-step guidance

Core Concepts

Understand how the Rules engine works

Operations Reference

Complete reference for all available operators

Examples Library

Real-world examples with complete code
Need Help? Visit our Help Center or join the Community for support.