Rule Matching
How policy rules are prioritized and matched to bookings
Rule Matching
When a user makes a booking, the system evaluates it against the policy's rules. Understanding how rules are matched helps you create effective policies.
The Matching Process
1. Get user's effective policy
↓
2. Filter rules that match the booking criteria
↓
3. Sort matching rules by budget threshold (descending)
↓
4. Evaluate each rule for violations
↓
5. First rule with violations → determines action
No violations in any rule → ALLOWStep 1: Policy Resolution
First, the system determines which policy applies to the user:
- User-specific policy (if assigned and within effective dates)
- Role-based policy (if assigned to user's role)
- Company default policy (fallback)
See Policy Hierarchy for details.
Step 2: Rule Filtering (Location Matching)
The system filters rules to find all that match the booking's location criteria.
Flight Rule Matching
A flight rule matches if ALL of the following conditions are true:
| Condition | Logic |
|---|---|
| Origin | Rule origin city matches, OR rule origin country matches (if no city specified), OR rule has no origin (wildcard) |
| Destination | Rule destination city matches, OR rule destination country matches (if no city specified), OR rule has no destination (wildcard) |
| International | Rule isInternational matches, OR rule has no isInternational setting (wildcard) |
Matching hierarchy for origin/destination:
1. City specified → must match exactly
2. Country specified (no city) → must match country
3. Neither specified (null) → matches any (wildcard)Hotel Rule Matching
A hotel rule matches if the location matches:
| Condition | Logic |
|---|---|
| Location | Rule city matches, OR rule country matches (if no city specified), OR rule has no location (wildcard) |
Null values in rules act as wildcards. A rule with no origin/destination restrictions matches all flights. A rule with no location restrictions matches all hotels.
Step 3: Sorting Matched Rules
After filtering, matching rules are sorted by budget threshold in descending order (highest budget first).
For flights, this considers duration-based tiers:
- The system calculates the effective budget for the flight's duration
- Rules are sorted by this duration-adjusted budget
Why descending order?
The system evaluates from highest budget to lowest. The first rule where the booking exceeds the limit triggers a violation. This ensures the most permissive matching rule that still has violations is selected.
Step 4: Violation Evaluation
Each matching rule is evaluated in order until a violation is found.
Flight Violations
| Violation Type | Triggered When |
|---|---|
| PRICE | Flight price exceeds rule's max budget (considering duration tiers) |
| CABIN_CLASS | Selected cabin class not in allowed list (considering duration tiers) |
| STOPS | Number of stops exceeds rule's max stops |
| ADVANCE_BOOKING | Booking made fewer than required days before departure |
Hotel Violations
| Violation Type | Triggered When |
|---|---|
| PRICE | Nightly rate exceeds rule's max price |
| STAR_RATING | Hotel star rating not in allowed list |
| NIGHTS | Stay length exceeds rule's max nights |
| ADVANCE_BOOKING | Booking made fewer than required days before check-in |
Step 5: Action Determination
| Scenario | Result |
|---|---|
| Violations found | Use rule's action if specified, otherwise use policy default action |
| No violations in any matching rule | Return ALLOW |
| No rules match the booking | Use policy default action (no violations) |
Duration Tier Evaluation
For flight rules with duration tiers, the system:
- Gets the flight's duration in hours
- Finds the matching tier range
- Uses that tier's budget/cabin limits for evaluation
Budget Tier Example
| Min Hours | Max Hours | Budget |
|---|---|---|
| 0 | 3 | $450 |
| 3 | 7 | $650 |
| 7 | null | $1,000 |
- 2-hour flight at $500: Uses 0-3hr tier ($450) → Price violation
- 5-hour flight at $600: Uses 3-7hr tier ($650) → No violation
- 10-hour flight at $900: Uses 7+hr tier ($1,000) → No violation
Cabin Tier Example
| Min Hours | Max Hours | Allowed Classes |
|---|---|---|
| 0 | 5 | Economy |
| 5 | 8 | Economy, Premium Economy |
| 8 | null | Economy, Premium Economy, Business |
- 4-hour flight, Business class: Uses 0-5hr tier (Economy only) → Cabin violation
- 6-hour flight, Premium Economy: Uses 5-8hr tier → No violation
- 10-hour flight, Business class: Uses 8+hr tier → No violation
If flight duration doesn't match any tier, the rule's base budget/cabin settings are used.
Complete Example
Policy rules (after matching a Baghdad → Dubai flight):
| Rule | Budget | Cabin | Priority |
|---|---|---|---|
| Baghdad → Dubai | $500 | Economy | 10 |
| Iraq → UAE | $700 | Economy, Premium | 20 |
| All international | $1,000 | Economy, Premium | 75 |
Booking: Baghdad → Dubai, $600, Premium Economy
- Filter: All 3 rules match (Baghdad is in Iraq, Dubai is in UAE, flight is international)
- Sort by budget (desc): $1,000, $700, $500
- Evaluate $1,000 rule: $600 < $1,000 ✅, Premium allowed ✅ → No violations
- Evaluate $700 rule: $600 < $700 ✅, Premium allowed ✅ → No violations
- Evaluate $500 rule: $600 > $500 ❌ → Price violation, Premium not allowed ❌ → Cabin violation
- Result: Violations found on $500 rule → Use that rule's action (or policy default)
The most specific rule (Baghdad → Dubai) triggers because it has the lowest budget. Even though less restrictive rules also match, the system finds violations against the strictest applicable limit.
Priority vs. Budget Sorting
Priority (set in the dashboard) controls:
- Display order in the UI
- Which rule is considered "primary" when multiple match
Budget sorting (during evaluation) ensures:
- The most restrictive applicable limit is enforced
- Violations are detected at the appropriate threshold
In practice, specific routes (Priority 10) typically have lower budgets than catch-all rules (Priority 100), so the two orderings often align.
Best Practices
Always Create a Catch-All Rule
Without a catch-all rule (matching "All flights" or "All hotels"), bookings that don't match any specific rule will use the policy's default action with no violations — effectively allowing them.
Route: All flights
Budget: $2,000
Cabin: Economy, Premium Economy
Action: (use policy default)Order Budgets from Specific to General
| Route | Budget | Rationale |
|---|---|---|
| Baghdad → Dubai | $500 | Known short route |
| Iraq → Gulf | $700 | Regional travel |
| International | $1,000 | Long-haul |
| All flights | $1,500 | Catch-all |
Use Duration Tiers for Long-Haul Flexibility
Don't set a single budget that's too low for long flights or too high for short flights:
Base: $500
Tiers:
0-4 hours: $450
4-8 hours: $700
8+ hours: $1,200Test Your Rules
Use the policy preview feature to verify rule matching:
- Go to Policies → Assignments
- Select a user
- Enter sample booking details
- See which rule matches and what violations would occur