Tinker
Can an Agent Improve a Rules Classifier Using Only Git Commits?
Run an experiment where a loop improves a Python rules classifier via git commits, with a test set sealed until one final reveal that shows the overfit.
Quick answer
The loop harness works, and you can run it yourself in a few minutes. Whether an LLM agent could do this job is not tested here. A plain Python rules classifier (keywords and regexes) sits in a git repo. The loop proposes one rule change, scores it on the training set, commits if the score goes up, and reverts if it doesn’t. The test set stays sealed until the very end, when it’s opened once.
One thing to be clear about up front: no LLM agent did this. We can’t call a model here, so the proposer is a scripted, deterministic stand-in that mines a keyword from a failing training example. The data is synthetic, generated by a seeded script. What you’re reading is the real output of that script, and it’s the harness an agent would plug into, not a result about any agent.
In the main run, 25 commits took the training score from 0.283 to 0.750. The single held-out score at the end was 0.637, a gap of 0.113. Five other seeds gave bigger gaps. That gap is the point of the exercise: it’s the honest price of choosing every change by looking at the same examples.

What we built, and what is a stand-in
The question is whether a loop that only has git and a score can improve a classifier without hand-tuning. Git gives you a record of every accepted change, a one-line revert for every rejected one, and a diff you can size-limit.
Here are the pieces, and which ones are real:
- The classifier is a Python file of ordered regex rules. The first rule that matches wins, and anything unmatched gets the label
other. This is real code. - The dataset is synthetic. A seeded generator writes fictional support messages with four labels:
billing,bug,accessandother. Nothing in it comes from a real system or real customers. - The loop is real. It scores, commits, reverts and enforces budgets using real
gitcommands in a throwaway repo. - The proposer is the stand-in. It’s a deterministic search, not a model. It takes a failing training example, picks the keyword or word pair that best separates that example’s label in the training set, and appends it as a rule. Every few attempts it tries deleting a rule instead.
We ran everything on Python 3.13.16 and git 2.43.0 (checked 2026-11-12). The README in the download says Python 3.10 or newer, but we didn’t test older versions.
The setup: rules, synthetic data and the wall
The starting classifier has three rules, one per label, and nothing else:
RULES = [
("billing", r"\brefund\b"),
("bug", r"\bcrashes\b"),
("access", r"\blocked out\b"),
# --- end of rules ---
]
DEFAULT = "other"
That snippet is the real rules_baseline.py from the download. It scores 0.283 on the training set, which is 34 of 120 messages right.
The generator is built to be a bit unfair, because real data is. Each message gets a phrase from its true label (twelve to choose from per label), sometimes two, and about one message in five also carries a decoy phrase from a different label. About one in ten has no useful phrase at all. Then 2 to 5 neutral filler words get mixed in, such as “tuesday”, “laptop” or “dashboard”, and 5 percent of the labels are flipped on purpose. That means no rule set can reach 100 percent, and it means filler words will sometimes line up with a label by pure chance in a small sample.
That last property is what makes overfitting visible. With only 120 training messages, a filler word that happens to show up in three billing messages looks like a billing signal. A greedy loop will take it.
The data is split like this:
| Split | Messages | Who may read it |
|---|---|---|
| Train | 120 | the loop, every iteration |
| Held-out test | 300 | nobody, until reveal.py runs once |
The wall is made of three small things. The files live in separate folders (train/ and holdout/). loop.py refuses any path with holdout in it. And reveal.py writes a REVEALED.txt marker the first time it runs, then refuses to run again on that data. If you want a second experiment, you generate fresh data with a new seed.
The loop in one screen
This is a trimmed excerpt of loop.py, which we ran. The propose() call is the only place a real agent would go.
while commits < MAX_COMMITS and attempt < MAX_ATTEMPTS:
attempt += 1
cur, failing = score(rules_path, train) # TRAIN only
desc, new_text = propose(attempt, failing, train, text, tried) # STAND-IN
open(rules_path, "w").write(new_text)
stat = git(repo, "diff", "--numstat", "rules.py").split()
if int(stat[0]) + int(stat[1]) > MAX_DIFF_LINES: # diff size limit
git(repo, "checkout", "--", "rules.py") # revert
continue
new, _ = score(rules_path, train)
if new > cur: # strictly better, or no commit
git(repo, "add", "rules.py")
git(repo, "commit", "-q", "-m", "%s: train %.3f -> %.3f" % (desc, cur, new))
commits += 1
else:
git(repo, "checkout", "--", "rules.py") # revert
Three details matter. First, “better” means strictly better, so a tie gets reverted. Second, the commit message records the score before and after, which means git log alone tells the whole story of the run. Third, the diff check uses git diff --numstat, which the official git diff documentation describes as a machine friendly count of added and deleted lines (checked 2026-11-12).
The budgets we set were 25 commits, 120 attempts and a two line diff limit. The run stopped because it hit the commit budget, not because it ran out of ideas.
The real commit history
This is the real output of git log --reverse --format='%h %s' from a fresh unzip of the download. We ran bash run_experiment.sh 7 out, so the data seed is 7. The hashes change on every run because commits carry timestamps; the scores don’t.
d4965c0 baseline rules: train 0.283
7c5e407 add bug rule \bwill\b: train 0.283 -> 0.300
1a32da9 add access rule \bexpired\b: train 0.300 -> 0.333
eaf5286 add bug rule \bspinner never\b: train 0.333 -> 0.350
d01347a add billing rule \btomorrow promo\b: train 0.350 -> 0.358
63d5d2d add bug rule \bblank screen\b: train 0.358 -> 0.392
eacdddc add billing rule \bdashboard\b: train 0.392 -> 0.425
66f8fc1 add billing rule \bclick\b: train 0.425 -> 0.458
27e9a95 add bug rule \bphone payment\b: train 0.458 -> 0.467
c99a305 add access rule \bpassword\b: train 0.467 -> 0.508
94d0bf1 add access rule \bsign\b: train 0.508 -> 0.533
dfc8224 add billing rule \btwice\b: train 0.533 -> 0.542
12afb92 add bug rule \bmissing\b: train 0.542 -> 0.567
4e21e01 add billing rule \bplan\b: train 0.567 -> 0.592
a157321 add access rule \bsuspended\b: train 0.592 -> 0.600
3f1ef98 add access rule \btwo factor\b: train 0.600 -> 0.617
597776d add access rule \bupload file\b: train 0.617 -> 0.625
720e4d4 add bug rule \bis broken\b: train 0.625 -> 0.642
fba9ea7 add billing rule \breceipt\b: train 0.642 -> 0.667
881a85d add billing rule \bevening phone\b: train 0.667 -> 0.675
ade3cad add access rule \blog in\b: train 0.675 -> 0.692
2ce916a add billing rule \bovercharged\b: train 0.692 -> 0.708
b0bb68c add billing rule \bupload\b: train 0.708 -> 0.717
037c0f4 add billing rule \bfailed meeting\b: train 0.717 -> 0.725
ed4a352 add billing rule \bsubscription renewed\b: train 0.725 -> 0.742
fd27a38 add bug rule \bexception\b: train 0.742 -> 0.750
The loop summary line said stopped after 29 attempts, 25 commits. outcomes: {'committed': 25, 'reverted': 4}. All four reverts were “drop a rule” tries (attempts 7, 14, 21 and 28), and each one lowered the training score. Every “add a rule” try was accepted, because with a training score this low, almost any rule that fixes one failing message and breaks nothing wins.
Read the log skeptically and you can already see trouble. Some rules look like real signals (receipt, overcharged, exception) and others look like noise (dashboard, click, evening phone). Because we wrote the generator, we can check properly. We compared each committed rule against the generator’s vocabulary. Five rules (dashboard, click, upload file, evening phone and upload) are made only of filler words. Three more (tomorrow promo, phone payment and failed meeting) mix a filler word with a real phrase word. So 8 of the 25 added rules lean on chance. Every one of them earned its commit, because it raised the training score.
The single reveal
After the 25th commit, we ran reveal.py once. It refuses if the repo has uncommitted changes, so it can only score what’s in git. This is its real output:
commit fd27a38
best train accuracy : 0.750
held-out accuracy : 0.637 (191 of 300)
gap (train - test) : +0.113
rough +/- on test : 0.028 (one standard error, sqrt(p(1-p)/n))
So the best training score was 0.750 (90 of 120) and the held-out score was 0.637 (191 of 300). A reader who only saw the git log would believe the classifier got to 75 percent. The held-out number says to expect about 64 percent on new data from the same generator, give or take a few points.
What a gap means and how to read it honestly
The gap is train minus held-out. A positive gap means the training score overstated how the rules will do on new data. It has three causes, and they stack:
- Overfitting. Rules like
dashboardexplain the particular 120 messages, not the generator. They add training score and add nothing, or less than nothing, on new messages. - Selection pressure. Every commit was chosen because it scored well on the training set. Picking the winners of many tries inflates the winners’ scores. The more attempts you allow, the stronger this gets.
- Sampling noise. The test score has a standard error of about 0.028 on 300 messages (the formula is in the output above). The training score, on only 120 messages, is looser still, roughly 0.04 by the same formula. Small gaps can be noise. For the gap itself, combine both errors: roughly sqrt(0.028^2 + 0.04^2), about 0.05, so 0.113 is a little over two of those. That is only a rough guide, because the training score was picked by selection and the simple formula assumes it wasn’t. The six seeds below tell you more than any one comparison.
Because one run is one sample, we repeated the whole experiment on five other seeds. Each seed is a separate experiment with its own fresh data and its own single reveal. We ran seeds 1 to 5 after seeing seed 7, and we’re reporting all of them:
| Seed | Best train | Held-out | Gap |
|---|---|---|---|
| 7 (main run) | 0.750 | 0.637 | +0.113 |
| 1 | 0.817 | 0.583 | +0.233 |
| 2 | 0.758 | 0.510 | +0.248 |
| 3 | 0.917 | 0.623 | +0.293 |
| 4 | 0.817 | 0.610 | +0.207 |
| 5 | 0.767 | 0.557 | +0.210 |
Every run showed a positive gap, from 0.113 to 0.293, with a mean of about 0.22. That is consistent with overfitting in this synthetic setup, and it says nothing about how an LLM agent, or real data, would behave. Seed 7, the run we happened to show first, had the smallest gap. So if you only read the main run, you’d come away too optimistic. That’s why the table is here.
The seed with the highest training score (seed 3, at 0.917) also had the largest gap. Six runs is far too few to call that a rule.
Here’s how to interpret a gap in your own runs:
- Gap near zero, within noise: the changes mostly generalized. You still can’t say the classifier is good, only that the training score wasn’t lying.
- Large positive gap: the loop overfit. Cut the commit budget, add training data, or require a minimum improvement per commit (for example at least two more examples right). We didn’t run those fixes here.
- Negative gap: check for a bug or a lucky split before celebrating.
Whatever the gap, the test number is the one you report.
Where an LLM agent plugs in
The swap point is one function, propose(). Today it reads the failing training examples and the current rules, and returns a description plus the full text of a new rules.py. A model would do the same job with better ideas, such as one regex that covers several phrasings instead of one token.
Everything else stays the same. Scoring is a script, commit and revert are git, and the budgets and diff limit are enforced by code the model doesn’t control. The model suggests, and the harness decides.
A prompt for the model could look like this (not run here, since we can’t call a model):
You are improving a rules based text classifier. Labels: billing, bug, access, other.
Below are the current rules and up to 10 training examples the rules get wrong,
each with its correct label.
Propose ONE change to rules.py: add a rule, edit a rule, or delete a rule.
Change at most two lines. Do not touch any other file.
Return the complete new rules.py and one sentence saying why.
Keep the loop’s strict test: commit only when the training score strictly improves. A model’s confident explanation isn’t evidence.
A model-based classifier isn’t deterministic, so a single score can move on its own. Build a 30 case eval set and run it three times covers repeating runs to see how much. Our rules classifier is deterministic, so repeats would print the same number here.
What to give the agent, and what never to give it
Give it:
- The failing training examples, with their correct labels. Cap the number (10 or so) so the prompt stays small and each change stays focused.
- The current
rules.py. - A short list of recent rejected proposals and their score changes, so it doesn’t try the same thing twice.
- The constraints in plain words: one change, two lines at most, one file.
Never give it:
- The test file, or its path. If the agent can read it, the wall is gone.
- Test scores of any kind, even a single number per commit. Feeding them back turns the test set into a second training set, one pass at a time.
- Summaries derived from the test set, such as “held-out accuracy dropped after commit 12”. That’s the same leak in different words.
If you want feedback during the run that isn’t the training score, split the training data again into train and a validation slice, and let the loop use that. The sealed test set stays sealed. We didn’t build that variant here, so treat it as a design suggestion.
There’s also a limit to our wall. Our loop.py refuses to read a path containing holdout, but that only stops our script. A real agent with a shell can open any file it can reach. If you use a tool-using agent, put the test data outside its sandbox or in a place the agent’s account can’t read, and make the scoring script the only code that touches it. Keep the scoring script and loop out of the agent’s writable files too, or it can change how it’s graded.
Guardrails to copy
| Guardrail | In the demo | What it prevents |
|---|---|---|
| Wall between train and test | separate folders, loop refuses holdout paths |
the loop tuning on the test set |
| Reveal once | REVEALED.txt marker, second run refuses |
quietly using the test set as a second training set |
| Clean tree before reveal | reveal.py checks git status |
scoring changes that were never committed |
| Commit budget | 25 commits | unlimited overfitting |
| Attempt budget | 120 tries | a loop that never ends |
| Diff size limit | 2 changed lines | a rewrite of the whole file in one go |
| Commit only on strict gain | new > cur |
ties and lucky noise becoming history |
| Writable files | only rules.py |
the proposer editing the scorer |
The three tests in tests.py check the wall, the reveal-once rule and the commit-only-if-better rule. We ran them from a fresh unzip and all three passed (Ran 3 tests ... OK).
This idea sits close to a CI gate, where a change merges only if a check passes. If you want that version, prompt regression gates in CI covers it. The difference here is that the loop writes its own changes, so the wall and the budgets matter more.
Run it yourself
Download the rules classifier loop source package and extract it into a new empty folder. You need Python and git. There are no packages, no network calls and no API keys.
gen_data.py makes the synthetic train and held-out files
rules_baseline.py the three starting rules
scoring.py loads a rules file and scores it
loop.py the loop (the stand-in proposer is propose())
reveal.py the one-time held-out score
run_experiment.sh runs the whole thing from scratch
tests.py checks for the guardrails
README.md
On macOS, Linux or WSL, run this (we ran it from a fresh unzip on Linux; we haven’t tested Git Bash or native Windows, and the script calls python3, which may be named python there):
bash run_experiment.sh 7 out
python3 -m unittest -v tests.py
Change the first number to try another seed. Each seed makes new data and gets one reveal, so don’t delete REVEALED.txt to peek again.
Two things worth trying: lower MAX_COMMITS to 8 and compare the gap, or replace propose() with a real model call and keep the rest. We haven’t run either, so we don’t know the numbers.
Limits of this experiment
- No agent was involved. The proposer is a few dozen lines of deterministic code. A real model would propose different, probably smarter changes, and the numbers would differ.
- The data is synthetic. We wrote the generator, including the noise and the filler, so overfitting was easy to provoke. Real data has its own quirks, and the size of the gap there is unknown.
- One data size and one budget. We used 120 training and 300 test messages and a 25 commit budget, and didn’t sweep either. Six seeds show the gap is consistent in this setup, not that the estimate is tight.
- A rules classifier is a narrow case. It’s easy to diff and easy to revert. A prompt or a whole codebase is harder to size-limit.
A scrolling git log suits this idea well, since each line is a step with a before and after score. It would make a good short video, but this post doesn’t include one.
FAQ
Can an LLM agent improve a rules classifier using only git commits?
The loop in this post can: propose a change, score it on the training set, commit if it improves and revert if not. We couldn’t call a model here, so a scripted stand-in did the proposing, and no agent result is claimed. The harness is the same one an agent would plug into by replacing propose().
Why keep the test set sealed until the end?
Every commit in the loop is chosen by looking at the training score, so that score is biased upward. A test set the loop never touches gives one honest number. In the main run, the training score was 0.750 and the held-out score was 0.637.
What does the gap between train and test score mean?
It’s the training score minus the held-out score. A positive gap means the training score overstated performance on new data, from overfitting, selection pressure and noise. The six seeds we ran gave gaps from 0.113 to 0.293.
What should you give an agent in the improvement loop?
Give it the failing training examples with their labels, the current rules, a short list of rejected tries and the constraints. Never give it the test file, its path or any score or summary derived from it. If you need mid-run feedback, split a validation set off the training data.
What guardrails should the loop have?
Use a wall between train and test, a commit budget, an attempt budget, a diff size limit and a commit-only-on-strict-improvement rule. The demo also checks for a clean git tree before the reveal and refuses a second reveal. With a tool-using agent, also keep the test data and scoring code out of its reach.
Can you check the numbers yourself?
Yes. Download the package, extract it and run bash run_experiment.sh 7 out. The scores should match this post, and the commit hashes will differ.
Where to go next
- Read how to choose an AI model with a simple task test for labelled cases and a grader that keeps mistakes visible.
- Try build a 30 case eval set and run it three times to see how much a score moves from run to run.
- See prompt regression gates in CI for turning a score check into a merge gate.
- Build the tool-calling loop an agent would run in build an AI agent in Python with tool calling.


