RahalCorporate
PoliciesConcepts

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:

  1. Review Step: When user views the booking summary
  2. Booking Submission: When user attempts to complete booking
  3. Request Creation: When a booking request is created
  4. 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):

  1. User-specific policy (if assigned and within effective dates)
  2. Role-based policy (if user has an active role with assigned policy)
  3. 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

CheckViolation If
PriceflightPrice > maxPricePerPerson (considering duration tiers)
Cabin ClassselectedClass NOT IN allowedCabinClasses (considering duration tiers)
StopsflightStops > maxStops
Advance BookingdaysUntilDeparture < advanceBookingDays

Hotel Violations

CheckViolation If
PricepricePerNight > maxPricePerNight
Star RatinghotelStars NOT IN allowedStarRatings
NightsstayNights > maxNights
Advance BookingdaysUntilCheckIn < advanceBookingDays

Evaluation Order

Rules are sorted by budget threshold (descending) and evaluated in order:

  1. Highest budget rule checked first
  2. If violations found → stop, use this rule's action
  3. If no violations → check next rule
  4. All rules pass → ALLOW

Step 4: Action Determination

The final action is determined by:

Possible Actions

ActionResult
ALLOWBooking proceeds normally
WARN_AND_ALLOWWarning shown, booking allowed
REQUIRE_APPROVALBooking becomes a request
BLOCKBooking 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 1

All 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:

ModeEvaluation ResultOutcome
DIRECT_BOOKINGALLOWDirect booking
DIRECT_BOOKINGREQUIRE_APPROVALSubmit request
DIRECT_BOOKINGBLOCKCannot book
REQUEST_ONLYAnySubmit request
HYBRIDALLOW/WARNDirect booking
HYBRIDREQUIRE_APPROVALSubmit request
HYBRIDBLOCKCannot book

API Endpoint

Policy evaluation is available via API:

POST /api/v1/policies/evaluate

Request 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"
  }
}

On this page