data-quality-contracts
Skill0 starsChanged 41 days agoMITView on GitHub
Validación declarativa de calidad de datos y contratos de esquemas sobre datasets tabulares (Pandas / DuckDB): aserciones de no-nulidad, unicidad de llaves primarias, rangos numéricos válidos, dominios de valores permitidos (enums), regex patterns y consistencia lógica entre columnas. Genera un reporte estructurado de conformidad (PASS/FAIL) con conteo de violaciones y ejemplos. Úsese antes de exportar datos, alimentar dashboards o entrenar modelos.
In this repository24 other files it gives its agents.
- AGENTS.mdAGENTS.md
- ab-testing-analysisSkill
- api-builderSkill
- audit-logSkill
- cohort-retentionSkill
- csv-profilerSkill
- customer-segmentationSkill
- excel-formulasSkill
- excel-profilerSkill
- feature-engineeringSkill
- insight-synthesisSkill
- ml-modelingSkill
- model-evaluationSkill
- pandas-cleaningSkill
- query-validationSkill
- report-exportSkill
- schema-mapperSkill
- sql-cloud-warehouseSkill
- sql-query-helperSkill
- sql-writeSkill
- statistical-testingSkill
- time-series-patternsSkill
- using-data-analytics-agentsSkill
- viz-patternsSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 40
No hay reglas o expectativas de negocio definidas (pedir las reglas primero).
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Data Quality Contracts
Especializada en la verificación formal de contratos de datos y reglas de integridad sobre datasets procesados. Adopta las mejores prácticas de Analytics Engineering (dbt tests, Great Expectations) sin requerir infraestructura externa: validaciones declarativas, puras y reproducibles sobre DataFrames.
Descripción general
La limpieza ad-hoc (pandas-cleaning) transforma columnas, pero un contrato de calidad
asegura formalmente que los datos transformados cumplen las expectativas del negocio
antes de guardarlos a disco o alimentar modelos/reportes.
Provee:
- Reglas declarativas pre-aprobadas:
is_unique: verificación de llaves primarias o IDs.is_not_null: completitud en columnas obligatorias.in_range: acotación de valores (min <= x <= max).is_in_set: pertenencia a listas válidas de categorías (status IN (...)).matches_regex: formato estándar (emails, RUTs/IDs, códigos postales).custom_condition: aserciones multivariadas (ej.fecha_entrega >= fecha_pedido).
- Reporte estructurado de calidad: tabla de resultados (PASS / FAIL, % de violación, filas afectadas y ejemplos de valores inválidos).
Cuándo usar
- Al finalizar la limpieza en
data-explorer, antes de entregar el archivo. - Antes de que
sql-analystejecute inserciones o persistencia consql-write. - Antes de que
ml-modelerinicie el split y entrenamiento de features. - Cuando el usuario pide "validá si los datos cumplen las reglas de negocio".
No usar cuando:
- El dataset está crudo y todavía no se hizo el perfil inicial (
csv-profilerprimero). - No hay reglas o expectativas de negocio definidas (pedir las reglas primero).
Snippet pre-aprobado (Pandas)
import pandas as pd
import numpy as np
def validate_data_contract(df, rules, raise_on_fail=False):
"""Ejecuta una lista declarativa de reglas de calidad sobre un DataFrame.
rules: lista de dicts con la especificación de cada test.
Ejemplos de regla:
- {"type": "is_unique", "column": "id"}
- {"type": "is_not_null", "column": "email"}
- {"type": "in_range", "column": "age", "min": 0, "max": 120}
- {"type": "is_in_set", "column": "status", "values": ["ACTIVE", "CHURNED"]}
- {"type": "matches_regex", "column": "zip_code", "pattern": r"^\d{5}$"}
- {"type": "custom_condition", "description": "fin >= inicio", "fn": lambda d: d["end_date"] >= d["start_date"]}
Devuelve dict con reporte estructurado y estado global.
"""
total_rows = len(df)
results = []
any_failed = False
for rule in rules:
r_type = rule.get("type")
col = rule.get("column")
desc = rule.get("description", f"{r_type} sobre '{col}'")
failed_mask = pd.Series(False, index=df.index)
if r_type == "is_unique":
failed_mask = df.duplicated(subset=[col], keep=False)
elif r_type == "is_not_null":
failed_mask = df[col].isna() | df[col].isin(["", "nan", "NaN", "null", "NULL"])
elif r_type == "in_range":
min_v = rule.get("min", -np.inf)
max_v = rule.get("max", np.inf)
val_num = pd.to_numeric(df[col], errors="coerce")
failed_mask = (val_num < min_v) | (val_num > max_v) | val_num.isna()
elif r_type == "is_in_set":
allowed = set(rule.get("values", []))
failed_mask = ~df[col].isin(allowed)
elif r_type == "matches_regex":
pat = rule.get("pattern", "")
failed_mask = ~df[col].astype(str).str.match(pat, na=False)
elif r_type == "custom_condition":
condition_series = rule["fn"](df)
failed_mask = ~condition_series
else:
raise ValueError(f"Tipo de regla desconocido: {r_type}")
failed_count = int(failed_mask.sum())
failed_pct = round(failed_count / total_rows * 100.0, 2) if total_rows > 0 else 0.0
passed = failed_count == 0
if not passed:
any_failed = True
examples = df.loc[failed_mask, col].dropna().head(3).tolist() if col and col in df.columns else []
else:
examples = []
results.append({
"rule": desc,
"status": "PASS" if passed else "FAIL",
"failed_count": failed_count,
"failed_pct": failed_pct,
"sample_errors": examples,
})
report_df = pd.DataFrame(results)
if raise_on_fail and any_failed:
failed_rules = report_df[report_df["status"] == "FAIL"]["rule"].tolist()
raise ValueError(f"Contrato de datos violado en {len(failed_rules)} regla(s): {', '.join(failed_rules)}")
return {
"global_status": "FAIL" if any_failed else "PASS",
"total_records": total_rows,
"total_rules": len(rules),
"passed_rules": int((report_df["status"] == "PASS").sum()),
"failed_rules": int((report_df["status"] == "FAIL").sum()),
"report": report_df,
}Formato de salida y reporte Markdown
Cuando el agente ejecute el contrato, debe imprimir la tabla resumen:
| Regla | Estado | Filas Fallidas | % Afectado | Ejemplos de Error |
is_unique sobre 'order_id' | PASS | 0 | 0.0% | — |
is_not_null sobre 'user_id' | PASS | 0 | 0.0% | — |
in_range (0-1000000) sobre 'monto' | FAIL | 3 | 0.03% | [-50.0, -12.5] |
is_in_set sobre 'status' | PASS | 0 | 0.0% | — |
Señales de alerta
- Contrato con 100% PASS pero sin reglas de unicidad: Las llaves duplicadas son la causa #1 de métricas infladas en joins posteriores.
- Validar rangos numéricos sobre strings: Asegurar que las columnas fueron coaccionadas con
coerce_numericantes de chequear rangos. - Sobreescribir datos ante un FAIL: Si el contrato falla, bloquear el pipeline y notificar al usuario en lugar de guardar silenciosamente.
Verificación
- Todas las columnas clave (
primary_key,foreign_key) tienen reglas explícitas. - Ninguna regla falla con errores de tipo de dato no controlado.
- El veredicto global es reportado al usuario antes de persistir la tabla o generar gráficos.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

