Decision Tables
Decision Tables are the foundation of DTRules. They provide a tabular way to represent complex business logic that both policy experts and developers can understand.
What is a Decision Table?
A Decision Table is a matrix where:
- Rows represent conditions (tests) and actions (operations)
- Columns represent rules
- Cells contain condition values or action markers
The power of decision tables comes from their ability to represent complex conditional logic in a format that's easy to read, validate, and modify.
Anatomy of a Decision Table
A typical decision table has three sections:
1. Header Section
Contains metadata about the table:
- Name - Unique identifier for the table
- Type - BALANCED, FIRST, or ALL
- Description - What the table does
2. Condition Section
Each row is a boolean expression. Cells contain:
- Y - Condition must be true
- N - Condition must be false
- * or - - Condition is ignored (don't care)
3. Action Section
Each row is an operation to execute. Cells contain:
- X - Execute this action
- - or blank - Skip this action
Example Decision Table
Here's an example eligibility determination table:
| Rule 1 | Rule 2 | Rule 3 | Rule 4 | |
|---|---|---|---|---|
| Conditions | ||||
| age >= 18 | Y | Y | N | N |
| income < threshold | Y | N | Y | N |
| Actions | ||||
| set eligible = true | X | - | X | - |
| set reason = "income" | - | X | - | - |
| set reason = "age" | - | - | - | X |
Reading column by column:
- Rule 1: If age >= 18 AND income < threshold, set eligible = true
- Rule 2: If age >= 18 AND income >= threshold, set reason = "income"
- Rule 3: If age < 18 AND income < threshold, set eligible = true
- Rule 4: If age < 18 AND income >= threshold, set reason = "age"
Table Types
BALANCED
All possible condition combinations must be explicitly defined. The compiler will error if any combination is missing. This ensures completeness but requires more columns.
Use when: Every scenario must be explicitly handled (e.g., compliance requirements).
FIRST
Executes only the first matching column from left to right. Once a match is found, no other columns are evaluated.
Use when: Rules have priority/precedence (most specific rules first).
ALL
Executes all matching columns from left to right. Multiple rules can fire for the same input.
Use when: Multiple actions may apply (e.g., applying multiple discounts).
Writing Conditions
Conditions use DTRules Expression Language (EL). Common patterns:
// Simple comparisons
age >= 18
income < poverty_level
// Entity attribute access
applicant.age >= 65
application.status = "pending"
// Calculations
income / household_size < threshold
// Array operations
count of dependents > 0
any dependent satisfies (dependent.age < 18)
// Boolean combinations (within a single cell)
citizen or permanent_resident Writing Actions
Actions perform operations when conditions match:
// Set values
set eligible = true
set benefit_amount = income * 0.5
// Add to arrays
add applicant to eligible_list
// Call other decision tables
perform Calculate_Benefits
perform Verify_Documents
// Conditional execution
if income < 0 then set income = 0
// Loop operations
for each dependent do
perform Check_Dependent_Eligibility
done Best Practices
1. Keep Tables Focused
Each table should handle one specific decision. Complex logic should be split across multiple tables that call each other.
2. Order Conditions Logically
Put the most discriminating conditions first. This makes the table easier to read and can improve performance with FIRST tables.
3. Use Meaningful Names
Name your tables descriptively: Determine_Eligibility, Calculate_Benefits,
Verify_Income.
4. Document Complex Logic
Use the description field to explain the business rule being implemented, especially for regulatory requirements.
5. Test Edge Cases
For BALANCED tables, the compiler ensures completeness. For FIRST/ALL tables, manually verify that all important scenarios are covered.
Common Patterns
Lookup Table
Map input values to output values:
| 1 | 2 | 3 | |
|---|---|---|---|
| state = "TX" | Y | N | N |
| state = "CA" | N | Y | N |
| set tax_rate = 0.0625 | X | - | - |
| set tax_rate = 0.0725 | - | X | - |
| set tax_rate = 0.05 | - | - | X |
Cascading Rules
Apply rules in order, using FIRST type:
| 1 | 2 | 3 | |
|---|---|---|---|
| vip_customer | Y | * | * |
| order_total > 100 | * | Y | * |
| set discount = 0.20 | X | - | - |
| set discount = 0.10 | - | X | - |
| set discount = 0 | - | - | X |
Next Steps
- Entity Data Dictionary - Define your data model
- Expression Language - Write conditions and actions
- CHIP Tutorial - See decision tables in action