A Python pipeline that detects broken data and fixes itself — automatically — using LLM-powered diagnosis via NVIDIA's free-tier API.
The Self-Healing Data Pipeline ingests raw data from various sources (CSV, REST APIs, databases), validates it against defined rules, detects anomalies, and — when issues are found — calls a large language model to diagnose the problem and generate a Python fix on the fly. Fixed data is re-validated before being passed downstream. Every repair attempt is logged for full auditability.
Raw Data → Ingest → Validate → Detect Anomalies → Transform → Output
↓ ↓
[issues] [anomaly]
└──────┬──────┘
↓
LLM Healer (NVIDIA Llama 3.1 70B)
↓
Auto-Fix → Re-Validate → Retry (max 3×)
↓
Quarantine if unresolved
| Layer | Tool |
|---|---|
| Language | Python 3.10+ |
| LLM | meta/llama-3.1-70b-instruct via NVIDIA API |
| LLM Client | openai SDK (NVIDIA-compatible) |
| Data | pandas |
| Validation | Custom rule engine (great_expectations optional) |
| Storage | SQLite / PostgreSQL |
| Logging | loguru |
| Config | PyYAML |
git clone https://github.com/your-username/self-healing-pipeline.git
cd self-healing-pipelinepip install -r requirements.txtSign up for free at build.nvidia.com — no credit card required.
export NVIDIA_API_KEY="your_api_key_here"Or create a .env file:
NVIDIA_API_KEY=your_api_key_here
python pipeline.py --input data/sample.csvself-healing-pipeline/
├── pipeline.py # Main orchestrator — run this
├── ingestion.py # Load from CSV, API, or DB
├── validator.py # Schema + rule-based validation
├── anomaly.py # Statistical & frequency anomaly detection
├── healer.py # LLM diagnosis and fix-code generation
├── logger.py # Audit log writer
├── config.yaml # Validation rules and thresholds
├── data/
│ └── sample.csv # Sample dataset for testing
├── quarantine/ # Batches that could not be auto-healed
├── tests/
│ ├── test_validator.py
│ ├── test_anomaly.py
│ └── test_healer.py
├── requirements.txt
└── README.md
Define your validation schema in config.yaml:
schema:
columns:
age:
type: int
nullable: false
min: 0
max: 120
email:
type: str
nullable: false
regex: "^[\\w.-]+@[\\w.-]+\\.\\w+$"
country:
type: str
allowed_values: [IN, US, UK, DE, FR]
pipeline:
max_heal_retries: 3
quarantine_on_failure: true
confidence_threshold: 0.7 # LLM fixes below this score go to human reviewWhen validation or anomaly detection flags an issue, the healer module:
- Builds a structured prompt with the error report, column metadata, and a sample of bad rows
- Calls Llama 3.1 70B on the NVIDIA API and requests a JSON response containing:
diagnosis— one-sentence explanation of the issuefix_code— a Python functionapply_fix(df)that returns a corrected DataFrameconfidence— a 0–1 score for how certain the model is
- Executes the fix against a copy of the data (original is never mutated until the fix is validated)
- Re-runs validation — if the score improves, the fix is accepted; otherwise it retries with a refined prompt
- Quarantines the batch after 3 failed attempts and sends an alert
# healer.py — simplified
def heal(df, error_report):
response = client.chat.completions.create(
model="meta/llama-3.1-70b-instruct",
messages=[{"role": "user", "content": build_prompt(df, error_report)}],
response_format={"type": "json_object"}
)
result = json.loads(response.choices[0].message.content)
return result # { diagnosis, fix_code, confidence }Every repair attempt is written to a repairs table:
| Column | Description |
|---|---|
timestamp |
When the repair ran |
batch_id |
Unique ID for the data batch |
issue_type |
null_values, type_mismatch, outlier, etc. |
diagnosis |
LLM's explanation |
fix_applied |
The generated Python fix |
confidence |
LLM confidence score |
outcome |
success, failed, quarantined |
- LLM-generated fix code runs against a DataFrame copy only — the original is never touched until the fix passes re-validation
- Fixes with
confidence < threshold(configurable) are flagged for human review rather than auto-applied - All
execcalls are scoped to a restricted namespace — no access to filesystem or network - Quarantined batches are never silently dropped — they are preserved with their full error context
pytest tests/ -v- Streamlit dashboard for pipeline health and repair history
- Kafka integration for streaming / real-time healing
- Human-in-the-loop approval UI for low-confidence fixes
- Domain-specific prompt templates (finance, IoT, e-commerce)
- Slack / email alerting for quarantined batches
MIT License — see LICENSE for details.
- NVIDIA NIM for free-tier LLM API access
- Meta Llama 3.1 for the underlying model
- Inspired by the growing field of self-healing data systems