CoolFace
Apppublic

DevKaushal/DataQualityEnv

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

DataQualityEnv ๐Ÿงน

A production-ready OpenEnv RL environment for training AI agents to audit and fix messy datasets.

1. Environment Description & Motivation

Real-world data pipelines are routinely polluted with missing values, duplicate records, wrong data types, statistical outliers, and inconsistent formats. Data teams spend a disproportionate amount of time on these repetitive auditing tasks.

DataQualityEnv turns data cleaning into a structured RL problem:

  • โ€”An agent receives a partially corrupted synthetic dataset.
  • โ€”It inspects the dataset via a rich Observation including per-column statistics and a dataset preview.
  • โ€”It applies structured Actions (fill missing, drop duplicates, fix dtypes, etc.) one at a time.
  • โ€”It receives a reward signal proportional to the overall data quality score it achieves.
  • โ€”The episode ends when the dataset reaches a passing quality threshold, the agent signals done, or it exhausts its step budget.

This framing is directly applicable to AutoML pipelines, data lake governance tools, and ETL automation.


2. Action Space

`action_type`DescriptionKey `params` / `column`
fill_missingFill null values with column mean (numeric) or mode (categorical)column (optional, applies to all cols if omitted)
drop_duplicatesRemove all duplicate rows from the datasetโ€”
fix_dtypeAttempt to cast a column to its correct numeric or datetime typecolumn (optional)
remove_outliersClip values beyond ยฑ3 standard deviations to the clipping boundscolumn (optional)
normalize_formatStandardize date strings to YYYY-MM-DDcolumn (optional)
doneSignal that the agent believes the dataset is clean; ends the episodeโ€”

All actions accept an optional column field and an arbitrary params dict for future extensibility.


3. Observation Space

FieldTypeDescription
dataset_previewlist[dict]First 5 rows of the current dataset as a list of row dicts
column_statsdictPer-column stats: dtype, null_count, duplicate_count, outlier_count
issues_remainingintEstimated total number of data quality issues still present
step_countintNumber of steps taken so far in this episode
task_idstrIdentifier of the active task
task_descriptionstrHuman-readable task objective
available_actionslist[str]List of valid action types the agent may use

4. Task Descriptions

Task IDDifficultyObjectiveMax StepsPassing Score
null_hunterEasyFix all missing values in the employee dataset15> 0.90
full_cleanupMediumRemove duplicates, fix missing values, and correct data types25> 0.85
master_auditHardFix nulls, duplicates, dtypes, outliers, and standardize all date formats to YYYY-MM-DD40> 0.88

Datasets:

  • โ€”null_hunter โ€” 100 rows ร— 5 columns, 10 % nulls
  • โ€”full_cleanup โ€” 200 rows ร— 7 columns, nulls + 15 % duplicates + 2 wrong-dtype columns
  • โ€”master_audit โ€” 300 rows ร— 10 columns, all of the above + 3-sigma outliers + mixed date formats

5. Reward Function

reward = quality_score(df, task_id)            # absolute quality, 0.0โ€“1.0
       โˆ’ 0.05  if quality_delta โ‰ค 0            # penalise no-progress steps
       โˆ’ 0.02  if action is a no-op            # penalise wasted actions

The quality score is a weighted average across four dimensions:

DimensionWeightFormula
Null score0.301 โˆ’ (null_cells / total_cells)
Duplicate score0.251 โˆ’ (duplicate_rows / total_rows)
Dtype score0.25correct_dtype_columns / total_columns
Outlier score0.201 โˆ’ min(outlier_cells / total_cells, 1.0)

The task graders apply task-specific weightings on top of this global score, adding a date-format compliance term for master_audit.

Reward is always clamped to [0.0, 1.0].


6. Setup & Usage

Prerequisites

  • โ€”Docker โ‰ฅ 20 or Python 3.11+

Docker (recommended)

bash
# Build
docker build -t data-quality-env .

# Run server (port 7860)
docker run -p 7860:7860 data-quality-env

Local (without Docker)

bash
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 7860

API Examples

Health check

bash
curl http://localhost:7860/health
# {"status":"ok"}

List tasks

bash
curl http://localhost:7860/tasks

Reset environment

bash
curl -X POST http://localhost:7860/reset \
     -H "Content-Type: application/json" \
     -d '{"task_id": "null_hunter"}'

Take a step

bash
curl -X POST http://localhost:7860/step \
     -H "Content-Type: application/json" \
     -d '{"action_type": "fill_missing", "column": null, "params": {}}'

Inspect current state

bash
curl http://localhost:7860/state

Running inference.py

Set the required environment variables, then:

bash
export API_BASE_URL="http://localhost:7860"   # DataQualityEnv server
export MODEL_NAME="mistralai/Mistral-7B-Instruct-v0.3"
export HF_TOKEN="hf_..."

python inference.py

7. Baseline Scores

These scores represent a rule-based greedy agent that always applies the most impactful action first.

TaskBaseline ScorePassed
null_hunter0.91โœ…
full_cleanup0.86โœ…
master_audit0.82โŒ

8. Environment Variables

VariableRequiredDescription
API_BASE_URLโœ…Full base URL of the DataQualityEnv server (e.g. http://localhost:7860) โ€” also used as the OpenAI-compatible endpoint for the LLM
MODEL_NAMEโœ…HuggingFace Inference API model name (e.g. mistralai/Mistral-7B-Instruct-v0.3)
HF_TOKENโœ…HuggingFace API token for authenticating LLM requests
โš ๏ธ Never hard-code credentials. All secrets must be injected via environment variables.

Project Structure

DataQualityEnv/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ main.py           โ† FastAPI app (port 7860)
โ”‚   โ”œโ”€โ”€ models.py         โ† Pydantic v2 models
โ”‚   โ”œโ”€โ”€ environment.py    โ† Core RL environment logic
โ”‚   โ”œโ”€โ”€ tasks.py          โ† Task definitions and graders
โ”‚   โ””โ”€โ”€ datasets.py       โ† Synthetic dataset generator
โ”œโ”€โ”€ inference.py          โ† LLM agent runner (root level)
โ”œโ”€โ”€ openenv.yaml          โ† OpenEnv manifest
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md

License

MIT