Nihar-776/Hackathon-MetaPytorch
Record Repair — OpenEnv Environment
An OpenEnv-compliant reinforcement learning environment where an LLM agent receives a corrupted JSON employee record and must return a fully corrected version in each step.
Environment Description
The environment generates synthetic employee records using the faker Python library. Each record has exactly 7 fields: name, email, phone, dob, salary, department, and join_date. On each episode reset, one or more fields are corrupted using a configurable set of corruption strategies. The agent receives the corrupted record and must return a corrected version. The environment scores the correction and returns a reward in [0.0, 1.0].
This is a real-world data quality task — corrupted records are a daily reality in ETL pipelines, CRM imports, and database migrations. The environment simulates that problem at the record level.
Action Space
The agent submits a POST body to /step with this JSON schema:
{
"corrected_record": {
"name": "Alice Johnson",
"email": "alice.johnson@example.com",
"phone": "555-123-4567",
"dob": "1990-06-15",
"salary": 87500.0,
"department": "Engineering",
"join_date": "2018-03-01"
},
"confidence": 0.9,
"task_id": "task1_single_typo",
"session_id": "<uuid returned by /reset>"
}Observation Space
Both /reset and /step return this structure:
{
"task_id": "task1_single_typo",
"session_id": "550e8400-e29b-41d4-a716-446655440000",
"step": 1,
"corrupted_record": {
"name": "Alce Johnson",
"email": "alice.johnson@example.com",
"phone": "555-123-4567",
"dob": "1990-06-15",
"salary": 87500.0,
"department": "Engineering",
"join_date": "2018-03-01"
},
"corruption_types_hint": ["typo"],
"num_corrupted_fields": 1,
"fields_still_wrong": 0,
"score_so_far": 0.94,
"max_steps": 5,
"done": true,
"message": "Success! Score: 0.9400"
}Reward Function
reward = 0.6 × exact_accuracy
+ 0.3 × fuzzy_accuracy
+ 0.1 × no_hallucination- exact_accuracy: fraction of corrupted fields the agent fixed exactly (after normalisation: strip, lowercase, remove commas/hyphens/currency suffixes)
- fuzzy_accuracy: average SequenceMatcher ratio across corrupted fields — gives partial credit for near-correct answers like almost-fixed typos
- no_hallucination: fraction of clean (non-corrupted) fields the agent left unchanged — penalises overcorrection
All three components and the final reward are in [0.0, 1.0].
Corruption Types
Tasks
Setup and Running Locally
Prerequisites: Python 3.11+, Docker
Without Docker
git clone https://huggingface.co/spaces/Nihar-776/Hackathon-MetaPytorch
cd Hackathon-MetaPytorch
pip install -r requirements.txt
uvicorn app:app --host 0.0.0.0 --port 7860With Docker
docker build -t record-repair-env .
docker run -p 7860:7860 record-repair-envRun the inference script
In a second terminal after the server is running:
export ENV_BASE_URL=http://localhost:7860
export API_BASE_URL=https://router.huggingface.co/v1
export MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
export HF_TOKEN=hf_your_token_here
python inference.pyQuick API test (no LLM needed)
# Health check
curl http://localhost:7860/
# Start an episode
curl -X POST http://localhost:7860/reset \
-H "Content-Type: application/json" \
-d '{"task_id": "task1_single_typo"}'
# Submit a correction (replace session_id with value from reset response)
curl -X POST http://localhost:7860/step \
-H "Content-Type: application/json" \
-d '{
"corrected_record": {"name":"Alice Johnson","email":"alice@example.com","phone":"555-123-4567","dob":"1990-06-15","salary":87500.0,"department":"Engineering","join_date":"2018-03-01"},
"confidence": 1.0,
"task_id": "task1_single_typo",
"session_id": "<your_session_id>"
}'File Structure
.
├── app.py ← FastAPI server (/reset, /step, /state)
├── models.py ← Pydantic typed models (Action, Observation, State)
├── data_generator.py ← Faker-based employee record generator
├── corruptor.py ← 5 corruption strategies with severity control
├── graders.py ← Reward function (exact + fuzzy + anti-hallucination)
├── inference.py ← LLM agent baseline using OpenAI client
├── tasks.yaml ← Task definitions (easy / medium / hard)
├── openenv.yaml ← OpenEnv specification manifest
├── Dockerfile ← Container build
├── requirements.txt ← Pinned Python dependencies
└── README.md ← This file