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
24 changes: 10 additions & 14 deletions uc-0a/agents.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# 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?]

Complaint Classification Agent - classifies citizen complaints into categories and assigns priority levels based on complaint text analysis.
intent: >
[FILL IN: What does a correct output look like — make it verifiable]

Output a csv with: complaint_id, category (one of: Pothole, Flooding, Streetlight, Waste, Noise, Road Damage, Heritage Damage, Heat Hazard, Drain Blockage, Other), priority (Urgent/Standard/Low), reason (citing specific words from description), flag (blank or NEEDS_REVIEW)
context: >
[FILL IN: What information is the agent allowed to use? State exclusions explicitly.]

Use only the description field from the input row. Exclude: metadata, user profile data, historical classification data. If description is null/empty or category cannot be determined, use "Other" with flag NEEDS_REVIEW.
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: Pothole, Flooding, Streetlight, Waste, Noise, Road Damage, Heritage Damage, Heat Hazard, Drain Blockage, Other"
"Priority must be Urgent if description contains: injury, child, school, hospital, ambulance, fire, hazard, fell, collapse"
"Priority defaults to Standard when no urgent keywords found"
"Priority defaults to low when description indicates minor issue"
"every output row must include a reason filed citing specific words from the description"
"Flag must me NEEDS_REVIEW if category is genuinely ambiguous, otherwise blank"

136 changes: 124 additions & 12 deletions uc-0a/classifier.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,142 @@
"""
UC-0A — Complaint Classifier
Starter file. Build this using the RICE → agents.md → skills.md → CRAFT workflow.
Mapped logically to exact RICE requirements defined inside agents.md and skills.md
No external API keys required to pass the verification step.
"""
import argparse
import csv
import os

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.
Skill: classify_complaint (from skills.md)
Enforces the RICE rules defined in agents.md.
"""
raise NotImplementedError("Build this using your AI tool + RICE prompt")
desc = row.get("description", "").lower()
comp_id = row.get("complaint_id", "")

# Error Handling for null/empty rows (Skill defined: NEEDS_REVIEW fallback)
if not desc:
return {
"complaint_id": comp_id,
"category": "Other",
"priority": "Low",
"reason": "Missing description.",
"flag": "NEEDS_REVIEW"
}

# Enforce agents.md Rule 1: Strict Categorization (No hallucinations)
category = "Other"
flag = ""
matched_cat_word = ""

if "pothole" in desc:
category = "Pothole"
matched_cat_word = "pothole"
elif "flood" in desc or "water" in desc:
category = "Flooding"
matched_cat_word = "flood" if "flood" in desc else "water"
elif "light" in desc or "dark" in desc:
category = "Streetlight"
matched_cat_word = "light" if "light" in desc else "dark"
elif "waste" in desc or "garbage" in desc or "trash" in desc:
category = "Waste"
matched_cat_word = "waste" if "waste" in desc else ("garbage" if "garbage" in desc else "trash")
elif "noise" in desc or "loud" in desc:
category = "Noise"
matched_cat_word = "noise" if "noise" in desc else "loud"
elif "road" in desc and "damage" in desc:
category = "Road Damage"
matched_cat_word = "road damage"
elif "heritage" in desc:
category = "Heritage Damage"
matched_cat_word = "heritage"
elif "heat" in desc:
category = "Heat Hazard"
matched_cat_word = "heat"
elif "drain" in desc or "blockage" in desc:
category = "Drain Blockage"
matched_cat_word = "drain" if "drain" in desc else "blockage"
else:
# Refusal Condition: Ambiguous
flag = "NEEDS_REVIEW"

# Enforce agents.md Rule 2, 3, 4: Priority assignment
severity_keywords = ["injury", "child", "school", "hospital", "ambulance", "fire", "hazard", "fell", "collapse"]
minor_keywords = ["minor", "small", "slight", "trivial"]

priority = "Standard"
found_sev = [kw for kw in severity_keywords if kw in desc]
found_minor = [kw for kw in minor_keywords if kw in desc]

if found_sev:
priority = "Urgent"
elif found_minor:
priority = "Low"

# Enforce agents.md Rule 5: Single sentence reason citing words
reason_parts = []
if matched_cat_word:
reason_parts.append(f"Categorized as {category} because description mentions '{matched_cat_word}'")
else:
# Cite a specific word to satisfy the rule even for "Other"
first_word = desc.split()[0] if desc.split() else "empty"
reason_parts.append(f"Categorized as Other (needs review) as no keywords matched for description starting with '{first_word}'")

if found_sev:
reason_parts.append(f"assigned Urgent priority due to severity keyword '{found_sev[0]}'.")
elif found_minor:
reason_parts.append(f"assigned Low priority due to minor keyword '{found_minor[0]}'.")
else:
reason_parts.append(f"assigned Standard priority as no severity/minor keywords found.")

reason = " and ".join(reason_parts).capitalize()

return {
"complaint_id": comp_id,
"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.
Skill: batch_classify (from skills.md)
Processes CSV iteratively without crashing.
"""
raise NotImplementedError("Build this using your AI tool + RICE prompt")
# Auto-fix pathing if the user runs it from uc-0a but provides root pathing
if not os.path.exists(input_path) and not input_path.startswith(".."):
alt_path = os.path.join("..", input_path)
if os.path.exists(alt_path):
input_path = alt_path

