CoolFace
Apppublic

AmbekarKush/etl-review-env

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

๐Ÿ”ง Pipeline Doctor โ€” AI ETL Debugging Environment

An AI agent acts as a data engineer on-call. It receives broken multi-stage ETL pipelines, diagnoses bugs, and applies targeted fixes โ€” earning rewards proportional to output correctness.

OpenEnv environment | 4 tasks (easy โ†’ expert) | Hybrid pandas + SQLite | 41 tests


๐ŸŒ Environment Overview

Pipeline Doctor simulates a real-world scenario every data team faces: a production ETL pipeline has failed. The AI agent must inspect intermediate data, form hypotheses, and apply precise fixes โ€” exactly like a senior data engineer debugging a failing Airflow DAG.

Why this domain is hard:

  • โ€”Most failures are silent โ€” no exception, just wrong data downstream
  • โ€”Bugs cascade across stages: fixing one reveals the next
  • โ€”Schema drift, type coercion, join key mismatches โ€” all realistic failure modes

๐Ÿงฉ OpenEnv Compliance

ComponentStatus
reset() โ†’ initial observationโœ…
step(action) โ†’ obs, reward, done, infoโœ…
state() โ†’ episode metadataโœ…
Typed Pydantic modelsโœ…
openenv.yamlโœ…
/tasks, /grader, /baseline endpointsโœ…
Dockerfile + HF Spacesโœ…

๐ŸŽฏ Observation Space

FieldTypeDescription
pipeline_stagesList[StageDefinition]All stages with current code
stage_resultsList[StageResult]Runtime status: PASSING / FAILING / SKIPPED
stage_statusesDict[str, str]Quick stage_id โ†’ status lookup
current_scorefloat [0,1]Score from most recent fix
source_schemaDict[str, str]Column โ†’ dtype of raw input
reasoning_traceList[ReasoningTrace]Agent hypothesis + evidence per step
efficiency_indicatorstroptimal / good / slow
fix_historyList[FixAttempt]All prior actions
doneboolEpisode terminated

โšก Action Space

ActionRequiredDescription
submit_fixstage_id, fixed_codeApply corrected code, re-run pipeline, compute reward
inspect_datastage_idRequest sample rows from stage output
add_commentcommentRecord diagnosis โ€” earns up to +0.05 bonus
skipโ€”Abandon episode

Pandas stage: Python block where df = input, assign result SQL stage: SELECT statement where input table = data


๐Ÿ† Reward Function

reward = (row_accuracy ร— 0.50)
       + (stage_pass_rate ร— 0.30 + column_match ร— 0.20) ร— efficiency_multiplier
       + comment_bonus (up to +0.05)
  • โ€”Efficiency multiplier: 1.0 at steps 1-5, decays to 0.85 at step 10
  • โ€”Applies only to structural scores โ€” correct output always scores โ‰ฅ0.99
  • โ€”Partial progress always rewarded: fixing 1 of 2 bugs โ†’ ~0.35 score

๐Ÿ“‹ Tasks

TaskDifficultyStagesBugsBug Type
dtype_cast_failure๐ŸŸข Easy31Comma in numeric string โ†’ NaN
multi_stage_logic_bug๐ŸŸก Medium42Silent case mismatch + wrong join key
schema_drift_silent_loss๐Ÿ”ด Hard53Upstream renamed columns across 5 stages
multi_source_reconciliation๐Ÿ’€ Expert54Wrong dedup + outer join + fillna(999) + SQL rename

๐Ÿ“Š Baseline Scores

TaskDifficultyScore
dtype_cast_failure๐ŸŸข Easy~0.85
multi_stage_logic_bug๐ŸŸก Medium~0.63
schema_drift_silent_loss๐Ÿ”ด Hard~0.38
multi_source_reconciliation๐Ÿ’€ Expert~0.22
Average~0.52

`OPENAI_API_KEY=sk-... OPENAI_MODEL=gpt-4o-mini python baseline/run_baseline.py`


๐ŸŽฎ 2-Minute Demo Walkthrough

bash
# 1. Reset
POST /reset  {"task_id": "dtype_cast_failure"}
# stage cast_revenue=FAILING, others=SKIPPED

# 2. Inspect
POST /step  {"action_type": "inspect_data", "stage_id": "cast_revenue"}
# sample rows show revenue=NaN

# 3. Diagnose
POST /step  {"action_type": "add_comment",
             "comment": "Comma thousands separator breaks pd.to_numeric"}

# 4. Fix
POST /step  {"action_type": "submit_fix", "stage_id": "cast_revenue",
             "fixed_code": "result = df.copy()\nresult['revenue'] = pd.to_numeric(result['revenue'].str.replace(',',''), errors='coerce')\n"}
# reward=1.0, done=True

# 5. Grade
POST /grader  โ†’  {"score": 1.0, "stage_pass_rate": 1.0, "output_row_score": 1.0}

๐Ÿš€ Setup

bash
# Local
pip install -r requirements.txt
uvicorn server.app:app --port 7860 --reload
streamlit run demo/streamlit_app.py   # separate terminal

# Docker (FastAPI + Streamlit)
docker build -t pipeline-doctor .
docker run -p 7860:7860 -p 8501:8501 pipeline-doctor

# API: http://localhost:7860/docs
# UI:  http://localhost:8501

๐Ÿ—‚ Structure

etl-review-env/
โ”œโ”€โ”€ env/             # models.py ยท environment.py ยท pipeline.py
โ”œโ”€โ”€ tasks/           # task_easy ยท task_medium ยท task_hard ยท task_expert
โ”œโ”€โ”€ graders/         # deterministic Jaccard grader
โ”œโ”€โ”€ server/          # FastAPI (7 endpoints)
โ”œโ”€โ”€ demo/            # Streamlit UI
โ”œโ”€โ”€ baseline/        # OpenAI inference script
โ”œโ”€โ”€ tests/           # 41 tests, 0 warnings
โ””โ”€โ”€ docker/          # supervisord (FastAPI + Streamlit)

MIT License