Skip to content
REC · NEW
PIXELTAPES
SUBSCRIBE
● AI 10 MIN READ

My AI Bot Wrote a Script. The Tests Said 3 of 15.

Closed laptop beside a blank ruled sheet and a rubber stamp pad on a wooden desk under warm lamp light

My AI bot wrote a script from one plain brief: turn messy SAMPLE receipt lines into a CSV. My rules came first: freeze the tests, hide them from the model, and publish the score even if it was bad. The first pass scored 3 of 15. The repair pass made it worse. Here is the full scorecard.

Why freeze the tests before the model sees them?

I keep seeing people post a screenshot of a model writing Python and call it done. The code looks fine. Nobody runs it. Nobody says what failed.

I wanted the opposite. Give a clear brief, freeze a test suite before the model sees a single word, then publish the real pass and fail counts. If the score is ugly, the score stays ugly. That was my rule for this post.

So you know who did what: I set the job and the rules, and I judged the result. My assistant bot was the referee. It wrote and froze the tests, called the model, and ran every command. A small local model, qwen3:4b, wrote the actual code.

This is the first post in a small recurring series here: I give my AI bot a concrete job, I judge what comes back, and I show the artifacts.

What setup did the bot run on?

Label for the run, so you can compare later:

  • Model that wrote the script: qwen3:4b through Ollama 0.40.11
  • Referee: my assistant bot on one box (wrote the suite, called the API, ran the tests)
  • API: local POST /api/chat with think: false, temperature: 0, seed: 42
  • Hardware: Intel Xeon, 8 CPUs, about 15 GiB RAM, CPU only (no GPU)
  • Date: 26 Oct 2026, Asia/Calcutta
  • API cost: $0 (local)

Ollama’s API docs expose prompt_eval_count, eval_count and the matching durations in nanoseconds. The same docs give the speed formula as eval_count / eval_duration * 10^9 tokens a second. The Qwen3-4B model card describes a thinking mode for hard reasoning and a non-thinking mode for faster general work. I told the bot to keep thinking off for this job.

Two honest limits before you read the numbers. This is one setup and one run of each pass, a small sample and not a benchmark. And Ollama’s qwen3:4b is a 4-bit GGUF build (Q4_K_M, according to ollama show qwen3:4b), not the full-precision weights on Qwen’s model card, so another build, another machine or a GPU can give you different code and different timings.

My bot ran the whole loop on one box so the numbers stay honest. The small model lived in Ollama. The tests lived in a folder that model could not read. Every JSON response, every log line and every hash sits in that same folder so a human reviewer can open them later.

If you want the same local loop on your own machine, start from the local Ollama setup guide. This post is not about Kali tools. It is about scoring one script.

What brief did I give the bot?

The job was small on purpose. Parse SAMPLE receipt lines shaped like STORE | DATE | AMOUNT, write a CSV with header store,date,amount, and stay quiet on success.

I asked for messy cases: rupee symbols, Rs prefixes, dollar signs, commas in amounts, dates as YYYY-MM-DD or DD/MM/YYYY, blank lines, and one malformed line that should be skipped. Standard library only. Return only the Python source for receipts_to_csv.py.

Exact brief (my bot also hashed it in the artifacts folder before the model call):

Write a single Python 3 script named receipts_to_csv.py that reads SAMPLE receipt lines from a text file path given as the first command line argument and writes a CSV to the path given as the second argument.

Each input line looks like: STORE | DATE | AMOUNT
- STORE is a shop name that may contain spaces.
- DATE may be YYYY-MM-DD or DD/MM/YYYY.
- AMOUNT may look like 12.50, 1,234.50, Rs 99, ₹250.00 or $12.50. Strip currency symbols and thousand separators. Keep two decimal places in the CSV.
- Skip blank lines and lines that are only whitespace.
- Skip malformed lines that do not have exactly two pipe characters, or that have an empty store, an unparseable date or an unparseable amount. Do not crash on them.
- Normalise every kept DATE to YYYY-MM-DD.
- Write a CSV with a header row: store,date,amount
- Quote every field with double quotes.
- Use only the Python standard library. No third party packages.
- Print nothing except optional progress is forbidden: the script must be silent on success (exit 0) and print a one line error to stderr then exit 1 only if the input file is missing.

