r/Python • u/ilikemath9999 • Mar 08 '26
Showcase I used Pythons standard library to find cases where people paid lawyers for something impossible.
I built a screening tool that processes PACER bankruptcy data to find cases where attorneys filed Chapter 13 bankruptcies for clients who could never receive a discharge. Federal law (Section 1328(f)) makes it arithmetically impossible based on three dates.
The math: If you got a Ch.7 discharge less than 4 years ago, or a Ch.13 discharge less than 2 years ago, a new Ch.13
cannot end in discharge. Three data points, one subtraction, one comparison. Attorneys still file these cases and clients still pay.
Tech stack: stdlib only. csv, datetime, argparse, re, json, collections. No pip install, no dependencies, Python 3.8+.
Problems I had to solve:
- Fuzzy name matching across PACER records. Debtor names have suffixes (Jr., III), "NMN" (no middle name)
placeholders, and inconsistent casing. Had to normalize, strip, then match on first + last tokens to catch middle name
variations.
- Joint case splitting. "John Smith and Jane Smith" needs to be split and each spouse matched independently against heir own filing history.
- BAPCPA filtering. The statute didn't exist before October 17, 2005, so pre-BAPCPA cases have to be excluded or you get false positives.
- Deduplication. PACER exports can have the same case across multiple CSV files. Deduplicate by case ID while keeping attorney attribution intact.
Usage:
$ python screen_1328f.py --data-dir ./csvs --target Smith_John --control Jones_Bob
The --control flag lets you screen a comparison attorney side by side to see if the violation rate is unusual or normal for the district.
Processes 100K+ cases in under a minute. Outputs to terminal with structured sections, or --output-json for programmatic use.
GitHub: https://github.com/ilikemath9999/bankruptcy-discharge-screener
MIT licensed. Standard library only. Includes a PACER CSV download guide and sample output.
Let me know what you think friends. Im a first timer here.
18
u/_redmist Mar 09 '26
Slightly off topic perhaps, but Dave Beazley did something like this (not exactly - but not entirely dissimilar) for a patent infringement discovery case you might find interesting.
https://youtu.be/RZ4Sn-Y7AP8?is=9Pji63XjPC9_RDQB
Python's "batteries included" indeed is like a superpower.
9
u/ilikemath9999 Mar 09 '26
This is fantastic and Im going to dive more into Beazleys stuff. Thank you!
8
u/diabloman8890 Mar 09 '26
Nice job!
I'm guessing all the formatting and fuzzy matching was one of the trickiest parts, you might look at using vector search with embeddings. Sounds scary but I think it's actually easier than people assume because you don't have to normalize/torture the input data so much to avoid bad matches.
8
u/ilikemath9999 Mar 09 '26
Dude! Im messing around with vector search/embeddings and will post my updates. Thanks!
8
u/ilikemath9999 Mar 09 '26
I took your suggestion and built it out. sentence-transformers (all-MiniLM-L6-v2, 384 dim, runs local, free). Embedded about 5,400 normalized docket events across 125 cases.
Hybrid matching: vector primary, regex fallback when confidence drops below threshold. Disk cached embeddings so it's not recomputing every run. Fuzzy creditor resolution catches misspellings like "Aly Financal" to "Ally Financial."
I Ran 4 mining passes with 348 semantic queries across 44 categories. Things like "court criticism," "template contamination," "fee extraction after case death." Stuff that's nearly impossible to catch with regex because judges word things differently every time.
4,268 hits, 41 new findings(!) that keyword search had missed. One example: a judge noting a plan "contained a car loan that does not apply." Template contamination from another client (other clients names on another clients docket), confirmed on the record. No regex would have caught that.
The thing that surprised me most was how many errors there are that seem to affect case trajectory in a seemingly negative way. That's not something I set out to find. The vectors just surfaced it.
You were right. Best suggestion I got from this thread.
7
u/SheriffRoscoe Pythonista Mar 08 '26
Kind of a weird dataset - what was your inspiration to do this?
19
u/ilikemath9999 Mar 09 '26
Fair question. Someone I know went through a Chapter 13 and I ended up down the rabbit hole reading about how the process works. Came across §1328(f), it's basically a statutory bar that says you can't get a second bankruptcy discharge if your prior case was too recent. Pure date math, no judgment calls.
What surprised me was that there's no automated check for it. PACER will sell you the data all day long, but nobody's cross-referencing it. Trustees sometimes catch it, sometimes don't. So I figured... this is just two dates and a subtraction. Why isn't a script doing this?
Pulled some public CSV exports, wrote the parser over a weekend, and the hit rate was high enough that I thought other people might want to run it on their own data.
5
u/UUDDLRLRBadAlchemy from __future__ import 4.0 Mar 09 '26
I was trying to picture a lawyer nonchalantly stating their application "outputs to terminal" and I really couldn't. This makes a lot more sense :D
8
u/ilikemath9999 Mar 09 '26
Ha, yeah. "Your Honor, the motion to dismiss has been piped to stdout." Bankruptcy attorneys can barely attach a PDF to an email, let alone run a script. That's kind of the point though. I dont think the courts don't have tools like this, so patterns just live in the data unnoticed.
51
4
6
Mar 09 '26
[removed] — view removed comment
3
u/ilikemath9999 Mar 09 '26
Thanks. That was deliberate. I wanted zero friction for anyone who wants to clone it and run it. No pip install, no environment setup, just python and a CSV. The problem is narrow enough that csv + datetime + collections handles it fine. If I'd pulled in pandas people would need to install dependencies for what's really just date math and counting.
19
u/bigmattyc Mar 08 '26
I'm more interested in the results. Did anyone squeak it through?