· AI

The prompt contradicted itself

A routing prompt of mine got 37 of 60 test cases right. After I removed a contradiction between two of its rules, the same model got 59. How I found the conflict, the fix, and an edit along the way that broke the output format instead.

Before the change, my routing prompt sent 37 of 60 test messages to the right place. After it, 59 of 60. The model, the hardware and the test cases were the same. All I changed was the prompt, and what I changed was a disagreement between two of its own rules.

Here are the full numbers, from three runs over 20 cases with a small local model.

| Measure | Before | After | |---|---|---| | Routed to the right agent | 37 of 60 | 59 of 60 | | Paraphrases held out of the editing | 28 of 42 | 41 of 42 | | Valid JSON | 59 of 60 | 60 of 60 | | Response time, 95th percentile | 2.9 s | 1.5 s |

What the router does

Every message that reaches my assistant goes first to a small model with one job. It reads the message and returns a small JSON object naming which agent should handle it. The system prompt lists the agents and what each one is for. There is also an UNKNOWN option for requests that nothing handles. I argued for that exit in February, when I wrote that a model with no way to decline will force every input into a category.

This is the kind of narrow, repetitive task small models are suited to, so 37 of 60 was a bad result.

How I found it

I did not go looking for a prompt bug. On August 14 I was comparing five local models to see whether a different one would route better. I ran each against the real system prompt and the real parsing code, on twelve cases, eleven of which have a correct agent.

Four of the five landed close together: 9 of 11, 9 of 11, 10 of 11 and 8 of 11. The fifth scored 3. What caught my attention was the pattern in the misses. The models that did well were missing the same cases.

Different models, with different training, failing identically on the same inputs is evidence about the inputs. When every model fails the same case, look at the prompt before you look for another model.

The contradiction

It was there in plain text once I read the prompt as a set of rules that might collide.

The description of UNKNOWN listed the kinds of request no agent handles. Calendar management was on that list. So a calendar request should come back as UNKNOWN.

Further down, a section headed ROUTING PRIORITY said that any actionable message that is not a greeting goes to the general task agent. And that agent's own description said it handled "ANY actionable task," with the capitals.

A calendar request is actionable. One rule said UNKNOWN and another said the task agent. The prompt gave no order of precedence, so the model had to pick, and every model I tested picked the more emphatic rule. The capitals did what capitals are for.

Each rule was sensible when read alone. I had not read them together.

The fix

It was three changes.

  1. An explicit order. The priority section became a numbered list that the model works through from the top, stopping at the first match. Specialist agents come first. The domains nobody handles come second and return UNKNOWN. The general task agent comes last.
  2. A narrower claim. The task agent's description now says what it really does, which is shell, file and deployment work. The word "ANY" is gone.
  3. The output format moved to the end. The JSON shape, with a literal example, is now the last thing in the prompt.

The first two removed the conflict. The third came from a mistake I made while fixing it.

The held-out row in the table is there to check my own work. I edited the prompt against the 20 cases, so a prompt that does well on them might simply be fitted to them. The 42 paraphrase runs use wordings I did not look at while editing. They moved from 28 to 41, which tells me the rules improved and I had not just tuned the prompt to twenty examples.

The drop in response time was a side effect I did not aim for.

Routing results before and after the prompt fix
Before

Two rules claimed calendar requests and no order was given

Right agent: 37 of 60

Held-out paraphrases: 28 of 42

Valid JSON: 59 of 60

After

Numbered priority list that stops at the first match

Right agent: 59 of 60

Held-out paraphrases: 41 of 42

Valid JSON: 60 of 60

Three runs over 20 cases with a small local model. The model, the hardware and the test cases were the same.

The edit that broke the format

One of my edits along the way appended routing examples to the end of the prompt, to show the model the hard cases.

The output broke. In five of six runs, the JSON came back with a nested key missing its opening quotation mark. That is one character, and it is fatal to a parser.

The cause was position. The output format had been the last instruction in the prompt. My examples pushed it up into the middle, and the model's grip on the exact shape loosened. There is research consistent with this. A 2023 study of how language models use long contexts found that "performance is often highest when relevant information occurs at the beginning or end of the input context." My prompt is short by those standards and my model is small, so I would not lean on the paper too hard. The observation matched, though. In my prompt the format instruction was followed exactly when it came last and loosely when it did not.

What makes this dangerous is what my code does with bad JSON. The parser pulls out the outermost braces and tries to load the result. When that fails, it returns UNKNOWN. It raises no error. So an edit meant to improve routing would have sent most messages to UNKNOWN, and from the outside each one would have looked like the model declining politely.

It also failed five times in six, which means it passed once. I wrote in February that a single run hides this kind of failure. If my one test run had been the lucky one, I would have shipped it.

So the rule I now follow has two parts. The prompt ends with the literal output example, and any edit that adds text gets checked to make sure the example is still last. And validity is scored over several runs, separately from correctness, every time the prompt changes.

What I would check in any prompt

Read it as a rulebook. For each test case, list every rule that applies. If two apply and give different answers, you have found a bug that no model will fix for you.

Search for the universal words: any, all, always, never. Each one claims the whole territory, including the parts another rule was written to cover. Capitals and "IMPORTANT" do the same thing louder.

Give the rules an order. If two can match the same input, say which wins.

Make a parse failure a different outcome from a real "none of these." Mine were the same value, which is why a format bug could pass as a routing decision. Where the runtime supports it, constraining the output to a schema removes the syntax errors altogether. Ollama, for one, accepts a JSON schema in the request and recommends also putting the schema in the prompt.

One caveat. All of this was measured on one prompt, one task and a handful of small models. The numbers are specific to that setup, and I would expect only the method to carry over.

The prompt is mine to maintain, and both of the rules that collided were mine. A prompt change is also a code change. The service that loads this prompt holds it in memory, so the new version took effect only after I deployed it and restarted that service.

Views are my own.