Return only the full Python source code for receipts_to_csv.py. No markdown fences, no commentary.

How did my bot freeze the tests before the model saw anything?

My bot wrote 15 unittest cases first. They live in test_receipts_to_csv.py. They cover the happy path, currency shapes, slash dates, blank lines, bad rows, quoted CSV fields and a missing input file.

Then it hashed the brief and the tests and wrote the order into a log, before any call to Ollama.

Actual lines from protocol-order.log (IST lines trimmed). The first model call is logged later, at 04:38:59 UTC:

step=1_brief_written
utc=2026-10-26T04:38:36Z
e632b926c0cf18169fbdc92c682a0c4f53c818eae613eba8753963ebf00d3a02  artifacts/brief.txt
step=2_tests_written_BEFORE_model
utc=2026-10-26T04:38:36Z
378f800444a7c0170fea4612df12a3f1b500b16dc8050de56c4dece3a799a169  artifacts/test_receipts_to_csv.py
note=model_has_not_been_called_yet

The prompt file for pass 1 is a copy of the brief. A grep for unittest and test_0 on that prompt returned 0. The model never got the tests.

What did the first pass score?

Bar chart comparing passed and failed unit tests for pass 1 and pass 2 of a local AI coding run
Pass 1 scored 3 of 15. The repair pass scored 1 of 15. Source: this run, 26 Oct 2026 IST, Ollama 0.40.11 / qwen3:4b / CPU only.

My bot called Ollama like this (system line asked for source only, no fences):

# body saved as request-pass1.json, then:
curl http://127.0.0.1:11434/api/chat -d @request-pass1.json

Wall clock for pass 1: 48.985 seconds. Prompt tokens: 330 at about 172.38 tok/s. Generated tokens: 600 at about 12.75 tok/s. Cost: $0.

The small model still wrapped the script in a markdown fence. My bot stripped the fence to save receipts_to_csv.py and changed nothing else. Then it ran:

python3 -m unittest test_receipts_to_csv -v

Pass 1 scorecard (15 tests), actual result from this run:

Passed: 3
Failed: 12
Passed names:
  test_01_script_exists
  test_02_header_only_on_empty_input
  test_14_missing_input_exits_one

So the file existed, the empty input wrote a header, and a missing input file exited 1. Every real receipt line failed. I expected better from a clean brief. The suite did not care what I expected.

What broke on the first pass?

The script split each line on | and never stripped the pieces. A line like Cafe Bean | 2026-10-01 | 12.50 became this (actual Python output):

['Cafe Bean ', ' 2026-10-01 ', ' 12.50']

datetime.strptime(' 2026-10-01 ', '%Y-%m-%d') raises ValueError. The code treated that as an unparseable date and skipped the row. Header only. That single miss explained the six IndexError cases (no data row to read) and the length assertions that expected 2 rows and got 1.

I am not annoyed that a 4B CPU model missed a .strip(). I am glad the tests caught it in under a second. The screenshot culture would have called that file a win because the code “looked right.”

Did a repair pass help?

I told my bot to try one repair pass. It sent only the failing test names, the error messages and the current script. No test source. Example of what the small model saw:

ERROR: test_03_simple_line
  IndexError: list index out of range

FAIL: test_13_fields_are_quoted
  AssertionError: '"Cafe Bean","2026-10-01","12.50"' not found in '"store","date","amount"\n'

Wall clock for pass 2: 56.839 seconds. Prompt tokens: 970 at about 164.09 tok/s. Generated tokens: 585 at about 11.52 tok/s. Cost: still $0.

Pass 2 scorecard (15 tests), actual result from this run:

Passed: 1
Failed: 14
Passed names:
  test_01_script_exists

The repair made it worse. The new file dropped the if __name__ == "__main__": main() block. When you run python3 receipts_to_csv.py ..., main() never runs. No CSV is written. A missing input file exits 0 because the check for it lives inside main().

The diff between the two files is only those last three lines. The split('|') bug from pass 1 is still there, untouched. So the repair fixed nothing and broke the one part that worked. That is an honest result, so it stays in the post.

Dark terminal style panel with abstract pass and fail marks beside a brass timer on a desk
The repair pass dropped the main guard, so the script stopped running at all.

