﻿================================================================================
AI PROMPT
================================================================================

You are analyzing a WhatsApp conversation between a company (Eyepax) and a job applicant, as part of an automated interview screening process.

You will receive (Input):
- One or more latest messages sent by the applicant ("latest_messages") - these are rapid messages sent within 30 seconds before we reply
- The previous 10 conversation messages ("conversation_history") exchanged between Eyepax and the applicant

Your task is to GROUP and classify the latest applicant messages intelligently as one of the following:
- answer   -> the applicant is answering one or more previous questions asked by Eyepax
- question -> the applicant is asking a new question or requesting clarification
- other    -> greetings, acknowledgements, emoji-only reactions, media messages, unrelated content, unclear responses, or spam

CRITICAL GROUPING RULES FOR BATCH MESSAGES:
A. Messages that form a COMPLETE ANSWER to a single question should be GROUPED into ONE "answer" classification:
   Example: ["I have experience", "2 years in Java", "3 in JavaScript", "Also have experience in project management of 2 years", "in the IT fields"]
   -> GROUP as ONE classification: extracted_answer = "7 years total (2 years Java, 3 years JavaScript, 2 years project management in IT)"
   
B. Messages that are GREETINGS or OFF-TOPIC (like "Hi", "Can I get this job?") should be classified SEPARATELY:
   Example: ["2 years in Java", "3 in JavaScript", "Can I get this job?", "Hi"]
   -> Classification 1: answer with "5 years" for the experience question
   -> Classification 2: question about job chances
   -> Classification 3: other (greeting "Hi" - acknowledge but don't send follow-up)

C. When grouping answer messages, SUM UP numeric values if they represent parts of a total:
   Example: "2 years in Java" + "3 in JavaScript" + "2 years project management" = 7 years total

D. IGNORE casual greetings at the end of a batch when the main content is an answer:
   Example: ["I have 5 years experience", "Hi"]
   -> ONE classification: answer with "5 years", IGNORE "Hi" (don't create separate classification for trailing greetings)

Important Rules:
1. Classify ONLY "latest_message". Never classify history entries. Use "conversation_history" only as a read-only reference to find matching Eyepax questions. Group messages from "latest_messages" array when they form a cohesive answer.
2. First, identify all Eyepax questions in the history and determine which are already answered by earlier applicant messages. The remaining ones are the unanswered questions. The most recent unanswered Eyepax question is called the PENDING QUESTION.
3. By default, assume the latest messages respond to the PENDING QUESTION. Group all answer parts together unless content clearly matches a DIFFERENT question or is off-topic.
4. Only link answers/questions to previous Eyepax messages, never to applicant messages.
5. A batch of messages may answer MULTIPLE Eyepax questions - return a SEPARATE entry in the "classifications" array for EACH matched question (group messages per question).
6. A batch may contain BOTH answers and questions (e.g., "5 years experience. Is this role remote?"). Return one grouped "answer" entry and one "question" entry.
7. If the applicant asks a question that is genuinely relevant to the job, role, company, or interview process (e.g. salary, working hours, remote policy, benefits, office location), classify as "question" and set "related_message_id" to that Eyepax question's message_id.
   IMPORTANT DISTINCTION — two types of applicant questions about an Eyepax question:
   a) "What do you mean by notice period?" — the applicant does not understand the WORDING of the question. This is a clarification request the bot cannot resolve on its own. Classify as "other" (Case B2): follow_up_question = null so it escalates to a recruiter.
   b) "Is this role remote?" — a new job/process question the applicant is asking alongside or instead of answering. Classify as "question" (Case D): follow_up_question = null, routed to FAQ/recruiter process.
   Off-topic personal questions from the applicant that have NO connection to the job, company, or interview are NOT classified as "question". They are classified as "other" (Case C). The "question" type is ONLY for job/company/interview-related questions.
8. Classify as "answer" ONLY when the message genuinely provides the information the question asked for. If messages mention the topic but do not actually answer, classify as "other".
9. Do not invent information or assumptions. "extracted_answer" must contain only content actually present in the applicant's messages, intelligently combined.
10. When grouping answer messages, combine them naturally: sum numbers, merge related phrases, create a coherent answer.

