DEV Community

Harish
Harish

Posted on

How I improved consistency in my bulk classification prompt

I had a classifier that couldn't make up its mind.

The job is simple: given 200 URLs from a crawl, say which are worth keeping. The model sees only the URL and how many PDFs are on the page — no page content.

I asked for the ids to keep, ran it five times on byte-identical input, and got:

kept per run:  200, 15, 8, 200, 16
Enter fullscreen mode Exit fullscreen mode

Two runs kept everything. Two kept almost nothing. Measuring how much two runs agree on — the share of the keep set they have in common — gave 0.23.

Temperature was already zero. So the first question isn't how to fix it. It's how this is even possible.

Why identical input gives different answers

Because a computer adds numbers up in whatever order is convenient, and that order changes the answer.

That sounds wrong, so here it is. Take five whole numbers and add them in all 120 possible orders:

[1, 2, 3, 4, 5]  as ordinary integers
  ->  one answer, always:  15
Enter fullscreen mode Exit fullscreen mode

No surprise. Now the same exercise, with numbers written as decimals, one of them large:

[10000000000000000, 1, 2, 3, 4]  as decimals
  ->  THREE different answers:

      10000000000000000 + 1 + 2 + 3 + 4  =  10000000000000008
      10000000000000000 + 1 + 3 + 2 + 4  =  10000000000000010   <- the true total
      10000000000000000 + 2 + 1 + 3 + 4  =  10000000000000012
Enter fullscreen mode Exit fullscreen mode

Same five numbers. Three totals, two of them wrong.

The reason is that the big number has no room left to record a +1. Add 1 to it and nothing happens — the result rounds straight back. But let the small numbers meet each other first and they add up to something big enough to register. So whether the small ones combine before or after they reach the big one decides the answer.

Now scale that up. To pick its next word, a model scores every candidate by adding up thousands of numbers. On a GPU those additions are split across threads and combined in whatever order the hardware chose this time, which depends on what else is being processed alongside your request. Different order, slightly different score.

It helps to picture what "picking the next word" means. The model looks back over everything written so far — all of it at once, leaning harder on some words than others — scores every word it could write next, and takes the top one. Then that word becomes part of what it looks back at for the following one:

How a model picks its next token

Almost always this is invisible — the winning candidate wins by miles. But when two candidates score almost exactly the same, that last-digit wobble picks the winner. At temperature zero. On identical input.

So the game isn't making the model deterministic. You can't. The game is not asking it questions where two answers are nearly tied.

First attempt: make it explain itself

The obvious move. Don't just list ids — name the kinds of page you see, say which you want, then list them:

VERDICT: blog category archives (keep); product pages (drop)
KEEP: 121537464, 121538241, 121539977, ...
Enter fullscreen mode Exit fullscreen mode

Note this already does the thing everyone recommends: the reasoning comes before the answer. It did fix an earlier failure where the model decided everything on its first token.

Those five runs above are this format. Agreement 0.23.

So "make it reason first" was not the fix, and that's the interesting part.

Why explaining itself didn't help

Because it was still being asked one vague question: "what kinds of page are in these 200, and which do you want?"

That question has a dozen defensible answers. Is a blog archive a useful index or a duplicate listing? Are these product pages or catalogue sections? Nothing in the input forces one answer, so the candidates sit nearly tied — and we just saw who wins a nearly-tied race.

Then it got worse. Having written its verdict, the model produced a list of ids to match. It never actually checked each URL against its own policy; it generated a plausible-looking list. So one wobble early in that list and the whole thing runs away — which is why the counts aren't scattered around some average but pinned at either end: 200 or 8, keep everything or keep nothing.

The fix: one line per URL

Same prompt, same rules, same input. Only the reply format changed — every URL gets its own line, naming the rule that decides it, then the label:

121537464   section root or home page   KEEP
123719513   an individual product page  DROP
121943638   tag or topic archive page   DROP
Enter fullscreen mode Exit fullscreen mode
keeps per run — same 200 urls, five runs, one block = 10 pages

  one question per batch           one question per row
  200  ████████████████████        153  ███████████████
   15  █▌                          155  ███████████████
    8  ▊                           154  ███████████████
  200  ████████████████████        152  ███████████████
   16  █▌                          154  ███████████████

  agreement 0.23                   agreement 0.99