What should you steal from this protocol?

Three habits beat a prettier model for this kind of job:

  1. Write the tests first and hash them before the prompt leaves your folder.
  2. Give the model the brief only. Keep the suite hidden.
  3. For a repair pass, send failure names and messages, not the test code, then measure again.

One more rule for the repair prompt: if a failure message quotes a CSV fragment, that is fine. If it would paste a full test function, cut it. The point is to see whether the model can fix the script from symptoms, not from a copy of the exam.

Also keep the raw JSON. Ollama returns the token counts and durations you need. If a number is not in that file, do not invent it.

I still like small local models for chores. I like them more when a held-out suite can embarrass them in public, with the raw timings sitting next to the score. For more on watching what a model actually does, my LLM observability notes for 2026 pair well with this scorecard habit.

How can you run this scorecard yourself?

You need Ollama with qwen3:4b pulled, Python 3, curl and jq. Everything below runs on your own machine and costs nothing. Swap in your own small job if receipts are not your thing.

Step 1: Write the brief and the tests, then freeze them

Write brief.txt and a unittest file for your job before you open any chat with a model. Then log the time and the hashes:

{ echo "step=tests_frozen_before_model"; date -u +utc=%Y-%m-%dT%H:%M:%SZ; sha256sum brief.txt test_receipts_to_csv.py; } >> protocol-order.log

Step 2: Build the request from the brief only

jq -n --rawfile brief brief.txt '{model:"qwen3:4b",stream:false,think:false,options:{temperature:0,seed:42},messages:[{role:"system",content:"You write Python 3 scripts. Return only the full source code. No markdown fences. No commentary."},{role:"user",content:$brief}]}' > request-pass1.json

This is the same body my bot sent, field for field.

Step 3: Call the model and save the script

curl -s http://127.0.0.1:11434/api/chat -d @request-pass1.json > response-pass1.raw.json
jq -r '.message.content' response-pass1.raw.json | sed '/^```/d' > receipts_to_csv.py

The sed line drops markdown fence lines in case the model adds them anyway. On this run’s raw JSON it rebuilt the pass 1 script byte for byte.

Step 4: Read the cost and speed from the raw JSON

jq '{prompt_eval_count, eval_count, tok_s: (.eval_count / .eval_duration * 1e9)}' response-pass1.raw.json

Actual output on this run’s pass 1 file:

{
  "prompt_eval_count": 330,
  "eval_count": 600,
  "tok_s": 12.753607884076336
}

Step 5: Run the frozen tests and check the guard

python3 -m unittest test_receipts_to_csv -v 2>&1 | tail -3
grep -q '__name__ == "__main__"' receipts_to_csv.py || echo "missing __main__ guard"

Actual output from the last line on the pass 2 script:

missing __main__ guard

That one grep would have saved a wasted repair call here. Run it before you spend another prompt.

Pitfalls and cost

  • Fences: the model added a markdown fence on pass 1 even though the brief said not to. Strip it, and log that you did.
  • Spaces: split('|') keeps the spaces around each field. If your format has a | b | c, a missing .strip() breaks every row.
  • Repairs can go backwards: the repair here dropped the __main__ block. Score every pass, not only the last one.
  • Time and money: on 8 CPU cores with no GPU, each call took about 49 to 57 seconds. API cost was $0 because the model is local. Your own power bill is the only cost.

What would I do next?

Next time I give my AI bot a coding job, I will add one line to the brief: “strip each field after you split.” I will also tell it to refuse markdown fences harder, or to post-check that the saved file compiles and defines main under __main__ before it spends a repair call.

If you repeat this at home, keep your own protocol-order.log. Write the UTC time and the sha256 of the brief and the suite before the first API call. When someone asks whether the model saw the tests, that file is the answer.

And I will keep publishing the ugly scores. A model that writes a script is easy to demo. A script that survives tests your referee froze first is the only demo I trust.

Written by DeepuMore about me, my work and my lab at deepu.live

Leave a comment

Your email stays private. First-time comments are held for a quick review.

AUTO-PLAY · UP NEXT

Keep the tape rolling

Never miss a new tape.

One email a week with everything new on PixelTapes. No spam, unsubscribe anytime.