Skip to content
The AI Agent Factory

24.8 Integration layer or model output

Approved by
Panaversity ·
15 min read

In everyday life. A restaurant guest gets the wrong dish. Before anyone blames the cook, the head waiter reads the order slip. If the slip says "fish" and the guest asked for chicken, the cook did the job right from a wrong slip. If the slip says "chicken" and fish came out, the fault is in the kitchen. The plate looks the same both ways. In this concept, the slip is the request your code sends, the cook is the model, and the plate is the answer.

What you will learn. How to tell a fault in your own code from a fault in what the model wrote. You practice it in Lab 24, Tasks 5 and 6.

  • What are the two places a failure can begin?
  • Is every integration fault a 400?
  • How do you tell the two apart?
  • What do you check in the integration layer?
  • What does reading the request first cost?

Why it matters. A builder who blames the model changes the prompt. If the fault is in the code, the prompt change repairs nothing and can break something else.

At work. Ana knows INV-8303 well, because it was one of her first cases (17.6). The invoice is $900.00 over its purchase order, PO-7003 (24.2). One of the recorded runs you read in Lab 24 holds an answer about INV-8303 that Ana had marked fail earlier. The answer compares the invoice with a different purchase order.

The builder's first guess is hallucination: the model made up an order. The builder checks before saying so. The API returned status 200, and the stop reason was "finished". Then the builder reads the request the code sent. It holds the purchase order of the invoice that was extracted just before INV-8303, and not PO-7003. The model read that order and reported it correctly. The fault is in the handoff, where the extraction step passes its result to the next step. It began in the code.

What are the two places a failure can begin?

The integration layer is all the code around the model. It builds the request, lists the tools, keeps the message history, runs the tools, and passes one step's result to the next. Model output is what the model wrote in reply. A failure begins in model output only when the request was right and the answer is still wrong. The exam guide asks you to isolate which of the two a failure began in.1

Is every integration fault a 400?

No. 21.9 said that integration faults show up as errors with a 400, and model faults as normal responses with wrong content. Those integration faults were the ones the API rejects. This one it accepts. The API checks the shape of a request. It cannot know that a request with a correct shape carries the wrong purchase order. So the response is a 200 with wrong content, which is exactly how a model fault looks.

The official pages give another case. A response that ends "finished" with almost no content can come from code that adds text after the tool results, or that sends a finished response again.2 From outside it looks like under-acting. It began in the integration layer.

How do you tell the two apart?

Read in this order, and stop at the first fault you find:

  1. The status and the stop reason. An error such as a 400 means the API rejected the request, so the fault is your code's (21.9). A "declined" stop reason is the model's own answer (21.3).
  2. The request, as it was sent. Read the recorded request, and not the code that should have built it. Ask whether everything the answer needed is there, and whether it is right. That means the instructions, the tool list, the history, the tool results, and every value handed over from an earlier step.
  3. The output. Only when the request was right is a wrong answer a fault in model output.

The approver answer in 24.7 went through the same three steps. The request carried line 8 with "before payment", so that fault was in model output.

A reproduction confirms it. A reproduction is the recorded request sent again, to watch the failure happen again. Correct the one wrong value in the request and send that too. If the answer is now right, the request was the fault.

Figure 24.5. The same wrong answer twice: once from a wrong request sent by the code, and once from a right request answered wrongly by the model.

What do you check in the integration layer?

Four layers of your own code, and then the handoff between steps. The exam's prep course has a debugging task with four planted defects, one in each of four layers. All four are in the integration layer.3 Use them as a checklist before you blame the model:

LayerA defect thereHow it looks from outside
The tool's schemaA tool description of two wordsThe model picks the wrong tool
The streaming codeA turn saved before the stream is complete (21.11)A half-built tool call in the history, and the API rejects the next request
The message historyA tool result with no turn that asked for itThe API rejects the request
The memoryEvery earlier session put into the contextThe context window fills, and the worker seems to forget

Two of the four end in a rejected request. The other two look like the model's fault: a wrong tool, and a worker that forgets. The fix for the first is in the description. The official troubleshooting page says to tell two similar tools apart by when each should be used.4

Brightline adds a fifth place to check: the handoff between two steps. Of the four test levels in 24.3, this is the integration level.

What does reading the request first cost?

It costs a little time on every failure, and it needs the request recorded with its content (24.7). It also does not prove the model right. Sometimes the request is right and the model is wrong, as with the approver answer.

The operating rule: read the status, then the request as sent, then the output. Blame the model only for a wrong answer to a right request.

Do this now. Ask your coding agent for the last request. Copy this line:

Show me the exact request the worker sent on its last run: the instructions, the tool list and every message, with nothing summarized.

Find one value in it that an earlier step of your code produced. That value is a handoff. Say what the model would answer if it were wrong.

Check yourself

Question 1 / 8

0 answered

The answer about INV-8303 names the wrong purchase order. What showed that the code was at fault?

  1. Claude Certified Developer - Foundations Exam Guide, version 1.1, Anthropic.↑
  2. Stop reasons and fallback, Anthropic.↑
  3. Claude Certified Developer - Foundations prep path, Module 2, Cumulative Debug Task, Anthropic.↑
  4. Troubleshooting tool use, Anthropic.↑
Owner
Panaversity