Liuma Research · Prompt debugging

Prompt debugging: tracing a failed run to two Chinese characters

We suspected the data-processing rules, the plotting instructions, and the reminder to inspect the original file. What surfaced was a single word in the first sentence of the system prompt.

Liuma team
Illustration. System-prompt passages are on the left, successive model outputs in the middle, and a verifiable failure on the right. Wider lines indicate stronger attribution.

Which part of the prompt would you change?

  1. Halfway through a task, your agent makes a claim you know is wrong.
  2. You open the system prompt. It has more than two hundred passages. Someone had a reason for adding each one.
  3. You suspect passage A. Your colleague points to B.
  4. Testing either hunch means running the whole task again. Each run takes tens of minutes, and the model can give a different answer each time.
  5. By the end of the afternoon, the pass rate has moved a point or two. You still can’t say which edit made the difference.

Here’s the failure that sent us looking. An agent fitting a spectrum averaged the data in bins. It looked at those averages and declared that the entire spectrum had only one peak. The data contained two.

We suspected the data-processing rules, the plotting instructions, even the line telling the agent to inspect the original file. None of us had picked the passage that surfaced in the experiment.

Which part of the context influenced the answer?

A production agent sees the system prompt, descriptions and instructions for dozens of skills, tool descriptions, retrieved memories, and dozens of turns of its own writing. People keep adding to every layer. Across tasks, the number of passages to maintain can reach the hundreds of thousands.

  • Add an instruction. “Always check the units.” That might fix this case. The prompt gets longer, and the original failure remains unexplained.
  • Run an ablation. Remove one passage, rerun the task, and compare. This directly tests the edit, but the cost grows with the number of passages. Variation between runs also calls for repeated samples per configuration.
217passages in the system prompt
1,584preceding passages in one failed run
10–38minutes per full run

Each square stands for a full run with one passage removed. Testing just the system prompt once per passage can take about three days for a single case.

Use ablation to test a specific edit

We call this way of debugging prompts ForkDiff.

Think of the failure as a node in a directed acyclic graph. An immediate predecessor can be something the model wrote earlier, or a passage supplied to it. Starting at the error, we follow the strongest attribution upstream until we reach text we can edit.

  1. Start with the earliest verifiable error. Prefer a false statement of fact, then a wrong conclusion, then a decision that sends the work off course.
  2. Trace earlier model output in turn. The immediate lead is often a sentence the model itself wrote. That sentence has its own history.
  3. Stop at supplied text. A passage from the system prompt, a skill, or a tool description becomes a candidate. At this point it is still a hypothesis.
  4. Test the edit on the target model. Rerun the original task with the selected change. Find the earliest verifiable error in the new trace and repeat until further tracing yields no improvement.

This is a tree search. Starting from several errors at once lets the same search run in parallel.

What a sensitivity score can tell you

We first tried a one-sided measure. Which earlier passages was the model most sensitive to when it produced the wrong sentence? We compared that ranking with eight experiments in which we removed one passage at a time.

One-sided sensitivity

Removing passage #129 had the largest effect.
Removing passage #30 had the smallest.

Following the strongest path to its end led to a harmless instruction about which workspace directory to start in.
ForkDiff

Line 3 of the system prompt surfaced.

It ranked first among all system-prompt passages.

We paused the trace at the earliest point where we could show that the model had gone wrong. We kept everything it had seen before writing that sentence. We then prepared two continuations. One was the mistaken judgment it actually wrote. The other was a judgment better supported by the evidence available at that moment.

Using the same white-box model, we backpropagated through each complete continuation. For each preceding passage we compared the two sensitivities. Which judgment did the passage favor, and by how much? We reviewed passages that favored the error first. Once we had chosen an edit, we gave the original model the task again from scratch and checked both the reasoning trace and the submitted answer.

One word in the agent’s job description

The model had read 662 input passages by the time it made the first error. The figure shows selected inputs on the left and the model’s actual words on the right.

Backpropagation target T7Thicker lines indicate higher scores
Model input 662 passages
Reasoning · T7 · #1+1.486

Wait — maybe x is not the Raman shift axis but rather something like wavelength-derived…

Traceable
Reasoning · T4 · #2+0.763

Wait maybe x is actually in cm^-1 but it's the "Raman shift" computed wrongly?…

Traceable
Model’s script · T5 · #4+0.645

# coarse profile: mean intensity in 20 bins by index

Traceable
System prompt · L283 · #45+0.056

Device name=Raman-Windows

System prompt · L3 · #29 Selected+0.112

You are the user’s long-term personal AI adviser…

Model output T7 · reasoning
T7Erroneous claim

