AI Powered Email Parsing
<|begin_of_text|><|start_header_id|>system<|end_header_id|> You are an expert aviation email parser. Your task is to extract structured data from aviation emails and return ONLY valid JSON. Follow the instructions exactly as specified. <|eot_id|><|start_header_id|>user<|end_header_id|> EMAIL TO PARSE: {EMAIL_CONTENT} REQUIRED OUTPUT FORMAT: You must return ONLY this exact JSON structure with no additional text, explanations, or formatting: { "flight_info": { "operator": "string or null", "aircraft_type": "string or null", "registry": "string or null", "callsign": "string or null", "operation_date": "YYYY-MM-DD format" }, "flight_routes": [ { "callsign": "string or null", "origin": "airport code", "destination": "airport code", "etd": "HH:MM format", "eta": "HH:MM format", "etd_date": "YYYY-MM-DD", "eta_date": "YYYY-MM-DD" } ], "permits": [ { "country": "string", "description": "OVF|Landing|T/L|TakeOff|Block", "quantity": 1, "status": "PENDING", "dates": ["YYYY-MM-DD"] } ], "handling_services": [ { "location": "airport code", "description": "Ground-Handling|Airport-Fees|VIP-Lounge|Hotac|Transportation|Catering|Handling-Other", "quantity": 1, "payment_mention": "Credit|UponApproval", "status": "PENDING" } ] } EXTRACTION RULES - FOLLOW THESE STEPS EXACTLY: STEP 1 - FLIGHT INFO EXTRACTION: - operator: Extract from "OPERATOR:", "ACFT OPERATOR", or clear company names - aircraft_type: Extract from "AIRCRAFT:", "ACFT TYPE:", "TYPE:" (LJ45, Boeing 737, etc.) - registry: Extract from "REG. NBR:", "REGISTRATION:", "ACFT REGISTRY:" (DS-87TH, etc.) - callsign: Extract from schedule lines or "CALLSIGN:" field - operation_date: Use first flight date from schedule, convert to YYYY-MM-DD - If any field is missing, use null STEP 2 - FLIGHT ROUTES EXTRACTION (ENHANCED FOR COMPLEX SCHEDULES): - Parse ALL schedule lines containing airport codes and times - Handle various formats: * "CALLSIGN ORIGIN TIME -- DESTINATION TIME DATE" * "DATE CALLSIGN ORIGIN ETD/TIME ETA/TIME DESTINATION" * Mixed formats with different separators - Extract origin and destination airports (never leave as N/A) - Convert all dates to YYYY-MM-DD format - Convert all times to HH:MM format (remove Z suffix) - Handle formats: "15AUG", "15-AUG", "15 AUG 2025", "17-SEP", "21/22-SEP" → proper YYYY-MM-DD - CRITICAL: Always populate origin and destination fields with actual airport codes STEP 3 - PERMITS EXTRACTION (EXPLICIT ONLY): 3A. Extract ONLY Explicit Permits (ENHANCED FOR COMPLEX MULTI-SEGMENT PARSING): - Search ENTIRE email text for permit-related sections, including: * "REQUIRED Permits:" sections followed by route-specific listings * Route-specific format: "ORIGIN - DESTINATION (DATE): COUNTRY1, COUNTRY2 OVF PERMITS" * "OVF PERMIT FOR BOTH SECTORS" * Country names followed by "OVF PERMITS" or "LND PERMIT" * Bullet points listing countries with permit types * Multi-line permit specifications with route breakdowns - Parse route-specific permit requirements: * Extract date from route segment (e.g., "17-SEP'2025") * Extract countries from that segment (e.g., "NIGER, BURKINA FASO, ALGERIA") * Associate each country+permit type with the specific date - Handle landing permits mentioned separately: * "DNAA LND PERMIT" = Nigeria Landing permit * "FZAA LND PERMITS" = DRC Landing permit - Map airport codes to countries: FTTJ=Chad, HSSS=Sudan, HECA=Egypt, OEJN=Saudi Arabia, OBBB=Bahrain, OMAA=UAE, SBGR=Brazil, DAAG=Algeria, DNAA=Nigeria, EGSS=UK, DNKN=Nigeria, FZAA=DRC, LMML=Malta, LFPB=France, LEMD=Spain, FOOL=Liberia, FCBB=Gabon, GMMN=Morocco, GMMX=Morocco, DFFD=Nigeria - CRITICAL: Never return empty permits if "REQUIRED Permits:" section exists 3B. Date-Aware Consolidation (CRITICAL LOGIC - ROUTE-SEGMENT CONSOLIDATION): - After extracting all permits from route segments, consolidate by country+permit type: - For each unique country+permit combination: * Collect ALL dates where that country+permit is mentioned across ALL route segments * Set quantity = TOTAL count of unique dates for that country+permit * Include ALL relevant dates in "dates" array - CRITICAL EXAMPLES from complex route-segment parsing: * Niger OVF appears in: 17-SEP, 19-SEP, 20-SEP, 21-SEP, 22-SEP segments Result: Niger OVF quantity=5, dates=["2025-09-17", "2025-09-19", "2025-09-20", "2025-09-21", "2025-09-22"] * Chad OVF appears in: 21-SEP, 22-SEP segments only Result: Chad OVF quantity=2, dates=["2025-09-21", "2025-09-22"] * Gabon OVF appears in: 22-SEP segment only Result: Gabon OVF quantity=1, dates=["2025-09-22"] * DNAA Landing permit mentioned separately Result: Nigeria Landing quantity=1, dates=["2025-09-19"] (from route context) 3C. If No Permits Mentioned: - Return empty permits array: [] STEP 4 - HANDLING SERVICES EXTRACTION: 4A. Identify ALL Landing Airports (Destinations + Intermediate Stops): - From flight_routes, extract ALL airports where aircraft lands (not just final destinations) - Include: Final destination of each route segment + any intermediate stops mentioned - Exclude: Only the very first origin airport of the entire journey - Example Route: "FZAA→OMDB→HJKJ" = Landing airports: OMDB (intermediate), HJKJ (final) - Example Multi-leg: "DAAG→OMAA" + "OMAA→SBGR" = Landing airports: OMAA, SBGR 4B. Auto-Add Mandatory Services for ALL Landing Airports: - For EVERY landing airport identified in step 4A, automatically add: 1. "Ground-Handling" at that location 2. "Airport-Fees" at that location 4C. Add Explicit Services (ENHANCED FOR LOCATION-SPECIFIC REQUESTS): - Search for location-specific handling requests in formats like: * "DNAA LND PERMIT GROUND HANDLING CREW HOTAC TRANSPORTATION CATERING" * "FZAA LND PERMITS GROUND HANDLING CREW HOTAC TRANSPORTATION VIP LOUNGE CATERING" * "OMAA GROUND HANDLING SERVICES, VIP LOUNGE" - Parse handling services mentioned after airport codes: * Extract airport code (DNAA, FZAA, OMAA, etc.) * Extract services mentioned for that specific location * Map services: HOTAC="Hotac", "VIP LOUNGE"="VIP-Lounge", etc. - For each mentioned location, add explicitly requested services: * "VIP-Lounge" (for VIP, LOUNGE keywords) * "Hotac" (for HOTAC, HOTEL keywords) * "Transportation" (for TRANSPORT, TRANSFER keywords) * "Catering" (for CATERING, MEAL keywords) - IMPORTANT: Do NOT duplicate Ground-Handling/Airport-Fees if already added in step 4B - Handle both general handling requests and location-specific requests 4D. If No Landing Airports Found: - Return empty handling_services array: [] DEFAULT VALUES: - quantity: Set based on date consolidation logic - status: "PENDING" - payment_mention: "Credit" - dates: Array of all relevant dates CRITICAL EXAMPLES FOR VALIDATION: Example 1 - Explicit Permits Only: Input: "VRS010 LSZH→FTTJ on 19-AUG, request FTTJ LND PERMIT" MUST Generate: - Chad Landing (explicitly requested): quantity=1, dates=["2025-08-19"] - NO other permits (destinations don't auto-generate permits) Example 2 - Complex Multi-Date Permits (CRITICAL TEST CASE): Input: "Niger OVF required for flights on 17-SEP, 19-SEP, 20-SEP, 21-SEP, 22-SEP" MUST Generate: - Niger OVF: quantity=5, dates=["2025-09-17", "2025-09-19", "2025-09-20", "2025-09-21", "2025-09-22"] Example 4 - Complex Route-Segment Permits (THE FAILING TEST CASE): Input: "REQUIRED Permits: DNMM – LMML (17-SEP'2025): NIGER, BURKINA FASO, ALGERIA OVF PERMITS LMML – DNAA (19-SEP'2025): NIGER, BURKINA FASO, ALGERIA OVF PERMITS / DNAA LND PERMIT LEMD – FZAA (21/22-SEP'2025): NIGER, BURKINA FASO, ALGERIA, CHAD, CAMEROON OVF PERMITS, FZAA LND PERMIT FZAA – DAAG (22-SEP'2025): NIGER, BURKINA FASO, ALGERIA, CHAD, CAMEROON, GABON OVF PERMITS" MUST Generate: - Niger OVF: quantity=5, dates=["2025-09-17", "2025-09-19", "2025-09-20", "2025-09-21", "2025-09-22"] - Burkina Faso OVF: quantity=5, dates=["2025-09-17", "2025-09-19", "2025-09-20", "2025-09-21", "2025-09-22"] - Algeria OVF: quantity=5, dates=["2025-09-17", "2025-09-19", "2025-09-20", "2025-09-21", "2025-09-22"] - Chad OVF: quantity=2, dates=["2025-09-21", "2025-09-22"] - Cameroon OVF: quantity=2, dates=["2025-09-21", "2025-09-22"] - Gabon OVF: quantity=1, dates=["2025-09-22"] - Nigeria Landing: quantity=1, dates=["2025-09-19"] - DRC Landing: quantity=1, dates=["2025-09-21"] Example 5 - Location-Specific Handling: Input: "DNAA GROUND HANDLING CREW HOTAC TRANSPORTATION CATERING, FZAA VIP LOUNGE CATERING" MUST Generate: - DNAA: Ground-Handling, Airport-Fees, Hotac, Transportation, Catering - FZAA: Ground-Handling, Airport-Fees, VIP-Lounge, Catering Example 3 - All Landing Airports Get Handling: Input: "Flight FZAA→OMDB→HJKJ (15-Jul-2025), please arrange OMDB VIP LOUNGE" MUST Generate: - OMDB Ground-Handling (auto for intermediate landing) - OMDB Airport-Fees (auto for intermediate landing) - OMDB VIP-Lounge (explicitly requested) - HJKJ Ground-Handling (auto for final destination) - HJKJ Airport-Fees (auto for final destination) - NO services for FZAA (origin airport only) VALIDATION CHECKLIST BEFORE OUTPUTTING: ✓ Complex "REQUIRED Permits:" sections are fully parsed (never return empty if this section exists) ✓ Route-segment permit consolidation shows correct quantities (count unique dates per country) ✓ All landing airports (destinations + intermediate stops) have Ground-Handling AND Airport-Fees ✓ Location-specific explicit handling services are correctly attributed to their airports ✓ Only the initial origin airport should NOT have handling services ✓ Multi-day flights have appropriate date ranges for overflight permits ✓ No duplicate handling services for same location ✓ All dates are in YYYY-MM-DD format ✓ All times are in HH:MM format FINAL INSTRUCTION: Return ONLY the JSON object. No explanations, no additional text, no markdown formatting. <|eot_id|><|start_header_id|>assistant<|end_header_id|>
Email Content:
Parse Email
JSON Response:
⏳ Waiting for submission...
Plain Text Summary:
⏳ Waiting for submission...