hugging2021/json-repair-env
<img src="https://capsule-render.vercel.app/api?type=venom&height=220&text=JSON%20Repair%20Environment&fontSize=52&color=0:0d1117,100:1a1a2e&fontColor=58a6ff&animation=twinkling&stroke=58a6ff&strokeWidth=1&desc=OpenEnv%20%E2%80%A2%20Reinforcement%20Learning%20%E2%80%A2%20LLM%20Reliability&descSize=18&descAlignY=78&descAlign=50" width="100%"/>
<div align="center">
<img src="https://readme-typing-svg.demolab.com?font=JetBrains+Mono&weight=800&size=22&duration=3000&pause=800&color=58A6FF¢er=true&vCenter=true&multiline=false&repeat=true&width=680&lines=%E2%9C%A8+Training+AI+agents+to+fix+broken+JSON...;%F0%9F%94%A7+step()++reset()++state()+%E2%80%94+OpenEnv+Spec;%F0%9F%8F%86+Scaler+%C3%97+HuggingFace+OpenEnv+Hackathon+2025;%F0%9F%A7%A0+Real-world+RL+%E2%80%94+Not+games%2C+not+toys." alt="Typing SVG" />
<br/><br/>
     
<br/>
  
</div>
<div align="center">
๐ก "Every LLM-powered product breaks JSON. This environment trains agents to fix it โ automatically."
</div>
๐ฅ What Is This?
<table> <tr> <td width="50%">
๐จ The Problem
{
"name": "Alice",
"age": "30", โ wrong type
"active": "true", โ wrong type
โ missing field!
} โ trailing comma</td> <td width="50%">
โ The Solution
{
"name": "Alice",
"age": 30,
"active": true,
"role": "user"
}</td> </tr> </table>
This OpenEnv RL environment rewards agents for transforming broken JSON into valid, schema-compliant, semantically correct output. It models a real production problem faced by every team deploying LLMs at scale.
๐ฎ Environment Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ JSON REPAIR ENVIRONMENT โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ ๐ค Agent ๐ OpenEnv Server โ
โ โโโโโโโโโโโ reset() โโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โโโโโโโโโโโโโโโบ โ Initial Observation โ โ
โ โ โ โโโโโโโโโโโโโโโ โ โข broken JSON โ โ
โ โ โ โ โข target schema โ โ
โ โ BRAIN โ step(action) โ โข hint โ โ
โ โ โ โโโโโโโโโโโโโโโบ โโโโโโโโโโโโโโโโโโโโโโโโค โ
โ โ โ โโโโโโโโโโโโโโโ โ Reward + Next Obs โ โ
โ โ โ โ 0.0 โโโโโโโโโโโบ 1.0 โ โ
โ โโโโโโโโโโโ state() โโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๐ฏ Three Tasks โ Easy โ Medium โ Hard
<div align="center">
</div>
Task 1 โ ๐ข Easy: Syntax Fix
# Input (broken)
'{"name": "Alice", "age": 30, "email": "alice@example.com",}'
# โ trailing comma
# Expected output (fixed)
'{"name": "Alice", "age": 30, "email": "alice@example.com"}'Task 2 โ ๐ก Medium: Type Repair
# Input (broken)
'{"user": "Bob", "score": "95", "active": "true"}'
# โ str โ str missing "role" field โ
# Expected output (fixed)
'{"user": "Bob", "score": 95, "active": true, "role": "user"}'Task 3 โ ๐ด Hard: Nested Reconstruction
# Input (broken)
"{product: 'Laptop', price: '999.99', specs: {ram: '16gb', storage: 512}}"
# โ unquoted keys โ wrong type โ missing field โ needs normalization
# Expected output (fixed)
'{"product": "Laptop", "price": 999.99, "specs": {"ram": "16GB", "storage": 512}, "available": true}'๐ Reward Function โ Partial Progress Signals
Reward = f(syntax, schema, semantics)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
Valid JSON syntax โ +0.40 โ
โ โ
Schema compliance โ +0.40 โ
โ โ
Exact semantic match โ +0.20 โ
โ โโโโโโโ โ
โ ๐
Maximum per task = 1.00 โ
โ โ
โ ๐ก Partial credit awarded for partially โ
โ correct fixes โ not binary pass/fail โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๐ Baseline Performance
<div align="center">
</div>
๐ข Easy โโโโโโโโโโโโโโโโโโโโโโ 95%
๐ก Medium โโโโโโโโโโโโโโโโโโโโโโ 75%
๐ด Hard โโโโโโโโโโโโโโโโโโโโโโ 55%๐งฉ OpenEnv Spec Compliance
โถ Action Space
class Action(BaseModel):
repaired_json: str # Agent's fixed JSON string
explanation: str # Brief description of changes (optional)๐ Observation Space
class Observation(BaseModel):
broken_json: str # The malformed JSON to repair
target_schema: dict # JSON Schema output must comply with
hint: str # What type of error to look for
task_name: str # Current task identifier
step_number: int # Current step in episode
total_tasks: int # Total tasks in episode๐ API Endpoints
๐ Quick Start
1๏ธโฃ Clone & Run Locally
git clone https://huggingface.co/spaces/preethamjain275/json-repair-env
cd json-repair-env
pip install -r requirements.txt
uvicorn main:app --host 0.0.0.0 --port 78602๏ธโฃ Test the API
# โ
Health check
curl http://localhost:7860/health
# ๐ Reset environment
curl -X POST http://localhost:7860/reset | python -m json.tool
# ๐ค Submit a repair action
curl -X POST http://localhost:7860/step \
-H "Content-Type: application/json" \
-d '{"repaired_json": "{\"name\": \"Alice\", \"age\": 30, \"email\": \"alice@example.com\"}", "explanation": "removed trailing comma"}'3๏ธโฃ Run Baseline Inference
export HF_TOKEN=hf_your_token_here
export API_BASE_URL=https://api-inference.huggingface.co/v1
export MODEL_NAME=mistralai/Mistral-7B-Instruct-v0.3
export ENV_URL=http://localhost:7860
python inference.py
# {"type": "START", "task": "json_repair_all_tasks", ...}
# {"type": "STEP", "step": 1, "reward": 0.95, "done": false, ...}
# {"type": "END", "success": true, "score": 0.75, ...}4๏ธโฃ Docker
docker build -t json-repair-env .
docker run -p 7860:7860 \
-e HF_TOKEN=hf_xxx \
-e API_BASE_URL=https://api-inference.huggingface.co/v1 \
-e MODEL_NAME=mistralai/Mistral-7B-Instruct-v0.3 \
json-repair-env5๏ธโฃ OpenEnv Validate
pip install openenv-core
openenv validate .
# โ openenv.yaml valid
# โ /reset responds correctly
# โ /step responds correctly
# โ /state responds correctly
# โ All checks passed!๐ Project Structure
json-repair-env/
โ
โโโ ๐ main.py โ FastAPI server (OpenEnv endpoints)
โโโ ๐ฏ tasks.py โ Task definitions: easy / medium / hard
โโโ โ๏ธ grader.py โ Deterministic reward & scoring logic
โโโ ๐ค inference.py โ Baseline inference script (REQUIRED)
โโโ ๐ openenv.yaml โ OpenEnv spec metadata
โโโ ๐ฆ requirements.txt โ Python dependencies
โโโ ๐ณ Dockerfile โ Container configuration
โโโ ๐ README.md โ This file๐ Real-World Impact
๐ญ Production LLM Apps โ Self-healing JSON parsing
๐ Function Calling Pipelines โ Reliable structured outputs
๐ Data Extraction Workflows โ Automatic error correction
๐ค Agentic Systems โ Resilient tool-call parsingโ๏ธ Environment Variables
<div align="center">
๐ Built For
<br/>
Scaler ร HuggingFace โ OpenEnv Hackathon 2026
Reviewed by engineers from Meta & HuggingFace ๐ค
<br/>
 
<br/>
โญ Star this repo if it helped you!
</div>
<img src="https://capsule-render.vercel.app/api?type=waving&color=gradient&customColorList=6,11,20&height=100§ion=footer&animation=twinkling" width="100%"/>