…So only one real local maximum structure at the low-x end (around 1650+), i.e., outside the file.

174 system-prompt passages in line order ▲ L3
Measured scores, rearranged for display. Earlier material ranked ahead of any system instruction, including the model’s own script for computing the bin averages. The first system-prompt passage was line 3, ranked 29th overall.

Line 3 opens the identity statement. It precedes all the instructions, appears in every request, and had never made our shortlist. The Chinese word 幕僚 (mùliáo) means a staff adviser. In translation, the sentence reads:

You are the user’s long-term personal AI adviser. Communicate as a colleague, with a stable identity and continuous memory.

We thought we had made a calculation error. We broke the sentence down into tokens and calculated their contributions separately.

Two tokens accounted for roughly two-thirds of the signal in the sentence.

For the rerun we changed only the role word, replacing “adviser” with “assistant.” Here is the edit in the language the model actually saw:

- 你是用户长期协作的个人 AI 幕僚,以同事的方式沟通……+ 你是用户长期协作的个人 AI 助手,以同事的方式沟通……

We checked the first request sent to the model. The task, tools, and model parameters matched. Aside from session paths, IDs, and timestamps, the only difference was those two characters in the system prompt.

The one-peak claim disappeared in the rerun. This time the model searched the smoothed curve for local maxima and found both real peaks by turn 14.

Why might the word matter? Our working hypothesis is about the role. An adviser is expected to offer a judgment. When evidence is thin, “assistant” may leave more room to keep looking. This experiment didn’t establish that explanation.

Then, on turn 39, the agent used the wrong horizontal axis. Its final score was still 1/3.

The next wrong turn

Removing one error let the agent reach a different decision. That is how the search tree acquired its second round.

Error tracedCandidate for reviewPassage selectedEdit testedHuman selection

At turn 39 the model decided to use the file’s raw horizontal axis and swapped the labels on the two peaks. Attribution was more diffuse this time. The first 168 passages included the model’s reasoning, the task text, and the output template. The highest-ranking system instruction came in at #169. It told the agent to use a fixed four-step procedure for every substantive message.

Only the opening sentence surfaced. After reading the surrounding text, we selected the whole section. We moved the procedure into a skill the model could load when needed and left a one-line pointer in the system prompt.

Round 2 · Same model and task, one run per condition
Procedure always presentProcedure loaded on demand
Recognized the axis conversionRequest 24Request 12
Final score2 / 33 / 3

Neither edit had been on anyone’s list. One changed a single word in the identity statement. The other moved a procedure the team had considered particularly thorough.

Where the reruns went

With an exhaustive search, you remove each passage, run the full task, and compare scores. With ForkDiff, most of the search happens before you commit to a rerun.

The estimate covers only the 217 system-prompt passages, with one 10–38 minute run per passage. The ForkDiff count covers the validation reruns for the two selected edits. It excludes exploratory runs while we were developing the method. One backward pass over all passages took about 2.5 minutes.

Passage-by-passage ablationForkDiff
SearchList the passages you suspectRank all preceding passages, including the model’s own words
Full runsOne or more for each candidateOne validation rerun per round in this case
Size of editRemove the whole passageDown to token level. We replaced one two-character word.
Outcome to inspectThe final score, which varies between runsThe specific wrong turn and whether it recurs
Unexpected candidatesThe test covers passages you chose to tryBoth edits came from outside our shortlist

The choice of outcome mattered. The same prompt scored both 1/3 and 2/3 on this task. Separating an edit’s effect from that variation using the final score alone would take many runs. With a particular failure in hand, we could ask a narrower question and answer it from one trace. Did the model claim there was only one peak again?

The size of the edit mattered too. Removing the whole identity statement would change several instructions at once. Tracing the signal down to 幕僚 let us test a one-word change.

What the experiments establish

  • Two different models. We calculated attribution on an open-weight model. The production agent used another model. Only a rerun on that target model could tell us whether a candidate carried over.
  • One run per condition. The old prompt scored both 1/3 and 2/3 across runs. The 3/3 was one observation. Estimating a pass rate would require more runs.
  • Time limit. Both configurations missed the task’s original 15-minute deadline. The runtime spent time persisting streamed events one by one, independently of the prompt change.
  • Checklist regression check. We replayed three production requests for which the agent had spontaneously created checklists, using a different model. Both prompt versions produced checklists in five of six runs. In 30 days of production traffic, the skill was never loaded in 208 sessions, yet 80 of those sessions created a checklist. The tool description and session reminders also gave the model instructions for creating one.

Both edits have been merged. Reliable completion within the deadline is still open. What this case demonstrates is how we chose where to edit and what we checked afterward.