Policy Evaluation
How policies are evaluated during booking
Policy Evaluation
Policy evaluation is the process of checking a booking against the user's policy to determine if it's compliant and what action should be taken.
When Evaluation Happens
Policy evaluation occurs at key points in the booking flow:
- Review Step: When user views the booking summary
- Booking Submission: When user attempts to complete booking
- Request Creation: When a booking request is created
- Admin Processing: When admin processes a request
Evaluation Flow
Step 1: Policy Resolution
The system first determines which policy applies to the user.
Resolution Order (first match wins):
- User-specific policy (if assigned and within effective dates)
- Role-based policy (if user has an active role with assigned policy)
- Company default policy (fallback)
See Policy Hierarchy for details.
Step 2: Rule Matching
After resolving the policy, the system finds rules that match the booking.
For Flights
A rule matches if:
- Origin matches (city → country → wildcard)
- Destination matches (city → country → wildcard)
- isInternational matches (if specified)
For Hotels
A rule matches if:
- Location matches (city → country → wildcard)
See Rule Matching for the complete algorithm.
Step 3: Violation Check
Each matching rule is evaluated for violations:
Flight Violations
| Check | Violation If |
|---|---|
| Price | flightPrice > maxPricePerPerson (considering duration tiers) |
| Cabin Class | selectedClass NOT IN allowedCabinClasses (considering duration tiers) |
| Stops | flightStops > maxStops |
| Advance Booking | daysUntilDeparture < advanceBookingDays |
Hotel Violations
| Check | Violation If |
|---|---|
| Price | pricePerNight > maxPricePerNight |
| Star Rating | hotelStars NOT IN allowedStarRatings |
| Nights | stayNights > maxNights |
| Advance Booking | daysUntilCheckIn < advanceBookingDays |
Evaluation Order
Rules are sorted by budget threshold (descending) and evaluated in order:
- Highest budget rule checked first
- If violations found → stop, use this rule's action
- If no violations → check next rule
- All rules pass → ALLOW
Step 4: Action Determination
The final action is determined by:
Possible Actions
| Action | Result |
|---|---|
ALLOW | Booking proceeds normally |
WARN_AND_ALLOW | Warning shown, booking allowed |
REQUIRE_APPROVAL | Booking becomes a request |
BLOCK | Booking is prevented |
Evaluation Result
The evaluation returns:
{
compliant: boolean, // true if no violations
action: PolicyAction, // ALLOW, WARN_AND_ALLOW, REQUIRE_APPROVAL, BLOCK
violations: [ // List of violations (empty if compliant)
{
type: 'PRICE' | 'CABIN_CLASS' | 'STOPS' | 'ADVANCE_BOOKING' | 'STAR_RATING' | 'NIGHTS',
message: string,
limitValue: number | string[],
actualValue: number | string,
excessAmount?: number
}
],
matchedRule: { // The rule that matched (if any)
id: string,
// rule details...
}
}Multiple Violations
A single booking can have multiple violations:
Booking: $1,500 Business class, 3 stops
Violations:
1. PRICE: Exceeds budget by $500
2. CABIN_CLASS: Business not allowed
3. STOPS: 3 stops exceeds max of 1All violations are reported, but the first matching rule with violations determines the action.
No Matching Rules
If no rules match the booking criteria:
Without a catch-all rule, unmatched bookings use the policy's default action with no violations. This may allow bookings you didn't intend to permit. Always include a catch-all rule.
Booking Mode Integration
Policy evaluation works with booking modes:
| Mode | Evaluation Result | Outcome |
|---|---|---|
| DIRECT_BOOKING | ALLOW | Direct booking |
| DIRECT_BOOKING | REQUIRE_APPROVAL | Submit request |
| DIRECT_BOOKING | BLOCK | Cannot book |
| REQUEST_ONLY | Any | Submit request |
| HYBRID | ALLOW/WARN | Direct booking |
| HYBRID | REQUIRE_APPROVAL | Submit request |
| HYBRID | BLOCK | Cannot book |
API Endpoint
Policy evaluation is available via API:
POST /api/v1/policies/evaluateRequest body:
{
"flight": {
"originLocationId": "BGW",
"destinationLocationId": "DXB",
"isInternational": true,
"departureDate": "2024-03-15",
"price": 750,
"currency": "USD",
"cabinClass": "ECONOMY",
"stops": 0,
"durationHours": 2.5
}
}Response:
{
"bookingMode": "HYBRID",
"defaultAction": "REQUIRE_APPROVAL",
"flightEvaluation": {
"compliant": true,
"action": "ALLOW",
"violations": []
},
"matchedFlightRule": {
"id": "rule_123",
"maxPricePerPerson": 800,
"allowedCabinClasses": ["ECONOMY", "PREMIUM_ECONOMY"],
"originCityName": "Baghdad",
"destinationCityName": "Dubai"
}
}