Skip to main content

Read the Request, Then Send It

Why This Matters

Testers read the test before they trust its result. Do the same with an API call: know every field you send before you judge what comes back. Most surprises in Claude applications are not in the answer; they are in a request nobody looked at closely.

The request, field by field

Open src/triage.ts. The whole call is one function:

const message = await client.messages.parse({
  model: options.model ?? DEFAULT_MODEL,
  max_tokens: options.maxTokens ?? 1024,
  system: SYSTEM_PROMPT,
  messages: [{ role: "user", content: buildTriageMessage(run, result) }],
  output_config: { format: zodOutputFormat(triageResultSchema) },
});
FieldWhat it doesWhy TestPilot sets it this way
modelWhich Claude model answersA capable default, overridable with TESTPILOT_MODEL
max_tokensUpper limit for the output tokens, including any thinking: current models think by defaultLeave room: lesson 11 shows a verdict cut off at 1,024
systemInstructions that apply to the whole conversationRole, categories and rules (lesson 10)
messagesThe conversation so farOne user message with the evidence
output_config.formatThe shape the answer must haveA schema your code can validate (lesson 9)

The same request in the Console Playground

Build the request by hand in the Playground and read it before you run it: model, system prompt, the user message with evidence in XML tags, and the model settings.

The Console Playground with TestPilot’s system prompt, the t-002 discount failure as the user message, and the model settings panel open

Switch to Code and you see the request as code: the same fields as src/triage.ts.

The same request shown as TypeScript code with model, max_tokens, system and messages

Predict first

Before you run anything, write down your own verdict for each failure in fixtures/runs/run-1042.json:

TestYour verdictWhy
t-002 discount
t-003 login button
t-004 search suggestions
t-005 payment
t-006 avatar upload

Predicting first turns the run into a test of the model, instead of letting the model’s answer anchor your opinion.

Run it

Press Run in the Playground. Claude cites the evidence, just as the system prompt asked.

The rendered response: numbered evidence quoting the error, the cart API response, the passing history and the pricing commit

Then run the whole fixture from your terminal:

npm run triage

This is a real run on run-1042:

npm run triage output: product_bug 0.80 for the discount test, test_bug 0.90 for the renamed login button, flaky 0.80 for the search timing race, environment 0.92 for the OOMKilled payment sandbox, and unknown 0.10 for the avatar upload

Compare it with your predictions. Notice three things:

  • Every verdict cites the evidence: the cart response, the renamed label, the 640 ms response time, the OOMKilled pod.
  • Confidence follows the evidence. 0.92 for an outage with a health check and a pod event; 0.10 for the avatar test, where there is nothing to go on.
  • The avatar test says unknown. That is the system prompt’s “prefer unknown over a confident guess” at work. Lesson 10 shows what happens without it.

Read the response, not just the answer

Switch the Playground response to Raw and look at what your code receives:

The raw JSON response with stop_reason end_turn and the usage block: 257 input tokens, 1,074 output tokens of which 188 thinking tokens, about $0.02 and 11.2 seconds

  • stop_reason: why the model stopped. end_turn means it finished; max_tokens means it was cut off and your answer is incomplete.
  • usage: input and output tokens, including tokens spent thinking and any cache activity. This is what you pay for.
  • The footer: the cost and the time of this single request.

Notice that this free-text answer is long: over a thousand output tokens for one failure. Lesson 9 fixes that.

Exercise

docs/exercises.md, lesson 8: compare TestPilot’s five verdicts with your predictions. Which one do you disagree with? Write down why, using only the evidence in the fixture. Keep your notes; you will need them for the golden set in module 3.

Show suggested answers

What the evidence in run-1042.json supports:

TestVerdictDeciding evidence
t-002 discountproduct_bug"applied":true but "discount":0, right after the PricingService refactor
t-003 logintest_bugThe button is now “Sign in” (en.json changed in the same commit); the test still looks for “Log in”
t-004 searchflakyFailed 3 of the last 8 runs; the suggestions arrived 640 ms after the assertion
t-005 paymentenvironmentECONNREFUSED, sandbox health check 503, pod OOMKilled
t-006 avatarunknownNo history, no log, a generic toBeTruthy message

The two that are worth disagreeing about:

  • t-004: flaky or test_bug? The timing makes it intermittent, but the root cause is a test that asserts before the data is there. “Flaky” describes the symptom, “test_bug” the fix. A good answer names both in the summary and picks the category your team acts on.
  • t-003: test_bug or product_bug? Only if the rename was intended. The evidence says the label was changed on purpose in en.json, so the test is outdated. If nobody meant to rename the button, it is a product bug. The model cannot know intent; that is exactly the kind of case a human confirms.