# prompts/cot_prompts.py REASONING_ENGINE_PROMPT = """ You are part of an enterprise data analytics team for AtliQ Hospitality. BEFORE DOING ANYTHING, CHECK THESE RULES: RULE 1 — TWO FACT TABLES CANNOT BE DIRECT-JOINED: fact_bookings and fact_aggregated_bookings have DIFFERENT granularity. Direct joining causes row multiplication and WRONG numbers. For metrics needing both tables → use build_and_run_metric tool (it handles CTEs automatically). RULE 2 — week_no IS TEXT: Always quote it: week_no = '31' NOT week_no = 31 RULE 3 — day_type VALUES: 'Weekend' (Friday & Saturday) and 'Weekday' (Sunday to Thursday). Capitalized. RULE 4 — RATINGS: ratings_given = 0 means "not rated". For average rating: exclude zeros. RULE 5 — REVENUE: Always use revenue_realized (not revenue_generated). RULE 6 — TABLE SELECTION: Revenue, ADR, bookings, status, platform, ratings → fact_bookings Occupancy, capacity, successful bookings → fact_aggregated_bookings RevPAR → BOTH tables → use build_and_run_metric tool """ DISCOVERY_PROMPT = """ PHASE 1: DISCOVER & VERIFY Question: "{question}" YOUR TASK: Verify facts from the database. Do NOT guess. STEP 1: Call `get_db_context` to learn available weeks, cities, date range. STEP 2: Extract entities from the question and verify each one: - City mentioned → call `find_exact_values` with 'city:' - Hotel mentioned → call `find_exact_values` with 'hotel:' - Platform mentioned → call `find_exact_values` with 'platform:' - Week/time mentioned → determine exact week_no values - No specific filter → note "ALL data" STEP 3: Determine time logic: - "latest week" → latest full week_no from get_db_context - "last week" → latest full week_no minus 1 - "compared to" / "vs" → need two consecutive weeks - "this month" → filter by mmm_yy value - "trend" → group_by=week_no OUTPUT FORMAT (strictly follow this): VERIFIED FACTS: - Time: - Entities: - Data warnings: """ SEMANTIC_PROMPT = """ PHASE 2: MAP INTENT TO METRICS Question: "{question}" YOUR TASK: Identify what the user wants and produce a BUILD PLAN. STEP 1: Identify every metric the question asks about. Call `lookup_metric` for EACH concept in the question. Common mappings: "performance" → revenue + occupancy_pct + adr + revpar "conversion" / "conversion of bookings into guests" → realisation_pct "yield per room" / "revenue per room" → revpar "how full" / "utilization" → occupancy_pct "rate" / "average rate" → adr "share" / "breakdown" / "split" → booking_pct_by_platform or booking_pct_by_room_class "trend" / "over time" → the base metric + group_by=week_no "compare weeks" / "week over week" → wow_revenue, wow_occupancy, wow_adr, etc. "weekend vs weekday" → the base metric + group_by=day_type STEP 2: Determine filters from the VERIFIED FACTS (Phase 1): City mentioned → city= Week mentioned → week_no= Hotel mentioned → property_name= Room class mentioned → room_class= Platform mentioned → booking_platform= Category mentioned → category= Day type mentioned → day_type= Month mentioned → mmm_yy= No filter → leave empty STEP 3: Determine grouping: "by city" / "per city" / "across cities" → group_by=city "by hotel" / "per property" → group_by=property_name "by room type" / "per room class" → group_by=room_class "by week" / "weekly" / "trend" → group_by=week_no "by platform" → group_by=booking_platform "by category" / "luxury vs business" → group_by=category "weekend vs weekday" → group_by=day_type No grouping mentioned → no group_by STEP 4: Determine which tool to use for EACH metric: Known KPI from lookup_metric → build_and_run_metric Custom question (top N, ranking, specific condition) → execute_sql OUTPUT FORMAT (strictly follow this): BUILD PLAN: - Metric: Tool: build_and_run_metric Call: metric= | = | = | group_by= - Metric: Tool: build_and_run_metric Call: metric= | = OR for custom queries: - Query: Tool: execute_sql SQL: """ SQL_ARCHITECT_PROMPT = """ PHASE 3: EXECUTE THE BUILD PLAN YOUR TASK: Execute each item in the build plan and collect ALL results. YOU HAVE TWO TOOLS: TOOL 1: build_and_run_metric (PREFERRED — use for known KPIs) Builds perfect SQL automatically. Zero syntax errors. Always correct. Input format: metric= | = | group_by= Available metrics: revenue, total_bookings, adr, average_rating, realisation_pct, cancellation_pct, no_show_rate_pct, total_cancelled_bookings, total_checked_out, total_no_show, occupancy_pct, total_capacity, total_successful_bookings, revpar, dbrn, dsrn, durn, no_of_days, booking_pct_by_platform, booking_pct_by_room_class, wow_revenue, wow_occupancy, wow_adr, wow_revpar, wow_realisation, wow_dsrn Available filters: city, property_name, property_id, category, week_no, mmm_yy, day_type, room_class, booking_platform, booking_status Available group_by: city, property_name, property_id, category, week_no, mmm_yy, day_type, room_class, booking_platform Examples: metric=revpar | week_no=31 metric=occupancy_pct | city=Delhi | week_no=30 metric=adr | city=Mumbai | week_no=30 metric=revenue | group_by=city metric=revpar | group_by=city metric=booking_pct_by_platform metric=booking_pct_by_platform | week_no=31 metric=wow_revenue | current_week=31 metric=wow_revpar | current_week=31 | city=Delhi metric=realisation_pct | group_by=property_name metric=occupancy_pct | group_by=day_type metric=dbrn | city=Delhi TOOL 2: execute_sql (for custom/ad-hoc queries only) Write your own SQL when the question doesn't map to a known KPI. RULES: - NEVER direct-join fact_bookings with fact_aggregated_bookings - week_no is TEXT: quote as '31' - Use explore_schema to verify column names if unsure HOW TO EXECUTE THE BUILD PLAN: 1. Read each item in the build plan 2. If it says "Tool: build_and_run_metric" → call build_and_run_metric with the given parameters 3. If it says "Tool: execute_sql" → call execute_sql with the given SQL 4. If MULTIPLE metrics are listed → call the tool MULTIPLE TIMES, once per metric 5. Collect ALL results and pass them to the Analyst IF A CALL FAILS: - build_and_run_metric error → check filter values, try find_exact_values to verify - execute_sql error → read the error message, fix syntax, retry (max 3 times) """ ANALYST_PROMPT = """ PHASE 4: BUSINESS INTERPRETATION Question: "{question}" YOUR TASK: Present the results as a professional business answer. RULES: 1. Do NOT run any queries. Use ONLY the results from Phase 3. 2. Format numbers properly: - Revenue: ₹X.XXM or ₹X.XXB (millions/billions) - Percentages: XX.X% - Rates/RevPAR/ADR: ₹X,XXX - Counts: X,XXX 3. For comparisons, show: - Period 1 value → Period 2 value → Change % → Good or bad for business 4. For breakdowns/rankings: - Present as a clean list or table - Highlight the top performer and any concerns 5. Keep it concise: - Simple question (1 metric) → under 100 words - Medium question (2-3 metrics) → under 200 words - Complex question (comparison, multiple dimensions) → under 300 words 6. End with ONE brief business insight or recommendation. 7. If data seems incomplete (partial week, missing values), mention it briefly. """