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
28 changes: 8 additions & 20 deletions uc-0a/agents.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
# agents.md — UC-0A Complaint Classifier
# INSTRUCTIONS:
# 1. Open your AI tool
# 2. Paste the full contents of uc-0a/README.md
# 3. Use this prompt:
# "Read this UC README. Using the R.I.C.E framework, generate an
# agents.md YAML with four fields: role, intent, context, enforcement.
# Enforcement must include every rule listed under
# 'Enforcement Rules Your agents.md Must Include'.
# Output only valid YAML."
# 4. Paste the output below

role: >
[FILL IN]
You are an automated Complaint Classification Agent responsible for processing citizen queries for the City Operations team efficiently. Your operational boundary involves categorizing issues identically without hallucinating parameters and ensuring no critical safety requests slip through prioritization filters.

intent: >
[FILL IN]
A reliable, rigidly structured tabular extraction classifying complaints into a strict taxonomy, aggressively marking critical dangers as Urgent with deterministic boolean logic, and always proving its logic backward towards specific keywords in the user's description.

context: >
[FILL IN]
You operate strictly on isolated complaint description rows. You must not invent or approximate standard practices.

enforcement:
- "[FILL IN: category enum rule]"
- "[FILL IN: severity keyword rule — list the keywords]"
- "[FILL IN: reason field rule]"
- "[FILL IN: ambiguity refusal rule]"
- "[FILL IN: no invented categories rule]"
- "The 'category' parameter must strictly map to exactly one of these allowed values: Pothole, Flooding, Streetlight, Waste, Noise, Road Damage, Heritage Damage, Heat Hazard, Drain Blockage, Other. Do not alter casing or synonyms."
- "The 'priority' parameter MUST be escalated to 'Urgent' immediately if the complaint description contains ANY of the following severity keywords: injury, child, school, hospital, ambulance, fire, hazard, fell, collapse."
- "Every output row must explicitly include a 'reason' field that quotes specific words directly cited from the raw description to mathematically justify the classification."
- "If the underlying category cannot be calculated safely or the complaint is overly ambiguous, you must systematically degrade to outputting 'category: Other' along with the boolean explicit 'flag: NEEDS_REVIEW'."
- "NEVER invent, hallucinate, or generate category names that fall outside the explicitly listed taxonomy."
129 changes: 111 additions & 18 deletions uc-0a/classifier.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,124 @@
"""
UC-0A — Complaint Classifier
classifier.py — Starter file

Build this using your AI coding tool:
1. Share agents.md, skills.md, and uc-0a/README.md
2. Ask the AI to implement this file
3. Run: python3 classifier.py --input ../data/city-test-files/test_pune.csv \
--output results_pune.csv
"""
import argparse
import csv
import sys

