Data Cleaning & Validation for AI Agents — Saifs AI
data_cleaningClean and validate a tabular export deterministically, with a change log. Inputs: rows (records, or a list of lists with the header row first; ERP / CRM headers as they are), optional rules ('amount = qty * price', 'due_date >= invoice_date', 'fd(pincode -> city)', 'status in (...)'), job (one of clean_dataset, map_columns, standardise_values, profile_data, infer_patterns, check_digits, validate_rules, fix_typos_units, fix_errors, discover_rules, fill_missing, flag_outliers, relationship_outliers, find_duplicates, compare_loads, quality_score, change_log), target_schema, field_weights, cleaning_profile (from an earlier run), history, confirmed_fixes + reviewed_rows (the user's corrections, to learn from), entity_key / source_field (several sources). Returns decision cards first, an agent-ready score before / after, column mapping, clean rows, the change log (old -> new, step, rule), quarantined rows with candidate fixes, missing-value report with ranges, outliers, Benford test, duplicate groups, check-digit failures, rules found in the data, values that do not fit their row, source reliability, what was learned, drift vs the last load, and an updated cleaning_profile. Never guesses an ambiguous fix; refuses imputation above 40% missing; under 30 rows profiles and validates only. Not for joining tables, looking data up outside the file, or deleting records. Files over 20,000 rows: data_cleaning_get_engine.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "data_cleaning"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| job | No | Which part to run; clean_dataset runs everything. | clean_dataset |
| rows | No | The data: records, or a list of lists with the header row first. Headers and values as exported (Party Name, Inv Amt, ₹1,25,000.00, 12-Jan-2025 ...). | |
| seed | No | ||
| rules | No | Business rules, e.g. 'amount = qty * price', 'due_date >= invoice_date', 'if country = "IN" then not_null(gstin)', 'fd(pincode -> city)', 'unique(invoice_no)', 'status in ("open", "paid")'. Use the standard field names (see column_mapping). | |
| steps | No | Advanced: explicit step list (overrides job). | |
| locale | No | Country for phones and ambiguous dates. | IN |
| headers | No | Headers only (job map_columns without data). | |
| history | No | Earlier clean rows (e.g. last months' invoice lines): usual ranges, and each item's usual quantity / amount, so more unit slips are settled instead of quarantined. | |
| max_log | No | ||
| fix_case | No | ||
| outlier_z | No | ||
| relations | No | Regressions to test, e.g. 'amount ~ qty * price'. | |
| date_order | No | ||
| entity_key | No | Column naming the thing several sources report (e.g. flight); found automatically when omitted. | |
| max_listed | No | ||
| return_rows | No | ||
| source_field | No | Column naming the source / feed / site (found automatically when named like source, src, provider). | |
| abs_tolerance | No | ||
| column_groups | No | Field groups for the multivariate outlier test. | |
| field_weights | No | {field: weight}: higher = more trusted, changed last by repairs. | |
| impute_method | No | auto | |
| rel_tolerance | No | ||
| reviewed_rows | No | Rows the user checked: every value not in confirmed_fixes is correct. | |
| target_schema | No | Your own fields: {field: {type, synonyms: [...]}}. | |
| duplicate_keys | No | Fields that identify a record (else chosen automatically). | |
| fd_min_support | No | ||
| confirmed_fixes | No | The user's corrections: row (0 = first data row), field or header, the correct value. Applied, and used to learn fixes for similar errors. | |
| learn_threshold | No | Probability a learned fix needs before it is applied. | |
| cleaning_profile | No | cleaning_profile from an earlier run (confirmed mapping, rules, baselines for drift). | |
| sensitive_fields | No | Extra personal fields to hide from the profile. | |
| fd_min_confidence | No | ||
| mapping_threshold | No | ||
| max_change_fields | No | ||
| max_rows_returned | No | ||
| check_digit_fields | No | {field: gstin | gtin | luhn | isbn | iban}. | |
| max_missing_impute | No | ||
| duplicate_threshold | No | ||
| log_standardisation | No | ||
| extra_missing_tokens | No | ||
| apply_discovered_rules | No | Also repair with rules found in the data (else only suggested). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| alerts | No | ||
| status | Yes | 1 = processed, 0 = refused (see decisions) | |
| benford | No | ||
| message | No | ||
| profile | No | ||
| sources | No | ||
| learning | No | ||
| metadata | Yes | ||
| outliers | No | ||
| decisions | Yes | Plain-language cards, priority order. Relay these first. | |
| row_flags | No | ||
| change_log | No | ||
| clean_rows | No | ||
| quarantine | No | ||
| assumptions | No | ||
| rule_errors | No | ||
| drift_report | No | ||
| rule_results | No | ||
| quality_score | No | ||
| suspect_cells | No | ||
| change_summary | No | ||
| column_mapping | No | ||
| fd_suggestions | No | ||
| missing_report | No | ||
| clean_row_index | No | ||
| cleaning_profile | No | ||
| discovered_rules | No | ||
| duplicate_groups | No | ||
| rule_suggestions | No | ||
| pattern_exceptions | No | ||
| data_quality_report | No | ||
| check_digit_failures | No | ||
| discovered_row_rules | No | ||
| relationship_outliers | No |