Skip to main content

Anatomy of a Triage Prompt

Why This Matters

Before you measure a prompt, you need to know what each part is for. Most prompt bugs are structure bugs: evidence mixed with instructions, the question buried under a 400-line log, or two rules that quietly contradict each other.

The parts

Open src/prompt.ts. TestPilot’s request has six parts:

PartWhereExample
RoleSystem prompt“You are TestPilot, an assistant that helps a QA team triage failed automated tests.”
TaskSystem prompt“Decide the most likely cause.”
DefinitionsSystem promptWhat product_bug, test_bug, flaky, environment and unknown mean
RulesSystem promptQuote evidence exactly; prefer unknown over a guess; never invent log lines
EvidenceUser message, in XML tags<run>, <test>, <error>, <log>
QuestionUser message, last line“Triage this failure.”

Stable parts (role, task, definitions, rules) go in the system prompt; they are the same for every failure, which also makes them ideal for caching (lesson 14). Variable parts (evidence) go in the user message.

The 4D framework, applied to TestPilot

Anthropic’s AI Fluency material describes four competencies for working with AI, the “4D framework”. Exam questions may use the terms, so know how they map onto what you build:

DMeaningIn TestPilot
DelegationDeciding what to hand to AI and what to keepAI advises on failures; pass/fail and ticket creation stay with code and people
DescriptionTelling the model clearly what you wantThe six prompt parts above, definitions and examples
DiscernmentJudging the output criticallySchema validation, golden set, scorecard, evidence quotes checked in code
DiligenceTaking responsibility for use and resultsHuman approval for actions, tracing, telling the team the verdict is AI-generated

Why evidence goes in XML tags

<error>
expect(received).toBe(expected)
Expected: "€90.00"  Received: "€100.00"
</error>
<log>
GET /api/cart 200 {"subtotal":100.00,"discount":0,"total":100.00}
</log>

Tags do three things:

  1. They separate data from instructions. The model can tell “this is a log line” from “this is what I am asked to do”.
  2. They make references precise. Rules can say “quote from <log>” and you can check that the quote is really in that section.
  3. They contain hostile text. A log line that says “ignore all previous instructions” stays a log line inside <log>. Tags are not a complete defence (module 7), but they are the first layer.

Order matters

Put the long evidence first and the question last. With a long log above it, the question at the end is the freshest thing the model reads. A question at the top followed by 400 lines of log is easier to lose.

Long logs

A CI log can be thousands of lines. Sending all of it costs tokens and buries the one line that matters. Trim in code before you send:

function aroundError(log: string[], errorLine: number, context = 20): string[] {
  const from = Math.max(0, errorLine - context);
  return [
    ...(from > 0 ? [`[${from} earlier lines omitted]`] : []),
    ...log.slice(from, errorLine + context),
  ];
}

Always say what you trimmed. A model (and a human) that knows lines were omitted will treat the gap as “unknown”, not as “nothing happened”.

Exercise

Here is a deliberately messy system prompt. Find the two rules that contradict each other and the one that belongs in code instead:

You are a QA expert. Always give a definitive category, never answer unknown.
Base your verdict only on the evidence. If the evidence is unclear, say unknown.
Count the failures in the history and call it flaky if more than 2 of 10 failed.
Be concise.

Rewrite it with the six parts from this lesson.