ALLOWED_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: complaint_id, category, priority, reason, flag
RICE Encapsulation: Strict taxonomic bounds without hallucination.
Returns identically structured objects.
"""
raise NotImplementedError("Build this using your AI tool + agents.md")
description = row.get("description", "").strip()
desc_lower = description.lower()

output = {
"complaint_id": row.get("complaint_id", "UNKNOWN"),
"category": "Other",
"priority": "Low", # Defaulting to lowest if standard isn't pushed
"reason": "",
"flag": ""
}

# 1. Error Handling Boundary
if len(description) < 15:
output["flag"] = "NEEDS_REVIEW"
output["reason"] = f"Flagged ambiguous logic due to short vague textual input: '{description}'"
return output

# 2. Enforcement: Priority Escalation via Deterministic Keywords (Severity Blindness fix)
urgent_triggers = [kw for kw in SEVERITY_KEYWORDS if kw in desc_lower]
if urgent_triggers:
output["priority"] = "Urgent"
output["reason"] += f"Escalated priority aggressively because the text cited dangers: {', '.join(urgent_triggers)}. "
else:
output["priority"] = "Standard"

# 3. Enforcement: Bounded Schema Generation (Taxonomy Drift & Hallucination fix)
category_assigned = False

# Rigid matching structure preventing string variations
mapping_keywords = {
"pothole": "Pothole",
"flood": "Flooding", "water": "Flooding", "drain": "Drain Blockage",
"light": "Streetlight", "dark": "Streetlight",
"waste": "Waste", "garbage": "Waste", "trash": "Waste",
"noise": "Noise", "loud": "Noise",
"road": "Road Damage", "crack": "Road Damage",
"heritage": "Heritage Damage", "monument": "Heritage Damage",
"heat": "Heat Hazard"
}

for kw, exact_cat in mapping_keywords.items():
if kw in desc_lower:
output["category"] = exact_cat
# Output rule: Force justification citation
output["reason"] += f"Explicitly mapped to category {exact_cat} because raw description contained '{kw}'."
category_assigned = True
break

# 4. Enforcement: Ambiguity requires defensive degradation (False Confidence fix)
if not category_assigned:
output["category"] = "Other"
output["flag"] = "NEEDS_REVIEW"
output["reason"] += "Routed to Other + Review queue due to lacking confident mapped classifier elements."

return output


def batch_classify(input_path: str, output_path: str):
"""Read input CSV, classify each row, write results CSV."""
raise NotImplementedError("Build this using your AI tool + agents.md")
"""
Orchestrates robust queue management without crushing the job on bad inputs.
"""
processed_count = 0
results = []

try:
with open(input_path, mode='r', encoding='utf-8-sig') as f:
reader = csv.DictReader(f)

for idx, row in enumerate(reader, start=1):
# Enforce batch_classify error handling skipping malformed datasets cleanly
if not row or "description" not in row:
print(f"⚠️ [Error Handle] Logger dropping corrupted iteration at row limit #{idx}. Bypassing safely...")
continue

classified = classify_complaint(row)
results.append(classified)
processed_count += 1

except FileNotFoundError:
print(f"Critical Halt: File exactly matching '{input_path}' not situated.")
sys.exit(1)

if not results:
print("Empty extraction buffer.")
sys.exit(0)

# Write cleanly exactly mapping the Dict
fields = ["complaint_id", "category", "priority", "reason", "flag"]
with open(output_path, mode='w', encoding='utf-8', newline='') as f:
writer = csv.DictWriter(f, fieldnames=fields)
writer.writeheader()
writer.writerows(results)

print(f"Classification success: Processed {processed_count} rows firmly inside strict Taxonomy rules.")


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="UC-0A Complaint Classifier")
parser.add_argument("--input", required=True)
parser = argparse.ArgumentParser(description="UC-0A Formal Classifier Endpoint")
parser.add_argument("--input", required=True)
parser.add_argument("--output", required=True)
args = parser.parse_args()

batch_classify(args.input, args.output)
print(f"Done. Results written to {args.output}")
print(f"Done. Extracted to -> {args.output}")
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,Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
AM-202402,Other,Standard,Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
AM-202405,Other,Standard,Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
AM-202406,Heat Hazard,Standard,Explicitly mapped to category Heat Hazard because raw description contained 'heat'.,
AM-202407,Other,Urgent,Escalated priority aggressively because the text cited dangers: child. Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
AM-202410,Pothole,Standard,Explicitly mapped to category Pothole because raw description contained 'pothole'.,
AM-202414,Other,Standard,Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
AM-202417,Waste,Standard,Explicitly mapped to category Waste because raw description contained 'waste'.,
AM-202421,Other,Standard,Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
AM-202424,Road Damage,Standard,Explicitly mapped to category Road Damage because raw description contained 'road'.,
AM-202429,Other,Standard,Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
AM-202431,Road Damage,Standard,Explicitly mapped to category Road Damage because raw description contained 'road'.,
AM-202435,Road Damage,Standard,Explicitly mapped to category Road Damage because raw description contained 'road'.,
AM-202444,Waste,Standard,Explicitly mapped to category Waste because raw description contained 'waste'.,
AM-202445,Other,Standard,Routed to Other + Review queue due to lacking confident mapped classifier elements.,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,Escalated priority aggressively because the text cited dangers: ambulance. Explicitly mapped to category Flooding because raw description contained 'flood'.,
GH-202402,Flooding,Standard,Explicitly mapped to category Flooding because raw description contained 'flood'.,
GH-202406,Flooding,Standard,Explicitly mapped to category Flooding because raw description contained 'water'.,
GH-202407,Drain Blockage,Standard,Explicitly mapped to category Drain Blockage because raw description contained 'drain'.,
GH-202410,Pothole,Standard,Explicitly mapped to category Pothole because raw description contained 'pothole'.,
GH-202411,Pothole,Urgent,Escalated priority aggressively because the text cited dangers: hospital. Explicitly mapped to category Pothole because raw description contained 'pothole'.,
GH-202412,Pothole,Urgent,Escalated priority aggressively because the text cited dangers: school. Explicitly mapped to category Pothole because raw description contained 'pothole'.,
GH-202417,Waste,Standard,Explicitly mapped to category Waste because raw description contained 'waste'.,
GH-202420,Other,Standard,Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
GH-202422,Road Damage,Urgent,Escalated priority aggressively because the text cited dangers: collapse. Explicitly mapped to category Road Damage because raw description contained 'road'.,
GH-202424,Flooding,Standard,Explicitly mapped to category Flooding because raw description contained 'flood'.,
GH-202428,Waste,Standard,Explicitly mapped to category Waste because raw description contained 'waste'.,
GH-202432,Other,Standard,Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
GH-202448,Flooding,Standard,Explicitly mapped to category Flooding because raw description contained 'flood'.,
GH-202438,Flooding,Standard,Explicitly mapped to category Flooding because raw description contained 'water'.,
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,Explicitly mapped to category Heritage Damage because raw description contained 'heritage'.,
KM-202402,Road Damage,Standard,Explicitly mapped to category Road Damage because raw description contained 'road'.,
KM-202405,Other,Standard,Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
KM-202409,Pothole,Standard,Explicitly mapped to category Pothole because raw description contained 'pothole'.,
KM-202410,Pothole,Standard,Explicitly mapped to category Pothole because raw description contained 'pothole'.,
KM-202411,Pothole,Standard,Explicitly mapped to category Pothole because raw description contained 'pothole'.,
KM-202415,Drain Blockage,Standard,Explicitly mapped to category Drain Blockage because raw description contained 'drain'.,
KM-202418,Waste,Standard,Explicitly mapped to category Waste because raw description contained 'waste'.,
KM-202421,Other,Urgent,"Escalated priority aggressively because the text cited dangers: fell, hospital. Routed to Other + Review queue due to lacking confident mapped classifier elements.",NEEDS_REVIEW
KM-202422,Road Damage,Standard,Explicitly mapped to category Road Damage because raw description contained 'road'.,
KM-202426,Heritage Damage,Standard,Explicitly mapped to category Heritage Damage because raw description contained 'heritage'.,
KM-202430,Road Damage,Standard,Explicitly mapped to category Road Damage because raw description contained 'road'.,
KM-202434,Heritage Damage,Standard,Explicitly mapped to category Heritage Damage because raw description contained 'heritage'.,
KM-202436,Streetlight,Standard,Explicitly mapped to category Streetlight because raw description contained 'dark'.,
KM-202438,Heritage Damage,Standard,Explicitly mapped to category Heritage Damage because raw description contained 'heritage'.,
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,Explicitly mapped to category Pothole because raw description contained 'pothole'.,
PM-202402,Pothole,Urgent,"Escalated priority aggressively because the text cited dangers: child, school. Explicitly mapped to category Pothole because raw description contained 'pothole'.",
PM-202406,Flooding,Standard,Explicitly mapped to category Flooding because raw description contained 'flood'.,
PM-202408,Flooding,Standard,Explicitly mapped to category Flooding because raw description contained 'flood'.,
PM-202410,Streetlight,Standard,Explicitly mapped to category Streetlight because raw description contained 'light'.,
PM-202411,Streetlight,Urgent,Escalated priority aggressively because the text cited dangers: hazard. Explicitly mapped to category Streetlight because raw description contained 'light'.,
PM-202413,Waste,Standard,Explicitly mapped to category Waste because raw description contained 'garbage'.,
PM-202418,Other,Standard,Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
PM-202419,Road Damage,Standard,Explicitly mapped to category Road Damage because raw description contained 'road'.,
PM-202420,Other,Urgent,Escalated priority aggressively because the text cited dangers: injury. Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
PM-202427,Flooding,Standard,Explicitly mapped to category Flooding because raw description contained 'flood'.,
PM-202428,Other,Standard,Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
PM-202430,Streetlight,Standard,Explicitly mapped to category Streetlight because raw description contained 'light'.,
PM-202433,Waste,Standard,Explicitly mapped to category Waste because raw description contained 'waste'.,
PM-202446,Other,Urgent,Escalated priority aggressively because the text cited dangers: fell. Routed to Other + Review queue due to lacking confident mapped classifier elements.,NEEDS_REVIEW
19 changes: 8 additions & 11 deletions uc-0a/skills.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# skills.md — UC-0A Complaint Classifier
# INSTRUCTIONS: Same as agents.md — paste README into AI, ask for skills.md YAML

skills:
- name: classify_complaint
description: "[FILL IN]"
input: "[FILL IN]"
output: "[FILL IN]"
error_handling: "[FILL IN]"
description: Processes an individual raw complaint record to securely categorize, prioritize, and flag issues according to strict operational taxonomies.
input: A dictionary representing a single complaint row, specifically utilizing the 'description' and 'location' fields.
output: A dictionary formally mapping exactly four strings—category, priority, reason, and flag.
error_handling: Securely handles short, unparsable, or ambiguous inputs by forcefully degrading to outputting 'Other' for the category while triggering the 'NEEDS_REVIEW' flag, rather than attempting to hallucinate confident classifications.

- name: batch_classify
description: "[FILL IN]"
input: "[FILL IN]"
output: "[FILL IN]"
error_handling: "[FILL IN]"
description: Handles bulk processing of CSV files automatically, routing rows concurrently to the unified classifier without crashing memory buffers.
input: A string referencing the filesystem path to the test CSV file.
output: A string confirming the path to the newly generated and populated results CSV file.
error_handling: Handles malformed columns explicitly by logging the corrupted row id or text locally to standard output and mathematically skipping the row to continue executing the rest of the batch unhindered.
Loading