Spaces:
Paused

File size: 3,179 Bytes
da7445d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Task definition for Expert tier: Medical Records Quality Assurance."""

TASK_ID = "expert"
TASK_NAME = "Medical Records Quality Assurance"
TASK_DIFFICULTY = "expert"
MAX_STEPS = 35

TASK_DESCRIPTION = """
You are a data quality agent working on a medical records dataset.

The dataset has 300 rows (plus duplicates) and 12 columns:
patient_id, age, gender, diagnosis, blood_glucose, blood_pressure_systolic,
bmi, medication, admission_date, days_admitted, discharge_status, insurance_type.

Your job is to fix these quality issues:
1. blood_glucose column has ~20% missing values — fill with median
2. bmi column has invalid sentinel values of -1.0 — filter those rows out
3. Duplicate patient records exist — remove them
4. medication column has casing variants (Metformin, LISINOPRIL, None, Albuterol)
   — normalize to lowercase
5. discharge_status column has casing variants (Recovered, DECEASED, Transferred)
   — normalize to lowercase
6. Some diabetes patients have blood_glucose=80 (statistically valid but
   medically impossible — diabetic patients must have blood_glucose > 100)

SEMANTIC RULES (cross-column, graded separately):
  diagnosis='diabetes'  -> blood_glucose must be > 100
  diagnosis='healthy'   -> medication must be 'none'
  bmi must be in range [10, 60]

IMPORTANT: The semantic rules contribute 30% of your final score.
Fixing bmi=-1.0 rows and medication casing directly improves semantic score.

You have {max_steps} steps. Call submit() when satisfied.
""".strip()

SYSTEM_PROMPT = """
You are a data cleaning expert. You will receive a dataset description
and must output a single JSON action to clean the data step by step.

Always respond with valid JSON in this exact format:
{
  "action_type": "<action_name>",
  "column": "<column_name_or_null>",
  "parameters": {}
}

Valid action_types: fill_nulls, drop_duplicates, cast_type,
normalize_category, clip_outliers, drop_column, filter_rows,
merge_categories, submit, noop

Key strategy for this task (follow this order EXACTLY):
1. fill_nulls on blood_glucose with strategy median
2. filter_rows to remove invalid bmi — condition: "bmi >= 10 and bmi <= 60"
3. drop_duplicates
4. normalize_category on medication with this EXACT mapping:
   {"Metformin": "metformin", "LISINOPRIL": "lisinopril",
    "None": "none", "Albuterol": "albuterol"}
5. normalize_category on discharge_status with this EXACT mapping:
   {"Recovered": "recovered", "DECEASED": "deceased",
    "Transferred": "transferred"}
6. submit

CRITICAL: For normalize_category you MUST include the mapping in parameters.
The correct JSON for step 4 is:
{
  "action_type": "normalize_category",
  "column": "medication",
  "parameters": {
    "mapping": {
      "Metformin": "metformin",
      "LISINOPRIL": "lisinopril",
      "None": "none",
      "Albuterol": "albuterol"
    }
  }
}

The correct JSON for step 2 is:
{
  "action_type": "filter_rows",
  "column": null,
  "parameters": {
    "condition": "bmi >= 10 and bmi <= 60"
  }
}

Do NOT call normalize_category without the mapping — it will do nothing.
If no more actions needed: {"action_type": "submit", "column": null, "parameters": {}}
""".strip()