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 classification agent. Your operational boundary is strictly limited to categorizing incoming complaint descriptions into an exact predefined taxonomy and assessing their priority based on severity indicators.

intent: >
[FILL IN: What does a correct output look like — make it verifiable]
Accurately classify each complaint with an exact category, assign a priority level, provide a one-sentence justification citing the description, and flag ambiguous cases appropriately. The correct output must contain exactly 4 fields: category, priority, reason, and flag.

context: >
[FILL IN: What information is the agent allowed to use? State exclusions explicitly.]
You will process rows from a tabular dataset where each row contains a citizen complaint description. You are only allowed to use the text provided in the complaint description. Do not use outside knowledge to assume severity or categorize complaints; rely solely on explicit statements and keywords in the input.

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]"
- "Category must be exactly one of the following exact strings: Pothole, Flooding, Streetlight, Waste, Noise, Road Damage, Heritage Damage, Heat Hazard, Drain Blockage, Other."
- "Priority must be exactly one of: Urgent, Standard, Low. You MUST classify the priority as Urgent if ANY of the following severity keywords are present in the complaint: injury, child, school, hospital, ambulance, fire, hazard, fell, collapse."
- "Every output must include a 'reason' field that is exactly one sentence long, and it MUST explicitly cite specific words from the original description."
- "The 'flag' field must be either 'NEEDS_REVIEW' or blank. You must set it to 'NEEDS_REVIEW' when the complaint is genuinely ambiguous."
108 changes: 99 additions & 9 deletions uc-0a/classifier.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,120 @@
"""
UC-0A — Complaint Classifier

UC-0A — Complaint Classifier
Starter file. Build this using the RICE → agents.md → skills.md → CRAFT workflow.
"""
import argparse
import csv
import re

CATEGORIES = [
"Pothole", "Flooding", "Streetlight", "Waste", "Noise",
"Road Damage", "Heritage Damage", "Heat Hazard", "Drain Blockage", "Other"
]
SEVERITY_KEYWORDS = ['injury', 'child', 'school', 'hospital', 'ambulance', 'fire', 'hazard', 'fell', 'collapse']

def classify_complaint(row: dict) -> 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.
"""
raise NotImplementedError("Build this using your AI tool + RICE prompt")
description = row.get('description', '').lower()

# Priority logic
priority = 'Standard'
reason_word = ''
for word in SEVERITY_KEYWORDS:
if re.search(r'\b' + re.escape(word) + r'\b', description):
priority = 'Urgent'
reason_word = word
break

# Category logic mapping
category_mapping = {
'Pothole': ['pothole', 'crater'],
'Drain Blockage': ['drain blocked', 'drain', 'choked'],
'Flooding': ['flood', 'flooded', 'waterlogged'],
'Streetlight': ['streetlight', 'lights out', 'dark'],
'Waste': ['garbage', 'dump', 'waste', 'trash', 'dead animal'],
'Noise': ['music', 'loud', 'noise', 'party'],
'Road Damage': ['cracked', 'sinking', 'manhole', 'tiles broken', 'broken'],
'Heritage Damage': ['heritage monument', 'fort damaged'],
'Heat Hazard': ['heatwave', 'boiling']
}

assigned_category = 'Other'
flag = ''
match_count = 0

for cat, keywords in category_mapping.items():
for kw in keywords:
if kw in description:
assigned_category = cat
match_count += 1
if not reason_word:
reason_word = kw
break

# Ambiguity check
if match_count > 1 or assigned_category == 'Other':
flag = 'NEEDS_REVIEW'
if assigned_category == 'Other':
assigned_category = 'Other'

# Reason fallback
if not reason_word:
reason_word = 'unclear'

reason = f"The description contained the word '{reason_word}'."

return {
'complaint_id': row.get('complaint_id', ''),
'category': assigned_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")
results = []
fieldnames = []

try:
with open(input_path, 'r', encoding='utf-8') as f:
reader = csv.DictReader(f)
# Retain original fields plus the 4 new ones minus complaint_id if it's already there
fieldnames = list(reader.fieldnames)
for f_add in ['category', 'priority', 'reason', 'flag']:
if f_add not in fieldnames:
fieldnames.append(f_add)

for row in reader:
try:
classification_res = classify_complaint(row)
row.update(classification_res)
results.append(row)
except Exception as e:
row['category'] = 'Other'
row['priority'] = 'Low'
row['reason'] = f"Failed to process: {str(e)}"
row['flag'] = 'NEEDS_REVIEW'
results.append(row)

except Exception as e:
print(f"Error opening input file: {e}")
return

try:
with open(output_path, 'w', encoding='utf-8', newline='') as f:
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(results)
except Exception as e:
print(f"Error writing to output file: {e}")

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,The description contained the word 'unclear'.,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,The description contained the word 'unclear'.,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,The description contained the word 'unclear'.,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,The description contained the word 'broken'.,NEEDS_REVIEW
AM-202407,2024-04-25,Ahmedabad,Ward 15 – Chandkheda,"Thaltej, residential park",Broken bench and upturned paving. Child injured last week.,Email,20,Road Damage,Urgent,The description contained the word 'child'.,
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,The description contained the word '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,The description contained the word 'unclear'.,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,The description contained the word '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,The description contained the word '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,Other,Standard,The description contained the word 'unclear'.,NEEDS_REVIEW
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,The description contained the word 'unclear'.,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,Other,Standard,The description contained the word 'unclear'.,NEEDS_REVIEW
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,Other,Standard,The description contained the word 'unclear'.,NEEDS_REVIEW
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,The description contained the word '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,Road Damage,Standard,The description contained the word 'broken'.,
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,The description contained the word '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,The description contained the word 'drain'.,NEEDS_REVIEW
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,The description contained the word '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,The description contained the word 'drain blocked'.,
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,The description contained the word '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,Standard,The description contained the word 'pothole'.,
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,The description contained the word '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,The description contained the word 'garbage'.,
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,The description contained the word 'unclear'.,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,Pothole,Standard,The description contained the word 'crater'.,
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,The description contained the word '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,The description contained the word '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,The description contained the word 'unclear'.,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,The description contained the word 'drain blocked'.,NEEDS_REVIEW
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,The description contained the word 'unclear'.,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,Other,Standard,The description contained the word 'unclear'.,NEEDS_REVIEW
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,Road Damage,Standard,The description contained the word 'broken'.,
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,The description contained the word 'unclear'.,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,The description contained the word '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,The description contained the word '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,The description contained the word '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,The description contained the word '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,The description contained the word '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,The description contained the word 'hospital'.,
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,Other,Standard,The description contained the word 'unclear'.,NEEDS_REVIEW
KM-202426,2024-06-17,Kolkata,Ward 24 – Shyambazar,"Bow Barracks, central Kolkata",Heritage residential building exterior defaced by billboard installation.,Phone Helpline,1,Other,Standard,The description contained the word 'unclear'.,NEEDS_REVIEW
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,Other,Standard,The description contained the word 'unclear'.,NEEDS_REVIEW
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,Other,Standard,The description contained the word 'unclear'.,NEEDS_REVIEW
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,Streetlight,Standard,The description contained the word 'dark'.,
KM-202438,2024-06-22,Kolkata,Ward 25 – Jadavpur,"Esplanade, near Metro",Street vendors using amplifiers illegally in heritage precinct.,Councillor Referral,19,Other,Standard,The description contained the word 'unclear'.,NEEDS_REVIEW
Loading