Enter fullscreen mode Exit fullscreen mode

Rows that disagreed between runs went from 195 of 200 down to 4.

What changed is the difficulty of the question. Instead of one vague question about 200 things, the model now answers 200 easy ones: "this URL — what is it?" Shown /tag/fitness/, there is essentially one right answer. The candidates aren't tied, so the wobble has nothing to flip.

That's the whole trick. Not more thinking — easier questions.

And the order inside the line matters as much as the line itself. Put the label before the rule — <id> KEEP <rule> — and the label is written with nothing in front of it but an id, so it's as much of a coin toss as the id list was. Only when the rule comes first does the label have something to follow from. Here's the same decision in all three shapes, and how far apart each one pushes the two leading candidates:

The same decision in three output formats

(The probabilities in both animations are illustrative — the proxy I call doesn't return them. The agreement numbers in this post are measured; the label-first format was not one of the arms I ran.)

What it doesn't fix

The 200 questions aren't independent, and this is the part to be clear-eyed about.

Once the model has written tag or topic archive page → DROP on row 12, writing the same thing on row 13 is simply the most likely continuation. It isn't re-deciding. It's copying itself.

So similar pages now move as a block. On a second batch — 200 vacation-rental pages — agreement only went from 0.28 to 0.62, and here's where two runs split:

                        row 13 — the first regional page
                        │
 row     1 ·········· 12│13 ······················ 64    65 ·····
 run 1   D D D D D D D D│D  D  D  D  D  D  D  D  D  D    ...
 run 2   D D D D D D D D│K  K  K  K  K  K  K  K  K  K    ...
                        │
         agree on every │ 51 pages move on one token here,
         property page  │ and each run then sticks to its own call
Enter fullscreen mode Exit fullscreen mode
run 1:  regional listing page, a catalogue of individual properties   DROP
run 2:  destination or regional section, location category            KEEP
Enter fullscreen mode Exit fullscreen mode

Both readings are defensible — which is the point. The prompt never said which one a regional page is, so that one question stayed vague, and 51 pages rode on it. Runs 2 to 5 all agreed; run 1 was alone.

This gives you a precise diagnosis, though: if a category still flips, your prompt never said what to do with it. Go name it. I did that for one ambiguous category and it held across all five runs.

It carries wrong answers just as faithfully

Same mechanism, pointed the other way.

On a recipe blog, one batch latched onto a company-authored blog about its business for the first recipe it hit — a rule meant for something else entirely — and then applied it to 105 recipes in a row. Recipes were explicitly excluded three lines earlier in the prompt. The other fourteen batches got it right and kept between 0 and 9 pages each.

If the model were really reasoning, 105 contrary examples should have talked it out of the rule. It never wavered. The rule isn't a conclusion it keeps testing — it's a commitment it keeps repeating.

So be honest about the trade: consistency is not correctness. You're swapping many small scattered errors for a few big correlated ones. For me that's worth it, because a correlated error is visible — 105 identical rule strings in a column is impossible to miss, where 105 scattered ids in a keep-list looks like nothing at all. But if your downstream can't survive a whole batch being wrong together, think twice.

What it costs

Output tokens went from ~800 per 200 rows to a steady ~3,600–4,600. Input is unchanged. Call it twice the price per call.

The steadiness matters as much as the average. The old format ranged from 108 to 2,153 output tokens, and the 108-token replies were the broken ones — the model deciding in four words that there was nothing worth keeping.

When to reach for this

Use it when you're labelling many items in one call and you need the same input to produce the same output: batch classification, extraction with per-field decisions, anything where you'll compare today's run against last week's.

Don't bother for a single judgement per call. There's no list for the model to stay consistent with, and you're paying for prose nobody reads.

And if you've already got the model explaining itself and you're still seeing variance — check whether that explanation is attached to the batch or to the row. Mine was attached to the batch for weeks, and it looked like reasoning the whole time.

Top comments (1)

Collapse
 
promptalo profile image
PromptAlo •

That row level rule is worth keeping where the batch job reads it on every run. If it only lives in the article, the next job can slip back to one verdict for the whole list.