Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions uc-0a/agents.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# agents.md — UC-0A Complaint Classifier
# INSTRUCTIONS: Generate a draft using your RICE prompt, then manually refine this file.
# Delete these comments before committing.

role: >
[FILL IN: Who is this agent? What is its operational boundary?]
You are an expert Citizen Complaint Classifier for a municipal government. Your primary responsibility is to categorize incoming citizen reports, assign appropriate priority levels, and provide a clear justification for each classification based on a strict predefined schema.

intent: >
[FILL IN: What does a correct output look like — make it verifiable]
Ensure every complaint is accurately mapped to the official category list and assigned the correct priority level. A correct output is a data structure (or CSV row) containing exactly four fields: `category`, `priority`, `reason`, and `flag`, where category matches the allowed values exactly and priority honors the severity keyword rules.

context: >
[FILL IN: What information is the agent allowed to use? State exclusions explicitly.]
You are allowed to use the complaint description provided in the input CSV. You must adhere strictly to the provided classification schema and priority rules. You are forbidden from hallucinating new categories or sub-categories. You should not use external knowledge about the city or general complaint types that contradict the provided taxonomy.

enforcement:
- "[FILL IN: Specific testable rule 1 — e.g. Category must be exactly one of: Pothole, Flooding, ...]"
- "[FILL IN: Specific testable rule 2 — e.g. Priority must be Urgent if description contains: injury, child, school, ...]"
- "[FILL IN: Specific testable rule 3 — e.g. Every output row must include a reason field citing specific words from the description]"
- "[FILL IN: Refusal condition — e.g. If category cannot be determined from description alone, output category: Other and flag: NEEDS_REVIEW]"
- "The `category` field must be exactly one of: Pothole, Flooding, Streetlight, Waste, Noise, Road Damage, Heritage Damage, Heat Hazard, Drain Blockage, or Other. No variations or additional labels are permitted."
- "The `priority` field must be set to 'Urgent' if the description contains any of the following keywords: injury, child, school, hospital, ambulance, fire, hazard, fell, or collapse. Otherwise, use Standard or Low."
- "The `reason` field must be a single sentence that explicitly cites specific words or phrases directly from the citizen's complaint description."
- "The `flag` field must be set to 'NEEDS_REVIEW' if the category is genuinely ambiguous or does not clearly fit into the predefined list. Otherwise, it must be left blank."
78 changes: 63 additions & 15 deletions uc-0a/classifier.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,78 @@
"""
UC-0A — Complaint Classifier
Starter file. Build this using the RICE → agents.md → skills.md → CRAFT workflow.
Build this using the RICE → agents.md → skills.md → CRAFT workflow.
"""
import argparse
import csv
import os

def classify_complaint(row: dict) -> dict:
def classify_complaint(description: str) -> dict:
"""
Classify a single complaint row.
Returns: dict with keys: complaint_id, category, priority, reason, flag

TODO: Build this using your AI tool guided by your agents.md and skills.md.
Your RICE enforcement rules must be reflected in this function's behaviour.
Classify a single complaint row based on instructions.
"""
raise NotImplementedError("Build this using your AI tool + RICE prompt")
desc_lower = description.lower()

# Categories and keywords
categories = {
"Pothole": ["pothole"],
"Flooding": ["flood", "waterlogging", "inundation"],
"Streetlight": ["streetlight", "light", "lamp"],
"Waste": ["waste", "garbage", "bin", "trash", "dump", "smell"],
"Noise": ["noise", "loud", "music", "weeknight"],
"Road Damage": ["cracked", "sinking", "road surface"],
"Heritage Damage": ["heritage", "old city"],
"Heat Hazard": ["heat", "sun", "hot"],
"Drain Blockage": ["drain", "sewage", "overflow"],
}

category = "Other"
for cat, keywords in categories.items():
if any(kw in desc_lower for kw in keywords):
category = cat
break

# Priority rules
urgent_keywords = ["injury", "child", "school", "hospital", "ambulance", "fire", "hazard", "fell", "collapse"]
priority = "Urgent" if any(kw in desc_lower for kw in urgent_keywords) else "Standard"

# Needs review flag
flag = "NEEDS_REVIEW" if category == "Other" else ""

# Reason (simple citation)
reason = "Cited keywords detected in description."
if priority == "Urgent":
triggered = [kw for kw in urgent_keywords if kw in desc_lower]
reason = f"Urgent priority assigned due to mentions of: {', '.join(triggered)}."
elif category != "Other":
triggered = [kw for kw in categories[category] if kw in desc_lower]
reason = f"Classified as {category} based on text: '{triggered[0]}'."

return {
"category": category,
"priority": priority,
"reason": reason,
"flag": flag
}