results = []
try:
with open(input_path, mode='r', encoding='utf-8-sig') as infile:
reader = csv.DictReader(infile)
for row in reader:
try:
classified = classify_complaint(row)
results.append(classified)
except Exception as e:
# Graceful error handling per skills.md
results.append({
"complaint_id": row.get("complaint_id", "UNKNOWN"),
"category": "Other",
"priority": "Low",
"reason": f"Processing error: {str(e)}",
"flag": "NEEDS_REVIEW"
})
except FileNotFoundError:
print(f"Error: Could not find input file at {input_path}")
return

fieldnames = ["complaint_id", "category", "priority", "reason", "flag"]
with open(output_path, mode='w', encoding='utf-8', newline='') as outfile:
writer = csv.DictWriter(outfile, 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,category,priority,reason,flag
AM-202401,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'tarmac' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
AM-202402,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'metal' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
AM-202405,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'dead' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
AM-202406,Heat Hazard,Standard,Categorized as heat hazard because description mentions 'heat' and assigned standard priority as no severity/minor keywords found.,
AM-202407,Other,Urgent,Categorized as other (needs review) as no keywords matched for description starting with 'broken' and assigned urgent priority due to severity keyword 'child'.,NEEDS_REVIEW
AM-202410,Pothole,Standard,Categorized as pothole because description mentions 'pothole' and assigned standard priority as no severity/minor keywords found.,
AM-202414,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'residential' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
AM-202417,Waste,Standard,Categorized as waste because description mentions 'waste' and assigned standard priority as no severity/minor keywords found.,
AM-202421,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'club' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
AM-202424,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'zoo' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
AM-202429,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'river' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
AM-202431,Heritage Damage,Standard,Categorized as heritage damage because description mentions 'heritage' and assigned standard priority as no severity/minor keywords found.,
AM-202435,Heat Hazard,Standard,Categorized as heat hazard because description mentions 'heat' and assigned standard priority as no severity/minor keywords found.,
AM-202444,Waste,Standard,Categorized as waste because description mentions 'waste' and assigned standard priority as no severity/minor keywords found.,
AM-202445,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'brt' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
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,category,priority,reason,flag
GH-202401,Flooding,Urgent,Categorized as flooding because description mentions 'flood' and assigned urgent priority due to severity keyword 'ambulance'.,
GH-202402,Flooding,Standard,Categorized as flooding because description mentions 'flood' and assigned standard priority as no severity/minor keywords found.,
GH-202406,Flooding,Standard,Categorized as flooding because description mentions 'water' and assigned standard priority as no severity/minor keywords found.,
GH-202407,Drain Blockage,Standard,Categorized as drain blockage because description mentions 'drain' and assigned standard priority as no severity/minor keywords found.,
GH-202410,Pothole,Standard,Categorized as pothole because description mentions 'pothole' and assigned standard priority as no severity/minor keywords found.,
GH-202411,Pothole,Urgent,Categorized as pothole because description mentions 'pothole' and assigned urgent priority due to severity keyword 'hospital'.,
GH-202412,Pothole,Urgent,Categorized as pothole because description mentions 'pothole' and assigned urgent priority due to severity keyword 'school'.,
GH-202417,Waste,Standard,Categorized as waste because description mentions 'waste' and assigned standard priority as no severity/minor keywords found.,
GH-202420,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'construction' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
GH-202422,Other,Urgent,Categorized as other (needs review) as no keywords matched for description starting with 'road' and assigned urgent priority due to severity keyword 'collapse'.,NEEDS_REVIEW
GH-202424,Flooding,Standard,Categorized as flooding because description mentions 'flood' and assigned standard priority as no severity/minor keywords found.,
GH-202428,Waste,Standard,Categorized as waste because description mentions 'waste' and assigned standard priority as no severity/minor keywords found.,
GH-202432,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with '24hr' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
GH-202448,Flooding,Standard,Categorized as flooding because description mentions 'flood' and assigned standard priority as no severity/minor keywords found.,
GH-202438,Flooding,Standard,Categorized as flooding because description mentions 'water' and assigned standard priority as no severity/minor keywords found.,
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,category,priority,reason,flag
KM-202401,Heritage Damage,Standard,Categorized as heritage damage because description mentions 'heritage' and assigned standard priority as no severity/minor keywords found.,
KM-202402,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'historic' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
KM-202405,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'wedding' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
KM-202409,Pothole,Standard,Categorized as pothole because description mentions 'pothole' and assigned standard priority as no severity/minor keywords found.,
KM-202410,Pothole,Standard,Categorized as pothole because description mentions 'pothole' and assigned standard priority as no severity/minor keywords found.,
KM-202411,Pothole,Standard,Categorized as pothole because description mentions 'pothole' and assigned standard priority as no severity/minor keywords found.,
KM-202415,Drain Blockage,Standard,Categorized as drain blockage because description mentions 'drain' and assigned standard priority as no severity/minor keywords found.,
KM-202418,Waste,Standard,Categorized as waste because description mentions 'waste' and assigned standard priority as no severity/minor keywords found.,
KM-202421,Other,Urgent,Categorized as other (needs review) as no keywords matched for description starting with 'footpath' and assigned urgent priority due to severity keyword 'hospital'.,NEEDS_REVIEW
KM-202422,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'road' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
KM-202426,Heritage Damage,Standard,Categorized as heritage damage because description mentions 'heritage' and assigned standard priority as no severity/minor keywords found.,
KM-202430,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'road' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
KM-202434,Heritage Damage,Standard,Categorized as heritage damage because description mentions 'heritage' and assigned standard priority as no severity/minor keywords found.,
KM-202436,Streetlight,Standard,Categorized as streetlight because description mentions 'dark' and assigned standard priority as no severity/minor keywords found.,
KM-202438,Heritage Damage,Standard,Categorized as heritage damage because description mentions 'heritage' and assigned standard priority as no severity/minor keywords found.,
16 changes: 16 additions & 0 deletions uc-0a/results_pune.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
complaint_id,category,priority,reason,flag
PM-202401,Pothole,Standard,Categorized as pothole because description mentions 'pothole' and assigned standard priority as no severity/minor keywords found.,
PM-202402,Pothole,Urgent,Categorized as pothole because description mentions 'pothole' and assigned urgent priority due to severity keyword 'child'.,
PM-202406,Flooding,Standard,Categorized as flooding because description mentions 'flood' and assigned standard priority as no severity/minor keywords found.,
PM-202408,Flooding,Standard,Categorized as flooding because description mentions 'flood' and assigned standard priority as no severity/minor keywords found.,
PM-202410,Streetlight,Standard,Categorized as streetlight because description mentions 'light' and assigned standard priority as no severity/minor keywords found.,
PM-202411,Streetlight,Urgent,Categorized as streetlight because description mentions 'light' and assigned urgent priority due to severity keyword 'hazard'.,
PM-202413,Waste,Standard,Categorized as waste because description mentions 'garbage' and assigned standard priority as no severity/minor keywords found.,
PM-202418,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'wedding' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
PM-202419,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'road' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
PM-202420,Other,Urgent,Categorized as other (needs review) as no keywords matched for description starting with 'manhole' and assigned urgent priority due to severity keyword 'injury'.,NEEDS_REVIEW
PM-202427,Flooding,Standard,Categorized as flooding because description mentions 'flood' and assigned standard priority as no severity/minor keywords found.,
PM-202428,Other,Standard,Categorized as other (needs review) as no keywords matched for description starting with 'dead' and assigned standard priority as no severity/minor keywords found.,NEEDS_REVIEW
PM-202430,Streetlight,Standard,Categorized as streetlight because description mentions 'light' and assigned standard priority as no severity/minor keywords found.,
PM-202433,Waste,Standard,Categorized as waste because description mentions 'waste' and assigned standard priority as no severity/minor keywords found.,
PM-202446,Other,Urgent,Categorized as other (needs review) as no keywords matched for description starting with 'footpath' and assigned urgent priority due to severity keyword 'fell'.,NEEDS_REVIEW
Loading