CoolFace
Apppublic

suresh9970/data-cleaning-env

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

DataCleaningEnv ๐Ÿงน

An OpenEnv environment where AI agents learn to clean messy CSV data.

![OpenEnv](https://openenv.dev) ![HF Space](https://huggingface.co/spaces)


Environment Description

Real data engineering pipelines constantly encounter messy CSVs โ€” missing values, duplicate rows, wrong data types, inconsistent formats, invalid emails, outlier values. This environment simulates exactly that challenge.

An agent interacts with a pandas DataFrame via structured actions, receiving shaped rewards for every step of progress. The environment provides rich, interpretable observations that tell the agent exactly what issues remain.

Why this fills a real gap: Most RL environments are either games or abstract toy problems. Data cleaning is a genuine, high-value real-world task that every data team faces daily. Training agents on this task directly enables automation of data pipeline quality control.


Action Space

The agent chooses from 8 action types:

Action TypeRequired FieldsDescription
fill_missingcolumn, valueFill NaN values. Value: literal, mean, median, mode, unknown
drop_duplicatesโ€”Remove all duplicate rows
fix_typecolumn, valueCast column type. Value: int, float, bool, str
standardize_formatcolumn, valueNormalize format. Value: phone, email, date_iso
drop_columncolumnRemove a column entirely
rename_columncolumn, valueRename a column to value
filter_rowsvalueKeep rows matching a pandas query string
submitโ€”End episode and trigger grader

Action JSON format

json
{
  "action_type": "fill_missing",
  "column": "quantity",
  "value": "median",
  "params": {}
}

Observation Space

Each step returns an Observation with:

FieldTypeDescription
rowslist[dict]Current dataset rows (all rows)
issueslist[str]List of detected data quality issues
columnslist[str]Column names
step_countintSteps taken in this episode
task_idstrCurrent task identifier
task_descriptionstrNatural language task objective
doneboolWhether the episode is complete

Tasks

๐ŸŸข Task Easy โ€” task_easy

Fill Missing Values

A sales CSV with ~25% missing values spread across customer_name, product, quantity, unit_price, and region. The agent must fill all NaN values with appropriate strategies (text columns โ†’ "Unknown", numeric columns โ†’ median).

  • โ€”Grader: Scores fraction of cells filled correctly (0.0 โ€“ 1.0)
  • โ€”Expected difficulty: ~5โ€“8 steps

๐ŸŸก Task Medium โ€” task_medium

Deduplicate and Fix Types

A customer CSV with: (1) 5 duplicate rows randomly inserted, and (2) columns stored as strings that should be numeric or boolean (age, spend_total, is_premium). Invalid/unparseable values should be dropped.

  • โ€”Grader: 40% deduplication + 30% age type + 30% spend type
  • โ€”Expected difficulty: ~8โ€“12 steps

๐Ÿ”ด Task Hard โ€” task_hard

Full Pipeline Clean

A messy employee dataset requiring a full 6-step cleaning pipeline:

  1. 1.Drop entirely-null and constant-value columns (useless_col, constant_col)
  2. 2.Remove duplicate rows (3 injected)
  3. 3.Fill missing values across all columns
  4. 4.Remove rows with invalid salary (negative values or >500,000)
  5. 5.Fix invalid email addresses (set bad literals to null)
  6. 6.Standardize phone numbers to XXX-XXXX format
  • โ€”Grader: 6 checks, each worth 1/6 of the score
  • โ€”Expected difficulty: ~15โ€“25 steps

Reward Function

EventReward
Base step cost-0.02 per step
Progress (score improvement)+0.5 ร— delta
Score regression-0.3 ร— delta
Useless/failed action-0.05
Episode submittedFull grader score
Max steps reached (30)0.7 ร— grader score

The reward function provides dense, trajectory-wide signal โ€” the agent gets feedback every step, not just at the end.


API Endpoints

EndpointMethodDescription
/GETEnvironment info
/healthGETHealth check
/tasksGETList all tasks
/resetPOSTReset environment
/stepPOSTTake a step (action JSON)
/stateGETCurrent environment state
/gradePOSTScore current state without ending

Setup & Usage

Local Development

bash
# Install dependencies
pip install -r requirements.txt

# Run server
python app.py
# โ†’ http://localhost:7860

# Or with uvicorn directly
uvicorn app:app --host 0.0.0.0 --port 7860 --reload

Docker

bash
docker build -t data-cleaning-env .
docker run -p 7860:7860 data-cleaning-env

Run Inference Baseline

bash
export API_BASE_URL=https://api-inference.huggingface.co/v1
export MODEL_NAME=meta-llama/Llama-3.1-8B-Instruct
export HF_TOKEN=your_hf_token_here

python inference.py

Baseline Scores

Baseline run with gpt-4o-mini (temperature=0):

TaskDifficultyScoreSteps
task_easyEasy0.927
task_mediumMedium0.7411
task_hardHard0.5123
Average0.72

Project Structure

data-cleaning-env/
โ”œโ”€โ”€ app.py                   # FastAPI server
โ”œโ”€โ”€ inference.py             # Baseline LLM agent script
โ”œโ”€โ”€ openenv.yaml             # OpenEnv metadata spec
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ validate.py              # Pre-submission validator
โ”œโ”€โ”€ env/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ environment.py       # DataCleaningEnv (reset/step/state)
โ”‚   โ”œโ”€โ”€ models.py            # Pydantic models: Observation, Action, Reward
โ”‚   โ”œโ”€โ”€ data_generator.py    # Messy dataset generators for each task
โ”‚   โ””โ”€โ”€ issue_detector.py    # Data quality issue scanner
โ””โ”€โ”€ tasks/
    โ”œโ”€โ”€ __init__.py
    โ””โ”€โ”€ task_definitions.py  # Task descriptions + graders

HuggingFace Spaces Deployment

  1. 1.Create a new Space on huggingface.co/spaces
  2. 2.Select Docker as the SDK
  3. 3.Push this repo:
bash
   git init
   git remote add origin https://huggingface.co/spaces/YOUR_USERNAME/data-cleaning-env
   git add .
   git commit -m "Initial commit"
   git push origin main
  1. 1.Set secrets in Space settings: API_BASE_URL, MODEL_NAME, HF_TOKEN

License