FailSlice
v0.1.1Shrink multi-table CSV/Parquet data to a small, FK-consistent, verified reproducer of a data bug.
Documentation · Persian guide (راهنمای فارسی) A pipeline produces a wrong number on 26,001 rows spread over three tables. Logs tell you *which* step failed; data-quality checks tell you *that* a rule or an aggregate is off. But the hardest data bugs come from a *combination* of rows across tables (a duplicated key plus a join that double-counts, a NULL inside NOT IN, a timestamp tie in "latest record per key"), where no single row is wrong. You cannot attach 26k rows to a bug report, and deleting rows by hand breaks the foreign keys and changes the bug.
Summary extracted from the README.
FailSlice
Shrink a multi-table dataset to the handful of rows that still trigger your data bug, keep foreign keys intact, prove it with an independent replay, and get a ready-to-run pytest regression test.
Documentation · Persian guide (راهنمای فارسی)
Status: alpha (0.1.1). The engine, the
failslicecommand line, the run report and manifest, the generated pytest test and thefailslice-mcpserver for AI agents work and are tested on Linux, macOS and Windows. The Python API and file formats may still change before 1.0.

Recorded in real time, not sped up (tape).
Why FailSlice
A pipeline produces a wrong number on 26,001 rows spread over three tables. Logs tell you
which step failed; data-quality checks tell you that a rule or an aggregate is off. But
the hardest data bugs come from a combination of rows across tables (a duplicated key plus
a join that double-counts, a NULL inside NOT IN, a timestamp tie in "latest record per
key"), where no single row is wrong. You cannot attach 26k rows to a bug report, and
deleting rows by hand breaks the foreign keys and changes the bug.
FailSlice answers: what is the smallest slice of these tables that still makes this failure happen? The ideas are not new (delta debugging to shrink failing inputs, database subsetting to keep foreign keys intact); what FailSlice adds is their combination with checked claims:
- the search is guided by your failure predicate, a DuckDB SQL query that says "the bug is present";
- removing rows never creates a dangling reference; orphans already in your input are never "repaired", and those that survive are recorded;
- the result is replayed in a fresh process from the exported files only, and called
1-minimal (verified)only when that check really ran; - you get a self-contained pytest test (only
pytestandduckdbneeded) that passes while the bug reproduces; after your fix, export it with--expect passesto guard against the bug's return; - an MCP server (
failslice-mcp), so an AI agent can go from "here are my files" to "here is a failing test" without loading millions of rows into its context.
FailSlice isolates rows; it does not determine the root cause.
Quickstart (under a minute)
Requirements: uv (it fetches Python 3.11+ if needed).
uvx failslice demo shop # a 3-table example: order 4242 was loaded twice
cd shop
uvx failslice reduce --out run # reduce, replay in a fresh process, write the test
uvx --with duckdb pytest -q run/pytest
1-minimal (verified): 26,001 -> 4 rows (0.02%); replay verified
run directory: .../shop/run
report: .../shop/run/report.md
test: pytest .../shop/run/pytest
The four rows: one customer, order 4242 twice, one order line. Joining lines to orders
double-counts revenue. uvx failslice explain run lists what is special about them (order
4242 has two parent rows), and run/report.md has the whole story. The generated test
needs only pytest and duckdb, not FailSlice.
Your own data:
cd path/to/your/data
uvx failslice init # failslice.yaml with every table and key *suggestions*
# review the suggestions, write the predicate, then:
uvx failslice check
uvx failslice reduce
init writes the key suggestions commented out, for you to review; the predicate is a SQL
query that is TRUE while the bug is present
(predicates). The
demo's failslice.yaml is a complete example. To install instead of using uvx:
uv tool install failslice or pip install failslice.
How it works
flowchart LR
CFG[failslice.yaml] --> LOAD[load files into DuckDB<br/>hash every input]
LOAD --> CHECK[determinism check:<br/>predicate TRUE 4x, same signature]
CHECK --> RED[cascade ddmin:<br/>delete row ranges, cascade to children]
RED --> CERT[certification:<br/>every single-row deletion is not TRUE?]
CERT --> EXP[export run directory<br/>spec.json + Parquet]
EXP --> VER[replay in a fresh process<br/>from the exported files only]
VER --> ART[report.md, manifest.json,<br/>CSV, pytest bundle]
Rows are removed in ranges, table by table, parents first; removing a parent also removes the child rows that would lose their parent. A candidate is kept only if the predicate is freshly evaluated TRUE on it. Details: foreign keys and minimality.
Guarantees and limits
Each guarantee is enforced in code and covered by tests:
- a configuration is kept only after a fresh TRUE evaluation (the cache holds negative results only);
- no new dangling references, ever; input orphans may survive as recorded exemptions;
- independent replay from the exported files;
verifiedmeans predicate TRUE and integrity intact there; 1-minimal (verified)only when certification completed, the replay is verified and the export was lossless; otherwise "reduced". Never a claim of the smallest possible result or of a root cause;explainreports observations;initmakes suggestions;- same inputs, settings and seed give the same result, unless a run is stopped by its wall-clock budget or an evaluation times out;
- a predicate must be a single read-only
SELECT(other statements and file-reading functions are rejected); every data file named in the config, every output path of the CLI and every path an MCP client passes stays inside an allowed root (a Python caller chooses its ownout_dir); DuckDB's external file access is switched off after loading, and FailSlice's own DuckDB connections never write spill files.
Limits: single-column, acyclic foreign keys; data loaded into memory; in-process runs have cooperative timeouts; the predicate must be deterministic.
For AI agents (MCP)
failslice-mcp exposes the loop inspect, check the predicate, reduce, verify, explain,
export a test to MCP clients over stdio. The agent passes paths and SQL, never the data.
claude mcp add failslice -- uvx failslice-mcp --root /absolute/path/to/your/data # Claude Code
Claude Desktop (Settings → Developer → Edit Config opens claude_desktop_config.json)
and Cursor (.cursor/mcp.json) use the same entry:
{
"mcpServers": {
"failslice": {
"command": "uvx",
"args": ["failslice-mcp", "--root", "/absolute/path/to/your/data"]
}
}
}
Claude Desktop does not read your shell's PATH: if it cannot start uvx, put the
absolute path that which uvx prints in command. The server reads files only inside
--root and writes only under <root>/.failslice/.
uvx failslice-mcp@latest picks up a newer release. Tools, resources, budgets and tested
clients: MCP server.
Examples and benchmarks
Four more scenarios, each runnable with one command from a checkout and each needing a combination of rows across tables:
- TPC-H fan-out: a
late-arriving duplicate order inflates revenue by region (TPC-H data from DuckDB's
tpchextension). - NULL in
NOT IN: one NULL in a suppression list empties a mailing. - Date-parsing crash:
a depot switches date format and the staging query fails (
raisespredicate). - Latest record per key: a timestamp tie across two event streams gives an account two "current" rows.
| scenario | input rows | output rows | kept | evaluations | wall time | minimality |
|---|---|---|---|---|---|---|
| quickstart | 26,001 | 4 | 0.0154% | 37 | 1.1 s | 1-minimal (verified) |
| tpch_fanout | 76,706 | 6 | 0.0078% | 57 | 2.2 s | 1-minimal (verified) |
| tpch_fanout (sf 0.1) | 765,603 | 6 | 0.0008% | 63 | 4.0 s | 1-minimal (verified) |
| null_not_in | 6,101 | 3 | 0.0492% | 21 | 1.0 s | 1-minimal (verified) |
| date_parse_crash | 30,007 | 2 | 0.0067% | 31 | 0.9 s | 1-minimal (verified) |
| latest_tie | 11,000 | 3 | 0.0273% | 37 | 1.1 s | 1-minimal (verified) |
Measured 2026-11-29 on one machine (12th Gen Intel(R) Core(TM) i7-1260P, 16 logical CPUs, 7.5 GiB RAM; Linux 6.6.87.2-microsoft-standard-WSL2; Python 3.12.15, DuckDB 2.0.0, FailSlice 0.1.1 at 57361ba). Wall time is the median of 3 runs of reduce(isolate=True) including the replay and artifacts, without data generation; it depends on the machine. Method.
Related tools
FailSlice builds on established ideas and complements these tools rather than replacing them:
- dfshrink shrinks a single Polars DataFrame against a validator; it has no notion of relations between tables.
- dbslice extracts referentially intact database subsets from a seed record; the subset is not guided by a failure.
- SQLancer's reducers,
sql-reduce and
SQLreduce shrink SQL scripts and statements
(SQLancer's reducer can also drop rows written as
INSERTs); they do not work on table files with declared foreign keys. - RATest (SIGMOD 2019) computes small relational counterexamples for wrong queries, as a research prototype.
FailSlice combines predicate-guided, multi-table, FK-consistent row reduction on local files with a verified replay, regression-test export and an MCP interface.
Documentation
| Overview | what FailSlice adds, and the map of the docs |
| Configuration | failslice.yaml, settings, init |
| Predicates | the three forms, outcomes, comparison rules |
| Foreign keys and minimality | semantics, orphans, cascade, what 1-minimal means |
| Command line and Python API | commands, options, exit codes, --json |
| Run artifacts | manifest, report, CSV, explain, the generated test, replay |
| MCP server | failslice-mcp for AI agents: client setup, tools, resources |
| Design and decisions | architecture and its reasoning |
| راهنمای فارسی | the complete guide in Persian |
Roadmap
Not in 0.1 and planned for later; the architecture leaves room for the first two:
- column dropping (removing columns the bug does not need);
- parallel predicate evaluation;
- composite and cyclic foreign keys;
- value-level simplification (shrinking strings and numbers);
- live warehouse connections;
- Polars or pandas predicates;
- a web UI.
Contributing
Bug reports and pull requests are welcome; see CONTRIBUTING.md for the development setup and checks. Changes: CHANGELOG.md.
License
MIT, see LICENSE. To cite FailSlice, see CITATION.cff.
Author
Created and maintained by Saeed Mahdian (@sdmhdn, saeed.mahdian@gmail.com).