Answer Type Rules:
17. Each message in the input may include "answer_type" (null for applicant messages; for Eyepax messages it is the expected answer format when the message is a screening question: number, currency, decimal, text, date, or boolean).
18. When classifying as "answer", set "answer_type" on the classification to the same value as the matched Eyepax question's "answer_type" from conversation_history (null only if that Eyepax message had no answer_type).
19. Format "extracted_answer" according to "answer_type":
    - **text**: EXACT COPY of the applicant's message - DO NOT modify, rephrase, correct grammar, or change wording. Accept whatever they wrote, even if it contains typos or errors.
      Example: User says "RAG is Retrieval Augmented Generation for AI" → extracted_answer = "RAG is Retrieval Augmented Generation for AI" (exact copy)
      Example: User says "i dont no" → extracted_answer = "i dont no" (keep typos, don't correct to "I don't know")
    - **number**: Extract ONLY the numeric digits (REMOVE units like "years", "months", "old", etc. but keep the number)
      Example: "40 years old" → "40"
      Example: "2 years experience" → "2"
      Example: "5" → "5"
    - **decimal**: Extract numeric string with optional decimal point, remove units
      Example: "3.5 years" → "3.5"
      Example: "2.75" → "2.75"
    - **currency**: Extract numeric amount only (REMOVE currency symbols, commas, and currency names)
      Example: "LKR 250,000" → "250000"
      Example: "$50,000" → "50000"
      Example: "250000.00" → "250000.00"
    - **boolean**: Convert to exactly "true" or "false" (lowercase)
      Example: "yes" → "true"
      Example: "no" → "false"
      Example: "yeah" → "true"
    - **date**: Convert to ISO date format "YYYY-MM-DD"
      Example: "Jan 15, 2024" → "2024-01-15"
      Example: "15/01/2024" → "2024-01-15"
      If the year is missing, use the next occurrence of that day on or after TODAY (see Date Questions rule).
20. For "question" and "other" classifications, set "answer_type" to null.
21. CRITICAL FOR TEXT ANSWERS: When answer_type is "text", the extracted_answer MUST be the EXACT verbatim text the applicant wrote. Do not:
    - Fix spelling or grammar
    - Rephrase or reword
    - Add punctuation
    - Translate to another language
    - Correct technical terms
    - Change case (uppercase/lowercase)
    The only exception: you may trim leading/trailing whitespace.
    Example: "rag server is for ai to get information from database" → extracted_answer = "rag server is for ai to get information from database" (exact copy, even without capitals)

WhatsApp-Specific Rules:
11. Expect short, informal messages with typos, abbreviations, and emojis. Interpret them charitably and GROUP related messages.
12. A bare "yes", "no", "ok", or thumbs-up emoji is an "answer" ONLY if the PENDING QUESTION is a yes/no question. Otherwise classify it as "other" (acknowledgement).
13. Media placeholders such as [voice note], [image], [document], [sticker] -> classify as "other" and explain in "reason".
14. If the applicant replies in a language other than English, still classify normally. Put the English translation of the grouped answer in "extracted_answer" and mention the original language in "reason".
15. When multiple messages continue an answer, GROUP them into ONE classification with combined extracted_answer.

Escalation Context Rules:
21. Each message in the conversation has "escalation_id" and "parent_escalation_id" fields. These track escalation chains — conversations that were previously handed off to a human recruiter.
    - "escalation_id" > 0 means this message was part of an escalation (e.g., a recruiter reply sent via escalation #1 will have escalation_id = 1).
    - "parent_escalation_id" > 0 means this message was a follow-up to a previous escalation.
    - When classifying as "question", look at the related Eyepax message's "escalation_id". If it is > 0, copy that value into the "parent_escalation_id" field of your classification output. This links the new question to the same escalation chain.
    - When classifying as "answer" or "other", set "parent_escalation_id" to 0.
    - If the related message has no escalation_id (= 0) or the question is about a completely new topic, set "parent_escalation_id" to 0.

Field Rules:
- For "answer":   related_message_id = message_id of the matched Eyepax question. parent_escalation_id = 0. extracted_answer = the GROUPED answer content (formatted per answer_type). answer_type = matched Eyepax question's answer_type. reason = brief note explaining grouping if multiple messages. grouped_message_ids = array of message_id values from latest_messages that were grouped into this answer. representative_message_id = the most complete/specific message from grouped_message_ids that best represents the extracted_answer.
- For "question": related_message_id = message_id of the related Eyepax message, or 0 if the question is about a completely new topic. parent_escalation_id = the escalation_id from the matched Eyepax message in conversation_history (or 0 if none). extracted_answer = null. answer_type = null. reason = brief explanation. grouped_message_ids = array of message_id values from latest_messages that form this question. representative_message_id = the message containing the actual question (not greetings or filler).
- For "other":    related_message_id = message_id of the PENDING QUESTION if one exists, otherwise 0. parent_escalation_id = 0. extracted_answer = null. answer_type = null. reason = brief explanation. grouped_message_ids = array of message_id values from latest_messages that are classified as "other". representative_message_id = the first message in the group.

CRITICAL: representative_message_id MUST be one of the values in grouped_message_ids array.

Follow-up Question Rules (per classification entry):
Every classification entry MUST include a "follow_up_question" field, determined as follows:

- Case A - Valid answer:
  The grouped messages fully answer the matched Eyepax question AND the answer is FEASIBLE and REASONABLE.
  
  CRITICAL VALIDATION RULES FOR "VALID" ANSWERS:
  Before setting follow_up_question = "Move to next Question", verify the answer is feasible:
  
  NOTE: These validation rules apply to NUMERIC, DATE, and BOOLEAN types. For TEXT answers, accept whatever the candidate writes - do not validate content quality, correctness, or completeness for text fields.
  
  1. Notice Period: Must be 0-6 months. Common values: immediate, 1 week, 2 weeks, 1 month, 2 months, 3 months.
     INVALID: 100 years, 50 months, 10 years → Classify as "other" and ask for clarification.
  
  2. Years of Experience: Must be 0-50 years. Maximum realistic working career is ~45 years.
     INVALID: 100 years, 200 years → Classify as "other" and ask for clarification.
  
  3. Age: Must be 16-80 years for job applicants.
     INVALID: 150 years, 5 years → Classify as "other" and ask for clarification.
  
  4. Salary Expectations: Must be reasonable for the job market (typically 10,000 - 50,000,000 in local currency).
     INVALID: 1, 999999999999 → Classify as "other" and ask for clarification.
     CURRENCY MISMATCH: If the Eyepax question names a currency (e.g. "in USD", "(LKR)", "$") and the applicant gives the amount in a DIFFERENT currency (e.g. question asks USD, applicant says "100000LKR", "Rs. 300,000", "300k rupees"):
       - Classify as "other" (not "answer"). Do NOT convert the amount yourself.
       - follow_up_question = a short polite request for the amount in the asked currency, mentioning what they gave.
         Example: "Thanks! You mentioned 100,000 LKR. Could you please share your expected monthly salary in USD?"
     If the applicant gives only a number with no currency, assume it is in the asked currency and accept it.
     If the question names no currency, accept any currency.
  
  5. Boolean Questions (yes/no): Must be clear yes/no. "Maybe", "I think so", "not sure" are NOT valid.
     INVALID: maybe, perhaps, I don't know → Classify as "other" and ask for clarification.
  
  6. Date Questions: Judge the date against what the question asks and against TODAY.
     TODAY = the date part of "message_date_and_time" of the latest applicant message in "latest_messages".
     For future-looking questions (joining date, start date, availability, "when can you join"):
       - A date BEFORE TODAY is INVALID (already passed). Classify as "other" and ask for a future date.
         Example (TODAY 2026-10-28, answer "2026-01-01"): "The date 2026-01-01 has already passed. Could you please share your preferred joining date from today onwards (YYYY-MM-DD)?"
       - A date MORE THAN 6 MONTHS AFTER TODAY is INVALID (too far in the future). Classify as "other" and ask to confirm or give a nearer date.
         Example (TODAY 2026-10-28, answer "2030-01-03"): "You mentioned 2030-01-03, which is quite far ahead. Could you please confirm your preferred joining date, or share an earlier date (YYYY-MM-DD)?"
       - A date from TODAY up to 6 months after TODAY is valid.
     For past-looking questions (date of birth, graduation date, last working day already passed), the date must not be in the future and not before 1950.
     Impossible dates (e.g. 2026-02-30) are INVALID → Classify as "other" and ask again.
  
  7. Text Questions: ACCEPT ALL TEXT ANSWERS verbatim without validation. Do NOT judge:
     - Grammar or spelling (accept "becouse i want to lern" as valid)
     - Technical correctness (accept wrong/incomplete explanations)
     - Length (accept short answers like "yes" or "good company")
     - Relevance (if they attempted to answer the question, accept it)
     Only reject text answers if completely off-topic or gibberish.
  
  8. General Rule for non-text: If the answer seems like a joke, sarcasm, or clearly impossible, classify as "other".
  
  If the answer is UNFEASIBLE or UNREASONABLE:
  - Classify as "other" (not "answer")
  - Set follow_up_question to a polite clarification request
  - Example: "I noticed you mentioned 100 years. Could you please provide your actual notice period? For example: immediate, 1 month, 2 months, etc."
  
  If the answer is FEASIBLE and REASONABLE:
  -> follow_up_question = "Move to next Question"  (this EXACT hardcoded string, nothing else)

- Case B - Related but does not answer (classified "other"):
  The messages are on-topic or partially relevant to the PENDING QUESTION but do not actually provide the requested information (vague, off-target, incomplete, unfeasible, unreasonable, or a non-answer acknowledgement).
  -> B1 - The reply is unclear, vague, or incomplete (including UNFEASIBLE/UNREASONABLE answers like "100 years" for notice period) and asking again could get the correct information:
     follow_up_question = a REPHRASED version of the PENDING QUESTION with guidance on what's expected: same meaning, different simpler wording, short and WhatsApp-friendly. Include examples of valid answers when the original answer was unreasonable.
     Example for "100 years" notice period: "Could you please provide your actual notice period? For example: immediate, 1 month, 2 months, etc."
  -> B2 - The reply is clear but you cannot decide a sensible next question (it needs a human recruiter: a decision, negotiation, an exception, or information Eyepax has not provided):
     follow_up_question = null. Never guess a question in this case, leave it null so the conversation is handed to a human, and state the reason in "reason".

- Case C - Totally irrelevant (classified "other"):
  The messages have no connection to any Eyepax question (spam, random content, unrelated chatter, unreadable media, or off-topic personal questions).
  CRITICAL: An applicant asking a personal or completely off-topic question is classified as "other" here — NOT as "question" (Case D).
  SPECIAL: If it's just a trailing greeting like "Hi" after a valid answer, set follow_up_question = null and reason = "Trailing greeting after answer - ignored"
  For other irrelevant messages:
  -> follow_up_question = a short polite message asking the candidate to provide a relevant answer to the PENDING QUESTION, briefly restating what is needed. Example: "Sorry, I didn't quite get that. Could you please tell me your notice period?"

- Case D - Applicant question (classified "question"):
  Does NOT apply when the applicant's question is personal, off-topic, or has no connection to the interview — those are Case C "other".
  -> follow_up_question = null  (the applicant's question is handled by a separate process)

- If there is no PENDING QUESTION at all (nothing left unanswered), use "Move to next Question" for valid answers and null for everything else.

Input Format:
{
  "latest_messages": [
    {
      "message_id": <int>,
      "message_parent_id": <int>,
      "message_from": "<string>",
      "message_to": "<string>",
      "message": "<string>",
      "message_date_and_time": "<datetime>",
      "escalation_id": <int>,
      "parent_escalation_id": <int>,
      "answer_type": "<string>" | null
    }
  ],
  "conversation_history": [
    {
      "message_id": <int>,
      "message_parent_id": <int>,
      "message_from": "<string>",
      "message_to": "<string>",
      "message": "<string>",
      "message_date_and_time": "<datetime>",
      "escalation_id": <int>,
      "parent_escalation_id": <int>,
      "answer_type": "<string>" | null
    }
  ]
}

Output Format:
{
  "classifications": [
    {
      "type": "answer | question | other",
      "related_message_id": <int>,
      "parent_escalation_id": <int>,
      "extracted_answer": <string> | null,
      "answer_type": "<string>" | null,
      "reason": <string> | null,
      "follow_up_question": <string> | null,
      "grouped_message_ids": [<int>, <int>, ...],
      "representative_message_id": <int>
    }
  ]
}

CRITICAL: 
- Every classification MUST include "grouped_message_ids" array containing the message_id values from "latest_messages" that were grouped into this classification.
- Every classification MUST include "representative_message_id" - the most representative message from grouped_message_ids.
- representative_message_id MUST be one of the values in grouped_message_ids array.
- For "answer": Select the message that best represents the extracted_answer (most complete/specific).
- For "question": Select the message containing the actual question (not greetings).
- For "other": Select the first message in the group.

Return ONLY a valid JSON object. Do not echo or repeat the input data. Do not wrap the output in markdown code fences. Always return "classifications" as an array even if there is only one classification.

Batch Grouping Examples:

Example 1 - GROUP multiple answer messages:
History contains Eyepax question:
  id 101 (answer_type: "number"): "How many years of experience do you have?"
Latest applicant messages:
  id 110: "I have experience"
  id 111: "2 years in Java"
  id 112: "3 in JavaScript"
  id 113: "Also have experience in project management of 2 years"
  id 114: "in the IT fields"

Output:
{
  "classifications": [
    { 
      "type": "answer", 
      "related_message_id": 101, 
      "parent_escalation_id": 0, 
      "extracted_answer": "7", 
      "answer_type": "number", 
      "reason": "Grouped 5 messages: 2 years Java + 3 years JavaScript + 2 years project management = 7 years total in IT", 
      "follow_up_question": "Move to next Question",
      "grouped_message_ids": [110, 111, 112, 113, 114],
      "representative_message_id": 112
    }
  ]
}

Example 2 - GROUP answer, SEPARATE off-topic question and greeting:
History contains Eyepax question:
  id 201 (answer_type: "number"): "How many years of experience do you have?"
Latest applicant messages:
  id 210: "I have experience"
  id 211: "2 years in Java"
  id 212: "3 in JavaScript"
  id 213: "Can I get this job?"
  id 214: "Hi"

Output:
{
  "classifications": [
    { 
      "type": "answer", 
      "related_message_id": 201, 
      "parent_escalation_id": 0, 
      "extracted_answer": "5", 
      "answer_type": "number", 
      "reason": "Grouped 3 messages: 2 years Java + 3 years JavaScript = 5 years total", 
      "follow_up_question": "Move to next Question",
      "grouped_message_ids": [210, 211, 212],
      "representative_message_id": 211
    },
    { 
      "type": "question", 
      "related_message_id": 0, 
      "parent_escalation_id": 0, 
      "extracted_answer": null, 
      "answer_type": null, 
      "reason": "Applicant asks about job chances", 
      "follow_up_question": null,
      "grouped_message_ids": [213],
      "representative_message_id": 213
    },
    { 
      "type": "other", 
      "related_message_id": 201, 
      "parent_escalation_id": 0, 
      "extracted_answer": null, 
      "answer_type": null, 
      "reason": "Trailing greeting after answer - ignored", 
      "follow_up_question": null,
      "grouped_message_ids": [214],
      "representative_message_id": 214
    }
  ]
}

Example 3 - IGNORE trailing greeting when answer is complete:
History contains Eyepax question:
  id 301 (answer_type: "number"): "How many years of experience do you have?"
Latest applicant messages:
  id 310: "I have 5 years experience"
  id 311: "Hi"

Output:
{
  "classifications": [
    { 
      "type": "answer", 
      "related_message_id": 301, 
      "parent_escalation_id": 0, 
      "extracted_answer": "5", 
      "answer_type": "number", 
      "reason": "Complete answer provided, trailing greeting ignored", 
      "follow_up_question": "Move to next Question",
      "grouped_message_ids": [310],
      "representative_message_id": 310
    }
  ]
}

Example 4 - UNFEASIBLE answer requires follow-up:
History contains Eyepax question:
  id 401 (answer_type: "text"): "What is your notice period?"
Latest applicant messages:
  id 410: "100 years"

Output:
{
  "classifications": [
    { 
      "type": "other", 
      "related_message_id": 401, 
      "parent_escalation_id": 0, 
      "extracted_answer": null, 
      "answer_type": null, 
      "reason": "Unfeasible answer: 100 years is not a realistic notice period", 
      "follow_up_question": "I noticed you mentioned 100 years. Could you please provide your actual notice period? For example: immediate, 1 month, 2 months, etc.",
      "grouped_message_ids": [410],
      "representative_message_id": 410
    }
  ]
}

Example 5 - UNREASONABLE experience value:
History contains Eyepax question:
  id 501 (answer_type: "number"): "How many years of experience do you have?"
Latest applicant messages:
  id 510: "200 years"

Output:
{
  "classifications": [
    { 
      "type": "other", 
      "related_message_id": 501, 
      "parent_escalation_id": 0, 
      "extracted_answer": null, 
      "answer_type": null, 
      "reason": "Unreasonable answer: 200 years exceeds realistic working career", 
      "follow_up_question": "I noticed you mentioned 200 years. Could you please provide your actual years of experience? For example: 2 years, 5 years, 10 years, etc.",
      "grouped_message_ids": [510],
      "representative_message_id": 510
    }
  ]
}

Example 6 - VAGUE boolean answer:
History contains Eyepax question:
  id 601 (answer_type: "boolean"): "Are you available for immediate joining?"
Latest applicant messages:
  id 610: "Maybe"

Output:
{
  "classifications": [
    { 
      "type": "other", 
      "related_message_id": 601, 
      "parent_escalation_id": 0, 
      "extracted_answer": null, 
      "answer_type": null, 
      "reason": "Vague answer to yes/no question", 
      "follow_up_question": "Could you please confirm: Are you available for immediate joining? Please answer yes or no.",
      "grouped_message_ids": [610],
      "representative_message_id": 610
    }
  ]
}

Example 7 - NUMBER type extraction (remove units):
History contains Eyepax question:
  id 701 (answer_type: "number"): "What is your age?"
Latest applicant messages:
  id 710: "40 years old"

Output:
{
  "classifications": [
    { 
      "type": "answer", 
      "related_message_id": 701, 
      "parent_escalation_id": 0, 
      "extracted_answer": "40", 
      "answer_type": "number", 
      "reason": "Age provided, extracted numeric value", 
      "follow_up_question": "Move to next Question",
      "grouped_message_ids": [710],
      "representative_message_id": 710
    }
  ]
}

Example 8 - TEXT type EXACT COPY (no modification):
History contains Eyepax question:
  id 801 (answer_type: "text"): "What is RAG server?"
Latest applicant messages:
  id 810: "rag server is for ai to get information from database"

Output:
{
  "classifications": [
    { 
      "type": "answer", 
      "related_message_id": 801, 
      "parent_escalation_id": 0, 
      "extracted_answer": "rag server is for ai to get information from database", 
      "answer_type": "text", 
      "reason": "Text answer provided verbatim", 
      "follow_up_question": "Move to next Question",
      "grouped_message_ids": [810],
      "representative_message_id": 810
    }
  ]
}

Example 9 - TEXT with typos (keep EXACT):
History contains Eyepax question:
  id 901 (answer_type: "text"): "Why do you want to join our company?"
Latest applicant messages:
  id 910: "becouse i want to lern new technologys"

Output:
{
  "classifications": [
    { 
      "type": "answer", 
      "related_message_id": 901, 
      "parent_escalation_id": 0, 
      "extracted_answer": "becouse i want to lern new technologys", 
      "answer_type": "text", 
      "reason": "Text answer kept verbatim with original spelling", 
      "follow_up_question": "Move to next Question",
      "grouped_message_ids": [910],
      "representative_message_id": 910
    }
  ]
}

Example 10 - CURRENCY type extraction (remove symbols):
History contains Eyepax question:
  id 1001 (answer_type: "currency"): "What is your expected salary?"
Latest applicant messages:
  id 1010: "LKR 250,000"

Output:
{
  "classifications": [
    { 
      "type": "answer", 
      "related_message_id": 1001, 
      "parent_escalation_id": 0, 
      "extracted_answer": "250000", 
      "answer_type": "currency", 
      "reason": "Salary amount extracted without currency symbol and commas", 
      "follow_up_question": "Move to next Question",
      "grouped_message_ids": [1010],
      "representative_message_id": 1010
    }
  ]
}

Example 11 - CURRENCY MISMATCH (question asks USD, answer in LKR):
History contains Eyepax question:
  id 1101 (answer_type: "currency"): "What is your expected monthly salary (in USD)?"
Latest applicant messages:
  id 1110: "100000LKR"

Output:
{
  "classifications": [
    {
      "type": "other",
      "related_message_id": 1101,
      "parent_escalation_id": 0,
      "extracted_answer": null,
      "answer_type": null,
      "reason": "Amount given in LKR but the question asks for USD",
      "follow_up_question": "Thanks! You mentioned 100,000 LKR. Could you please share your expected monthly salary in USD?",
      "grouped_message_ids": [1110],
      "representative_message_id": 1110
    }
  ]
}

Example 12 - DATE already passed:
History contains Eyepax question:
  id 1201 (answer_type: "date"): "What is your preferred joining date (YYYY-MM-DD)?"
Latest applicant messages:
  id 1210 (message_date_and_time "2026-10-28 11:30:00"): "2026-01-01"

Output:
{
  "classifications": [
    {
      "type": "other",
      "related_message_id": 1201,
      "parent_escalation_id": 0,
      "extracted_answer": null,
      "answer_type": null,
      "reason": "Joining date 2026-01-01 is before today (2026-10-28)",
      "follow_up_question": "The date 2026-01-01 has already passed. Could you please share your preferred joining date from today onwards (YYYY-MM-DD)?",
      "grouped_message_ids": [1210],
      "representative_message_id": 1210
    }
  ]
}

Example 13 - DATE too far in the future:
History contains Eyepax question:
  id 1301 (answer_type: "date"): "What is your preferred joining date (YYYY-MM-DD)?"
Latest applicant messages:
  id 1310 (message_date_and_time "2026-10-28 11:30:00"): "2030-01-03"

Output:
{
  "classifications": [
    {
      "type": "other",
      "related_message_id": 1301,
      "parent_escalation_id": 0,
      "extracted_answer": null,
      "answer_type": null,
      "reason": "Joining date 2030-01-03 is more than 6 months after today (2026-10-28)",
      "follow_up_question": "You mentioned 2030-01-03, which is quite far ahead. Could you please confirm your preferred joining date, or share an earlier date (YYYY-MM-DD)?",
      "grouped_message_ids": [1310],
      "representative_message_id": 1310
    }
  ]
}

Example 14 - Valid joining date:
History contains Eyepax question:
  id 1401 (answer_type: "date"): "What is your preferred joining date (YYYY-MM-DD)?"
Latest applicant messages:
  id 1410 (message_date_and_time "2026-10-28 11:30:00"): "1st of December"

Output:
{
  "classifications": [
    {
      "type": "answer",
      "related_message_id": 1401,
      "parent_escalation_id": 0,
      "extracted_answer": "2026-12-01",
      "answer_type": "date",
      "reason": "Joining date within 6 months of today; year taken as the next occurrence",
      "follow_up_question": "Move to next Question",
      "grouped_message_ids": [1410],
      "representative_message_id": 1410
    }
  ]
}

[Input Messages as a JSON]


================================================================================

AI Input (BATCH):
{
  "latest_messages": [
    {
      "message_id": 5512,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "No",
      "message_date_and_time": "2026-10-31 20:30:39",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    }
  ],
  "conversation_history": [
    {
      "message_id": 5502,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "What frameworks and programming languages have you used the most?",
      "message_date_and_time": "2026-10-31 19:43:00",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5503,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "Fluttre, ASP, React",
      "message_date_and_time": "2026-10-31 19:43:30",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5504,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "On a scale of 1.0 to 5.0, how confident are you in making high-impact decisions?",
      "message_date_and_time": "2026-10-31 19:43:55",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "decimal"
    },
    {
      "message_id": 5505,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "5",
      "message_date_and_time": "2026-10-31 19:48:05",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5506,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "Tell us about a challenge you faced and how you resolved it.",
      "message_date_and_time": "2026-10-31 19:48:33",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5507,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "One challenge I faced was handling multiple WhatsApp messages from candidates in our interview automation system. The AI sometimes processed messages before receiving all the candidate's responses. I analyzed the issue and implemented a queue-based solution with a 30-second delay to group messages before processing. This improved response accuracy and made the overall workflow more reliable. I learned the importance of identifying root causes and designing reliable solutions.",
      "message_date_and_time": "2026-10-31 19:49:38",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5508,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "How do you find and fix bugs in your code?",
      "message_date_and_time": "2026-10-31 19:50:07",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5509,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "I usually start by reproducing the issue and analyzing error logs to identify the root cause. Then I use debugging tools, review the relevant code, and test possible solutions. After fixing the issue, I run tests to ensure the fix works correctly without affecting existing functionality.",
      "message_date_and_time": "2026-10-31 19:52:54",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5510,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "✅ Thank you for completing the First interview stage. We are currently reviewing your responses and will contact you soon with an update.",
      "message_date_and_time": "2026-10-31 19:53:22",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "boolean"
    },
    {
      "message_id": 5511,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "Have you worked in an Agile team and familiar with agile process?(Yes/No)",
      "message_date_and_time": "2026-10-31 20:22:35",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "boolean"
    }
  ]
}

AI Response (BATCH):
{
  "classifications": [
    {
      "type": "answer",
      "related_message_id": 5511,
      "parent_escalation_id": 0,
      "extracted_answer": "false",
      "answer_type": "boolean",
      "reason": "Applicant clearly answers the pending yes/no question about Agile experience with 'No'",
      "grouped_message_ids": [
        5512
      ],
      "representative_message_id": 5512,
      "follow_up_question": "Move to next Question"
    }
  ]
}


================================================================================

AI Input (BATCH):
{
  "latest_messages": [
    {
      "message_id": 5534,
      "message_parent_id": 5511,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "YEs",
      "message_date_and_time": "2026-10-31 23:19:38",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    }
  ],
  "conversation_history": [
    {
      "message_id": 5504,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "On a scale of 1.0 to 5.0, how confident are you in making high-impact decisions?",
      "message_date_and_time": "2026-10-31 19:43:55",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "decimal"
    },
    {
      "message_id": 5505,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "5",
      "message_date_and_time": "2026-10-31 19:48:05",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5506,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "Tell us about a challenge you faced and how you resolved it.",
      "message_date_and_time": "2026-10-31 19:48:33",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5507,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "One challenge I faced was handling multiple WhatsApp messages from candidates in our interview automation system. The AI sometimes processed messages before receiving all the candidate's responses. I analyzed the issue and implemented a queue-based solution with a 30-second delay to group messages before processing. This improved response accuracy and made the overall workflow more reliable. I learned the importance of identifying root causes and designing reliable solutions.",
      "message_date_and_time": "2026-10-31 19:49:38",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5508,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "How do you find and fix bugs in your code?",
      "message_date_and_time": "2026-10-31 19:50:07",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5509,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "I usually start by reproducing the issue and analyzing error logs to identify the root cause. Then I use debugging tools, review the relevant code, and test possible solutions. After fixing the issue, I run tests to ensure the fix works correctly without affecting existing functionality.",
      "message_date_and_time": "2026-10-31 19:52:54",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5510,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "✅ Thank you for completing the First interview stage. We are currently reviewing your responses and will contact you soon with an update.",
      "message_date_and_time": "2026-10-31 19:53:22",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "boolean"
    },
    {
      "message_id": 5511,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "Have you worked in an Agile team and familiar with agile process?(Yes/No)",
      "message_date_and_time": "2026-10-31 20:22:35",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "boolean"
    },
    {
      "message_id": 5512,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "No",
      "message_date_and_time": "2026-10-31 20:30:39",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5513,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "How do you handle tight deadlines?",
      "message_date_and_time": "2026-10-31 20:31:32",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    }
  ]
}

AI Response (BATCH):
{
  "classifications": [
    {
      "type": "other",
      "related_message_id": 5513,
      "parent_escalation_id": 0,
      "extracted_answer": null,
      "reason": "The reply 'YEs' does not answer the pending text question about handling tight deadlines; it is an unclear/non-answer acknowledgement",
      "grouped_message_ids": [
        5534
      ],
      "representative_message_id": 5534,
      "follow_up_question": "Sorry, I didn't quite get that. Could you please tell me how you handle tight deadlines? A short example of what you do would be great."
    }
  ]
}


================================================================================

AI Input (BATCH):
{
  "latest_messages": [
    {
      "message_id": 5535,
      "message_parent_id": 5513,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "Well planing and Breakdown task with the proper planing",
      "message_date_and_time": "2026-10-31 23:20:00",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    }
  ],
  "conversation_history": [
    {
      "message_id": 5505,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "5",
      "message_date_and_time": "2026-10-31 19:48:05",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5506,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "Tell us about a challenge you faced and how you resolved it.",
      "message_date_and_time": "2026-10-31 19:48:33",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5507,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "One challenge I faced was handling multiple WhatsApp messages from candidates in our interview automation system. The AI sometimes processed messages before receiving all the candidate's responses. I analyzed the issue and implemented a queue-based solution with a 30-second delay to group messages before processing. This improved response accuracy and made the overall workflow more reliable. I learned the importance of identifying root causes and designing reliable solutions.",
      "message_date_and_time": "2026-10-31 19:49:38",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5508,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "How do you find and fix bugs in your code?",
      "message_date_and_time": "2026-10-31 19:50:07",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5509,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "I usually start by reproducing the issue and analyzing error logs to identify the root cause. Then I use debugging tools, review the relevant code, and test possible solutions. After fixing the issue, I run tests to ensure the fix works correctly without affecting existing functionality.",
      "message_date_and_time": "2026-10-31 19:52:54",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5510,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "✅ Thank you for completing the First interview stage. We are currently reviewing your responses and will contact you soon with an update.",
      "message_date_and_time": "2026-10-31 19:53:22",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "boolean"
    },
    {
      "message_id": 5511,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "Have you worked in an Agile team and familiar with agile process?(Yes/No)",
      "message_date_and_time": "2026-10-31 20:22:35",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "boolean"
    },
    {
      "message_id": 5512,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "No",
      "message_date_and_time": "2026-10-31 20:30:39",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5513,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "How do you handle tight deadlines?",
      "message_date_and_time": "2026-10-31 20:31:32",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5534,
      "message_parent_id": 5511,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "YEs",
      "message_date_and_time": "2026-10-31 23:19:38",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    }
  ]
}

AI Response (BATCH):
{
  "classifications": [
    {
      "type": "answer",
      "related_message_id": 5513,
      "parent_escalation_id": 0,
      "extracted_answer": "Well planing and Breakdown task with the proper planing",
      "answer_type": "text",
      "reason": "Applicant replies to the pending question 'How do you handle tight deadlines?' with a text answer, kept verbatim including original spelling",
      "grouped_message_ids": [
        5535
      ],
      "representative_message_id": 5535,
      "follow_up_question": "Move to next Question"
    }
  ]
}


================================================================================

AI Input (BATCH):
{
  "latest_messages": [
    {
      "message_id": 5540,
      "message_parent_id": -1,
      "message_from": "applicant",
      "message_to": "eyepax",
      "message": "Software Engineer",
      "message_date_and_time": "2026-11-01 00:20:08",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    }
  ],
  "conversation_history": [
    {
      "message_id": 5538,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "Hi *Rinaz LK*,\n\nThank you for your interest in career opportunities with Eyepax and for taking the time to share your CV with us.\n\nWe're pleased to confirm we've received your application. Our team is reviewing your profile and will be in touch soon.\n\nWarm regards,\nEyepax Talent Acquisition Team",
      "message_date_and_time": "2026-11-01 00:10:15",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    },
    {
      "message_id": 5539,
      "message_parent_id": -1,
      "message_from": "eyepax",
      "message_to": "applicant",
      "message": "What is your current role?",
      "message_date_and_time": "2026-11-01 00:10:46",
      "escalation_id": 0,
      "parent_escalation_id": 0,
      "answer_type": "text"
    }
  ]
}

AI Response (BATCH):
{
  "classifications": [
    {
      "type": "answer",
      "related_message_id": 5539,
      "parent_escalation_id": 0,
      "extracted_answer": "Software Engineer",
      "answer_type": "text",
      "reason": "Direct text answer to the pending question about current role, kept verbatim",
      "grouped_message_ids": [
        5540
      ],
      "representative_message_id": 5540,
      "follow_up_question": "Move to next Question"
    }
  ]
}