def batch_classify(input_path: str, output_path: str):
"""
Read input CSV, classify each row, write results CSV.

TODO: Build this using your AI tool.
Must: flag nulls, not crash on bad rows, produce output even if some rows fail.
"""
raise NotImplementedError("Build this using your AI tool + RICE prompt")
if not os.path.exists(input_path):
print(f"Error: Input file {input_path} not found.")
return

results = []
with open(input_path, mode='r', encoding='utf-8') as f:
reader = csv.DictReader(f)
fieldnames = reader.fieldnames + ["category", "priority", "reason", "flag"]

for row in reader:
classification = classify_complaint(row["description"])
row.update(classification)
results.append(row)

with open(output_path, mode='w', encoding='utf-8', newline='') as f:
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(results)

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="UC-0A Complaint Classifier")
Expand Down
16 changes: 16 additions & 0 deletions uc-0a/results_ahmedabad.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
complaint_id,date_raised,city,ward,location,description,reported_by,days_open,category,priority,reason,flag
AM-202401,2024-04-24,Ahmedabad,Ward 13 – Sabarmati,Kankaria Lake promenade,Tarmac surface melting at 44°C. Footwear sticking. Park users unsafe.,Email,1,Other,Standard,Cited keywords detected in description.,NEEDS_REVIEW
AM-202402,2024-04-23,Ahmedabad,Ward 12 – Maninagar,"Naroda Industrial Area, main gate",Metal bus shelter reaching dangerous temperatures. Commuters refusing to use.,Citizen Portal,4,Other,Standard,Cited keywords detected in description.,NEEDS_REVIEW
AM-202405,2024-05-08,Ahmedabad,Ward 11 – Vastrapur,"Sabarmati Riverfront, North section",Dead trees with split branches. Fall risk to walkers. 3 trees affected.,WhatsApp Helpline,19,Other,Standard,Cited keywords detected in description.,NEEDS_REVIEW
AM-202406,2024-04-21,Ahmedabad,Ward 15 – Chandkheda,"Chandkheda, Sector 22 park",Irrigation system broken. Grass dying in heatwave conditions.,Phone Helpline,18,Heat Hazard,Standard,Classified as Heat Hazard based on text: 'heat'.,
AM-202407,2024-04-25,Ahmedabad,Ward 15 – Chandkheda,"Thaltej, residential park",Broken bench and upturned paving. Child injured last week.,Email,20,Other,Urgent,Urgent priority assigned due to mentions of: child.,NEEDS_REVIEW
AM-202410,2024-05-02,Ahmedabad,Ward 12 – Maninagar,SG Highway near Prahladnagar,Pothole on main highway causing morning rush lane closure.,Ward Office Walk-in,4,Pothole,Standard,Classified as Pothole based on text: 'pothole'.,
AM-202414,2024-04-20,Ahmedabad,Ward 14 – Odhav,"Jodhpur Village, off SG Highway",Residential colony unlit after 9pm. Wiring theft reported.,Citizen Portal,10,Other,Standard,Cited keywords detected in description.,NEEDS_REVIEW
AM-202417,2024-05-08,Ahmedabad,Ward 13 – Sabarmati,"Manek Chowk, Old City",Night market waste not cleared before morning. Heritage area affected.,Councillor Referral,21,Waste,Standard,Classified as Waste based on text: 'waste'.,
AM-202421,2024-05-03,Ahmedabad,Ward 14 – Odhav,"CG Road, commercial zone",Club music audible at residential buildings at 2am.,Citizen Portal,18,Noise,Standard,Classified as Noise based on text: 'music'.,
AM-202424,2024-05-04,Ahmedabad,Ward 11 – Vastrapur,"Shahibaug, near zoo",Zoo approach road surface bubbling at 45°C. Visitor complaints.,Councillor Referral,19,Road Damage,Standard,Classified as Road Damage based on text: 'road surface'.,
AM-202429,2024-04-24,Ahmedabad,Ward 11 – Vastrapur,Ellis Bridge walking track,River walk surface temperature unbearable. Installed temperature reads 52°C.,Councillor Referral,3,Other,Standard,Cited keywords detected in description.,NEEDS_REVIEW
AM-202431,2024-04-26,Ahmedabad,Ward 14 – Odhav,"Paldi, Ratanpol area",Old city road subsidence near ancient step well. Heritage concern.,Citizen Portal,18,Heritage Damage,Standard,Classified as Heritage Damage based on text: 'heritage'.,
AM-202435,2024-05-07,Ahmedabad,Ward 11 – Vastrapur,"New CG Road, Chandkheda",Black metal road dividers storing heat. Motorists reporting burns on contact.,WhatsApp Helpline,16,Heat Hazard,Standard,Classified as Heat Hazard based on text: 'heat'.,
AM-202444,2024-05-15,Ahmedabad,Ward 12 – Maninagar,"Jivraj Park, commercial area",Restaurant waste bins overflowing on Sunday night. Health risk.,Councillor Referral,20,Waste,Standard,Classified as Waste based on text: 'waste'.,
AM-202445,2024-04-19,Ahmedabad,Ward 13 – Sabarmati,Ranip Bus Rapid Transit stop,BRT shelter roof glass broken. Users exposed to full sun.,Councillor Referral,9,Heat Hazard,Standard,Classified as Heat Hazard based on text: 'sun'.,
16 changes: 16 additions & 0 deletions uc-0a/results_hyderabad.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
complaint_id,date_raised,city,ward,location,description,reported_by,days_open,category,priority,reason,flag
GH-202401,2024-07-01,Hyderabad,Ward 55 – Secunderabad,Tank Bund Road underpass,Underpass flooded after 1hr rain. Ambulance diverted. Lives at risk.,WhatsApp Helpline,13,Flooding,Urgent,Urgent priority assigned due to mentions of: ambulance.,
GH-202402,2024-07-13,Hyderabad,Ward 55 – Secunderabad,Dilsukhnagar Monda Market area,Market area flooded. Traders suffering losses. Drain completely blocked.,Citizen Portal,20,Flooding,Standard,Classified as Flooding based on text: 'flood'.,
GH-202406,2024-07-26,Hyderabad,Ward 54 – Kukatpally,"Mehdipatnam, Rethibowli Road",Main stormwater drain 100% blocked with construction debris.,Phone Helpline,3,Drain Blockage,Standard,Classified as Drain Blockage based on text: 'drain'.,
GH-202407,2024-07-15,Hyderabad,Ward 55 – Secunderabad,"Santoshnagar, Saidabad",Drain blocked and mosquito breeding. Dengue concern.,WhatsApp Helpline,4,Drain Blockage,Standard,Classified as Drain Blockage based on text: 'drain'.,
GH-202410,2024-07-23,Hyderabad,Ward 55 – Secunderabad,"Outer Ring Road service lane, Narsingi",Potholes causing vehicles to slow to 20kmph on fast road.,Councillor Referral,18,Pothole,Standard,Classified as Pothole based on text: 'pothole'.,
GH-202411,2024-07-31,Hyderabad,Ward 55 – Secunderabad,"Tolichowki, Mount Pleasant Road",Pothole swallowed entire motorcycle wheel. Rider hospitalised.,Ward Office Walk-in,17,Pothole,Urgent,Urgent priority assigned due to mentions of: hospital.,
GH-202412,2024-07-24,Hyderabad,Ward 53 – LB Nagar,"Nagole, Ramanthapur Road",School bus struggling to navigate 6 potholes in 200m stretch.,Citizen Portal,4,Pothole,Urgent,Urgent priority assigned due to mentions of: school.,
GH-202417,2024-07-16,Hyderabad,Ward 53 – LB Nagar,"Charminar area, old city",Heritage zone garbage overflow. Tourist photographs showing piles of waste.,WhatsApp Helpline,11,Waste,Standard,Classified as Waste based on text: 'waste'.,
GH-202420,2024-07-10,Hyderabad,Ward 55 – Secunderabad,Hitech City co-working zone,Construction drilling from 5am daily near residential towers.,WhatsApp Helpline,12,Other,Standard,Cited keywords detected in description.,NEEDS_REVIEW
GH-202422,2024-07-31,Hyderabad,Ward 52 – Madhapur,"Attapur, Shaikpet Road",Road collapsed partially. Crater 1m deep near residential gate.,Social Media,1,Other,Urgent,Urgent priority assigned due to mentions of: collapse.,NEEDS_REVIEW
GH-202424,2024-07-19,Hyderabad,Ward 52 – Madhapur,Malkajgiri railway underpass,Underpass floods in light rain. Cars regularly abandoned.,Councillor Referral,5,Flooding,Standard,Classified as Flooding based on text: 'flood'.,
GH-202428,2024-07-24,Hyderabad,Ward 54 – Kukatpally,Tolichowki Friday Market area,Post-market waste not cleared. Area unusable by Sunday morning.,Ward Office Walk-in,8,Waste,Standard,Classified as Waste based on text: 'waste'.,
GH-202432,2024-07-19,Hyderabad,Ward 51 – Jubilee Hills,"Kukatpally, KPHB Phase 7",24hr supermarket delivery trucks idling with engines on.,Citizen Portal,2,Other,Standard,Cited keywords detected in description.,NEEDS_REVIEW
GH-202448,2024-07-22,Hyderabad,Ward 52 – Madhapur,Kondapur main drain,Main drain blocked — entire locality at flooding risk this week.,Councillor Referral,8,Flooding,Standard,Classified as Flooding based on text: 'flood'.,
GH-202438,2024-07-06,Hyderabad,Ward 53 – LB Nagar,Hayathnagar residential colony,Colony surrounded by fields that channel rainwater through main road.,Social Media,11,Other,Standard,Cited keywords detected in description.,NEEDS_REVIEW
16 changes: 16 additions & 0 deletions uc-0a/results_kolkata.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
complaint_id,date_raised,city,ward,location,description,reported_by,days_open,category,priority,reason,flag
KM-202401,2024-06-19,Kolkata,Ward 27 – Salt Lake,"Park Street, Victoria area",Heritage lamp post knocked over by delivery vehicle. Not restored.,Email,17,Streetlight,Standard,Classified as Streetlight based on text: 'lamp'.,
KM-202402,2024-06-07,Kolkata,Ward 25 – Jadavpur,"College Street, Boi Para",Historic tram road cobblestones broken up by cable laying work.,Councillor Referral,16,Other,Standard,Cited keywords detected in description.,NEEDS_REVIEW
KM-202405,2024-06-13,Kolkata,Ward 25 – Jadavpur,"Jorasanko, heritage zone",Wedding band playing near Tagore Museum at 11pm. Festival season ongoing.,Ward Office Walk-in,10,Other,Standard,Cited keywords detected in description.,NEEDS_REVIEW
KM-202409,2024-06-05,Kolkata,Ward 26 – Behala,VIP Road near Dum Dum Airport,Airport access road full of potholes. Diplomatic complaint received.,Councillor Referral,7,Pothole,Standard,Classified as Pothole based on text: 'pothole'.,
KM-202410,2024-06-21,Kolkata,Ward 26 – Behala,EM Bypass near Science City,Pothole causing tyre blowouts. Three incidents this week.,Email,1,Pothole,Standard,Classified as Pothole based on text: 'pothole'.,
KM-202411,2024-06-23,Kolkata,Ward 26 – Behala,"Tollygunge, Sardar Shankar Road",Deep pothole filling with rainwater. Depth invisible. Accident risk.,Councillor Referral,12,Pothole,Standard,Classified as Pothole based on text: 'pothole'.,
KM-202415,2024-06-28,Kolkata,Ward 26 – Behala,"Kasba, off bypass",New residential complex draining directly onto public road.,WhatsApp Helpline,13,Drain Blockage,Standard,Classified as Drain Blockage based on text: 'drain'.,
KM-202418,2024-06-04,Kolkata,Ward 23 – Park Street,"New Market, Lindsay Street",Tourist zone waste overflowing. Foreign visitors photographing piles.,Ward Office Walk-in,15,Waste,Standard,Classified as Waste based on text: 'waste'.,
KM-202421,2024-06-08,Kolkata,Ward 23 – Park Street,Rashbehari Avenue,Footpath broken and sinking. Elderly pedestrian fell. Hospital visit.,Social Media,3,Road Damage,Urgent,"Urgent priority assigned due to mentions of: hospital, fell.",
KM-202422,2024-06-06,Kolkata,Ward 24 – Shyambazar,"Howrah Bridge approach, Kolkata side",Road surface buckled near bridge. Structural concern raised.,Social Media,1,Road Damage,Standard,Classified as Road Damage based on text: 'road surface'.,
KM-202426,2024-06-17,Kolkata,Ward 24 – Shyambazar,"Bow Barracks, central Kolkata",Heritage residential building exterior defaced by billboard installation.,Phone Helpline,1,Heritage Damage,Standard,Classified as Heritage Damage based on text: 'heritage'.,
KM-202430,2024-06-08,Kolkata,Ward 23 – Park Street,"Park Street, restaurant zone",Road subsided near gas pipeline. Gas leak smell reported too.,Social Media,21,Waste,Standard,Classified as Waste based on text: 'smell'.,
KM-202434,2024-06-15,Kolkata,Ward 23 – Park Street,"Marble Palace, Muktaram Babu Street",Street paving removed for utility work — heritage stone not replaced.,Email,14,Heritage Damage,Standard,Classified as Heritage Damage based on text: 'heritage'.,
KM-202436,2024-06-26,Kolkata,Ward 27 – Salt Lake,"New Alipore, residential colony",Entire colony substation tripped. Darkness for 3 nights.,Councillor Referral,17,Other,Standard,Cited keywords detected in description.,NEEDS_REVIEW
KM-202438,2024-06-22,Kolkata,Ward 25 – Jadavpur,"Esplanade, near Metro",Street vendors using amplifiers illegally in heritage precinct.,Councillor Referral,19,Heritage Damage,Standard,Classified as Heritage Damage based on text: 'heritage'.,
Loading