← Harness Engineering From First Principles

Tool Schemas as Cognitive Interfaces

Hold task and model fixed while varying tool interfaces; count invalid actions and recovery attempts.

Chapter 4 ended with a defect that no evaluator could have caught by looking at evidence. In the original Project 01 lab, the citation contract required each answer to quote a file’s full 64-character SHA-256 digest. The tool output showed the model only the first 12 characters. The positive-path tests passed because the scripted responder took the full hash from the fixture store, out of band, and not from anything a model could see (docs/research/HARNESS-PROJECT-01-REVIEW/REVIEW.md, P01R-01; OBSERVED, Critical). The evidence pipeline was consistent and the evaluator was strict, yet the task as presented could not be completed.

This chapter asks what a tool interface is for a language model, and why designing one is a separate engineering problem from implementing the function behind it. The short answer is that, for the model, the interface is the world. The tool names, descriptions and parameter schemas are everything the model knows about what it can do. The tool results and error messages are everything it learns about what happened. A harness that gets the function right and the interface wrong has built a correct system that nothing can use correctly.

Evidence status. Draft manuscript. Code excerpts are from the Project 01 working-tree candidate (examples/pi-harness-lab/src/tools.ts), which carries uncommitted corrections. Independent re-review of that candidate (HARNESS-PROJECT-01-REVIEW-02) is complete with verdict REJECT (2026-11-23). Nothing in it is accepted; §5.4’s code observation stands as inspection-only and its model effect is untested. The §5.7 interface-cost accounting is executed through the real tool handler (D01-WALKTHROUGH: 2 invalid actions, 2 recovery attempts, 92 bounded error bytes of 1102 total, 4 calls charged). Observations marked “source inspection” are this chapter’s own reading of that code, not review findings and not test results. External studies are DOCUMENTED and report what their authors found; none is replicated here. The live-model interface comparison in §5.8 is EXPERIMENT PENDING.

5.1 Two audiences for one interface

Every tool has two readers. The model reads the name, the description, the parameter schema, the result text and the error text, and uses them to decide what to do next. The host reads the same call as structured arguments, decides whether to execute it, executes it, and charges it against a budget. Ordinary API design has mostly one audience at a time: a programmer reads documentation, and a runtime enforces types. A tool interface for an agent serves both audiences in the same moment, and it can fail either one independently.

Interface element What the model uses it for What the host must enforce Project 01 example
Name Choosing an action Only admitted names execute fixture_list, fixture_read. Literal names; no +name modifiers (R02 C02)
Description Understanding when to use it Nothing: descriptions are advice “Read numbered lines from one fixture file by fileId and 1-based inclusive range.”
Parameter schema Forming arguments Shape, types, bounds, unknown keys fileId string; startLine, endLine integers; no additional properties
Result format Extracting facts and citation data Byte limits; no ambient data Header line with display path, file ID, full digest and range, then numbered lines
Error vocabulary Deciding how to recover Stable codes; no paths, stacks or secrets UNKNOWN_FILE_ID, INVALID_RANGE, RANGE_OUT_OF_BOUNDS, RANGE_TOO_LARGE, BUDGET_EXHAUSTED, INVALID_ARGUMENTS
Budget behaviour Knowing when to stop Every attempt is charged Exhaustion returns a bounded diagnostic and is itself charged

The table makes one asymmetry visible. Some elements are read by the model but enforce nothing; the description is the clearest case. Others are enforced by the host whether or not the model understands them. A great deal of fragile agent engineering consists of putting an enforcement requirement into an advisory element, such as “only read files under src/” written in a description. That is the prompt-as-policy antipattern of Chapter 1, appearing at the scale of a single tool.

5.2 The producibility principle

P01R-01 suggests a principle that is simple to state and easy to violate:

Producibility. Every value that the acceptance oracle requires in an answer must be derivable from information the model can actually see through the interface, under the admitted budget.

The original lab violated it in a way that is typical, not exotic. The digest was shortened in two places in tools.ts, probably to save bytes and make the output more readable: the catalogue used slice(0, 12), and so did the fixture_read header (P01R-01 locators). The evaluator, written separately, demanded exact equality with the full digest. Each component was reasonable on its own. The contradiction existed only in the composition, and the only test that composed them used a responder that did not depend on the interface.

The candidate’s current catalogueText and fixture_read header emit the full contentSha256. The first corrective re-review observed full digests in both tool responses (INDEPENDENT-REREVIEW.md; OBSERVED). The more general corrective, though, is a testing rule rather than a code change. A positive-path test must succeed using only model-visible bytes. If a scripted responder may consult the fixture store, the oracle or the manifest directly, then the test is checking the evaluator, not the interface. In practice the scripted responder should be built from the tool transcript alone, which is what the corrected lab README claims for its finite responder (“constructs facts and citations from the actual tool transcript”). That remains an implementer claim: independent re-review is complete with verdict REJECT, and the zero-tool finding in §5.4 shows the responder path could still supply an answer that no tool call produced.

Producibility also covers the budget. A citation that is derivable only by reading a whole file, when the byte budget admits half of it, is not producible either. Chapter 3’s contract and this chapter’s interface have to be designed together.

5.3 Two layers of validation, and why both exist

The candidate validates fixture_read arguments twice. The Pi wrapper declares a TypeBox schema that rejects unknown properties:

// examples/pi-harness-lab/src/tools.ts (working-tree candidate)
parameters: Type.Object(
  { fileId: Type.String(), startLine: Type.Integer(), endLine: Type.Integer() },
  { additionalProperties: false },
),

The pure handler behind it then checks again, with no reliance on Pi:

// examples/pi-harness-lab/src/tools.ts (excerpt of readResult)
if (!isArgumentsObject(rawArgs)) { /* INVALID_ARGUMENTS */ }
const keys = Object.keys(rawArgs);
if (keys.length !== 3 || !keys.includes("fileId")
    || !keys.includes("startLine") || !keys.includes("endLine")) { /* INVALID_ARGUMENTS */ }
...
const start = toLineNumber(startLine);   // Number.isSafeInteger, else null
const end = toLineNumber(endLine);
if (start === null || end === null || start < 1 || end < 1 || start > end) {
  return { ok: false, code: "INVALID_RANGE", message: "range must be 1-based integers with start <= end" };
}

isArgumentsObject rejects arrays, null, and objects whose prototype is neither Object.prototype nor null. File IDs are looked up in a Map, so __proto__ cannot reach an inherited property.

It is tempting to call the second layer redundant. It is not, and the reason is structural. The two layers answer different questions. The schema is part of the model-facing interface: it tells the model what shape to produce, and it lets the runtime reject malformed calls early. The handler is the enforcement point, and it is unit-tested without Pi (the file’s header says so). Pi 1.6.0 also allows extension hooks that block or mutate tool calls, and the R02 audit records that tool input is not revalidated after mutation (R02-PI.md C12; DOCUMENTED/OBSERVED; Established for the inspected artifact). A handler that trusted the schema would be trusting every hook that might run between schema validation and execution. In a stricter future configuration with no hooks, the second check costs a few comparisons. In a looser one it is the only check that holds.

The general rule: the schema describes, and the handler decides. If the two ever disagree, the handler wins, and the disagreement is a defect in the interface.

5.4 Errors are part of the interface

When a call fails, the error text is the model’s only evidence about why, and therefore about what to try next. An error vocabulary is a small recovery protocol. The candidate’s codes are stable strings with bounded messages, and they contain no native paths, environment values or stack traces. The offline contract makes that last point a requirement (OFFLINE-IMPLEMENTATION-CONTRACT.md §2; PROPOSED, implemented in the candidate). Each code suggests a different repair:

  • UNKNOWN_FILE_ID: list the catalogue again; the ID was invented or misspelled.
  • RANGE_OUT_OF_BOUNDS: the file is shorter than assumed; the catalogue carries each file’s lineCount.
  • RANGE_TOO_LARGE: split the read; the limits are 100 lines and 8 KiB.
  • INVALID_RANGE: fix the integers or their order.
  • BUDGET_EXHAUSTED: stop; nothing further will succeed.

A good error vocabulary has one property above all: distinct causes get distinct codes, because each cause needs a different recovery. This chapter’s source inspection of the candidate found one place where that property does not hold. When a task’s admitted tool list excludes a tool and the model calls it anyway, invoke returns INVALID_ARGUMENTS with the message “tool not allowed for task” (tools.ts, invoke; OBSERVED by source inspection, not tested here). A model that reads only the code may conclude that its arguments were wrong and retry the same forbidden tool with different arguments, spending budget on a call that can never succeed. In Project 01 both tools are normally admitted, and the wrapper also filters out tools a task does not allow — but tool-presence enforcement is already load-bearing: independent re-review found a zero-tool pre-authored answer completing and verifying (REVIEW-02, P01R-02 NOT CLOSED). The distinct-code recommendation stands; its model effect is untested and no new defect is asserted here. A distinct code such as TOOL_NOT_ADMITTED is the obvious repair. It is recorded as a recommendation to the implementation stream, not made here.

Errors also have a cost. In the candidate, every attempt, valid or not, is charged against the call budget, and the bytes of the rendered error text are charged against the byte budget. The first re-review observed both (INDEPENDENT-REREVIEW.md: “fifty invalid invocations charge fifty calls”; OBSERVED). That makes interface quality measurable. A poorly designed interface shows up as budget spent on errors and recoveries rather than on evidence.

5.5 Designing out whole classes of mistakes

Some of the strongest interface decisions in Project 01 are not about wording at all. They remove a decision that the model would otherwise have to make, and so remove every way of getting that decision wrong.

Opaque IDs instead of paths. The R04 dossier compared live read-only filesystem tools with an immutable manifest of text indexed by opaque file IDs, and recommended the manifest for Project 01 (R04-SECURITY-RECOVERY.md R04-P04; PROPOSED). Its main argument is about authority: no native path ever reaches the filesystem, so a large class of traversal, casing, reparse-point and alias questions does not arise. There is also a cognitive argument. A model given paths has to decide how to spell them: absolute or relative, which separator, which case. A model given fileId: "retry-config" has nothing to spell. The interface has fewer ways to be misused because it has fewer degrees of freedom. (This removes the question of path containment for Project 01. It does not answer it for later projects; see Chapters 11–12.)

Numbered lines. Citations name line ranges, so fixture_read prefixes every returned line with its number. Without that, the model would have to count lines in its own context to produce a citation, an arithmetic task that has nothing to do with the question being asked.

Self-describing results. Every successful read carries the display path, the file ID, the full file digest, the returned range and the fixture digest in a header. Everything a citation needs is in the same result as the evidence it cites.

Deterministic ordering and bounds. The catalogue is sorted by file ID, and the limits are published constants. The same request returns the same bytes in both arms of the Project 01 comparison, which the experiment plan requires.

None of this is new as a general idea. Yang and colleagues argue that language-model agents are a new kind of end user who would benefit from interfaces built for them. They call such an interface an agent-computer interface and study how its design affects agent performance (SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering, NeurIPS 2024, arXiv:2405.15793; DOCUMENTED). Their project documentation describes, among other choices, a purpose-built file viewer used in place of raw file dumps (SWE-agent ACI notes; DOCUMENTED). This book takes the hypothesis seriously, but not their numbers. Their measurements belong to their tasks, models and harness, and are not a replication here.

Narrower evidence points the same way, with an important caution. Stencil’s edit-format study compared several edit interfaces across sixteen models on synthetic React repair tasks (R03-HARNESS-RESEARCH.md R03-C08; DOCUMENTED). The R03 dossier’s reading is that the published chart shows model × format interactions: one format does not beat another for every model, and at least one model does worse under the newer format. It therefore supports measuring interfaces, not choosing a universal winner (R03, “Stencil interpretation”). The benchmark code pin could not be resolved, so a faithful replication is blocked.

5.6 The question is part of the interface

The task text is model-visible input too, and it can make a task impossible to answer correctly just as surely as a truncated digest can. Project 01’s task T4 asks, “In which function is RetryExhausted raised and handled?” The sealed oracle expects execute_with_retry. In the fixture source, that function raises RetryExhausted inside an except Exception block. Nothing in the fixture handles RetryExhausted; only a header comment in the file claims that it does (fixture-data.ts, oracle-data.ts; ambiguity recorded in HARNESS-BOOK-WRITE-02/README.md).

A careful model that trusts the code over the comment may dispute the premise or abstain, and the oracle would then score it wrong. That is a false failure created by the question rather than by the agent. The author’s decision is to correct T4 before any live experiment by versioning the fixture or excluding T4. The frozen fixture is not silently edited. Until then, any interface comparison that includes T4 confounds interface quality with question ambiguity. The lesson generalizes: an interface study must be able to distinguish “the model misused the tool” from “the task demanded something the evidence does not support.”

5.7 Worked example: counting interface cost on T2

Interface quality becomes measurable once three quantities are defined for an attempt, and all three are executed through the real tool handler in D01-WALKTHROUGH (interface-cost case pins every number below):

  • Invalid actions: calls that return an error code. These include schema rejections, unknown IDs, bad ranges, and calls to tools that are not admitted.
  • Recovery attempts: calls made after an invalid action and before the next successful call that moves the task forward.
  • Error spend: calls and bytes charged to invalid actions and their recoveries, as a share of the attempt’s total.

Here is a T2 attempt (“What configuration key controls the maximum number of attempts?”). The tool results follow the candidate’s real formats; the model’s moves are scripted to show the accounting, then executed against handleToolCall with a 4-call budget. No live model is involved.

call 1  fixture_list {}                                       ok    (catalogue: retry-config 4L, full digests)
call 2  fixture_read {fileId:"scheduler/retry.ini", startLine:1, endLine:4}
                                                              ERROR UNKNOWN_FILE_ID (37 bytes) ← used display path, not ID
call 3  fixture_read {fileId:"retry-config", startLine:1, endLine:10}
                                                              ERROR RANGE_OUT_OF_BOUNDS (55 bytes) ← file has 4 lines
call 4  fixture_read {fileId:"retry-config", startLine:1, endLine:4}
                                                              ok    (lines 1–4, full digest in header)
answer  max_attempts, cited retry-config lines 3–3, full digest

Here a recovery episode counts calls after the first rejection through the first successful corrected call, including that success; the initial invalid call is not a recovery attempt. The measured accounting: two invalid actions (calls 2 and 3), two recovery attempts (calls 3 and 4), 92 bytes of bounded error diagnostics out of 1102 total rendered bytes, and four calls charged — every attempt counts, including the errors. The answer is correct, and the oracle would accept it. The interface still cost half the call budget.

Each invalid action points to a specific interface question. Call 2 asks whether the catalogue makes the difference between the ID column and the display-path column clear enough. One candidate repair is a description that says “use the first column as fileId”. Another is an interface that accepts either form and resolves it unambiguously. Call 3 asks whether models reliably carry lineCount from the catalogue into their range choice, or whether fixture_read should clamp. Clamping, however, would mean returning something other than what was requested, which is exactly the silent behaviour the contract forbids. These are design hypotheses, and the next section turns them into an experiment.

5.8 Project study: varying the interface

The chapter brief asks for exactly this: hold task and model fixed, vary the tool interface, and count invalid actions and recovery attempts. The live-model study below is PROPOSED; EXPERIMENT PENDING. It cannot run until Project 01’s offline foundation is accepted and a live registration exists. The accounting it would use — invalid actions, recovery attempts, error spend per attempt — is executed in §5.7 against the real handler.

Arm Interface change (only this differs) Purpose
I0 Current candidate interface Reference
I1 All error codes and messages replaced by one generic TOOL_ERROR Tests whether specific codes reduce recovery attempts
I2 Descriptions rewritten to state the ID/path distinction and line limits explicitly Tests the advisory channel alone
I3 Catalogue and read header show a 12-character digest prefix, as in the original lab Negative control. Producibility is violated, so a correct cited answer should be impossible. Any I3 success indicates an evaluator or oracle leak

Model, provider settings, fixture (excluding T4, or using a versioned correction), prompts other than the changed element, budgets and oracle are held constant, following Chapter 3. Endpoints are verified task completion, invalid actions, recovery attempts and error spend per attempt, with task-grouped paired analysis. The registered predictions are:

  • I1 increases recovery attempts relative to I0 without changing verified completion much.
  • I2 reduces call-2-type errors.
  • I3 has near-zero verified completion.

The falsifiers are the opposite results. The prediction for I3 is the strongest test in the set. If I3 “succeeds”, the comparison is invalid, whatever I1 and I2 show.

One limitation should be stated now. Interface effects are expected to be model-specific (the Stencil interaction above). A result on one model is a result about that model and that interface, not a law about interfaces.

5.9 Failure modes

  • Unproducible requirement. The oracle demands data that the interface does not expose. Defence: positive-path tests built from model-visible bytes only.
  • Advice used as enforcement. A description says “only” or “never” and nothing enforces it. Defence: every restriction in a description has a matching handler check.
  • Trusting the schema. The handler assumes arguments were validated upstream. Defence: validate in the handler; treat hooks and wrappers as untrusted transformations (R02 C12).
  • Conflated errors. Different causes share a code, so the model’s recovery is a guess. Defence: one code per recovery path.
  • Silent repair. The tool truncates, clamps or guesses instead of failing, and the model cites something it did not request. Defence: fixed structured errors, with no partial content.
  • Ambiguous task text. The question’s premise conflicts with the evidence (T4). Defence: human acceptance of questions before scoring, and abstention treated as a scored outcome, not an error.

5.10 What you can build and test now

D01-WALKTHROUGH already executes the §5.7 loop: the T2 transcript through the real handler with invalid actions, recovery attempts and error spend pinned (92 error bytes of 1102, 4 calls charged). The lab suite separately unit-tests the handler with schema-rejected arguments (extra keys, floats, __proto__, arrays), proving it does not rely on the schema. Still to write as such: a full producibility test (every oracle field reconstructible from tool-visible bytes only — the zero-tool finding shows why the scripted responder path needs it) and a per-error-code recovery table. Extend all of it with the live-model arms of §5.8 once runs exist, so interface cost is reported alongside task outcome.

5.11 What remains unverified

  • The status of the corrected candidate. Independent re-review of the second freeze is complete with verdict REJECT (HARNESS-PROJECT-01-REVIEW-02, 2026-11-23). Nothing in it is accepted.
  • Any live-model measurement of invalid actions or recovery under this interface (P01-E and P01-F not run).
  • Whether specific error codes, descriptions or ID schemes help any particular model. The §5.8 study is EXPERIMENT PENDING.
  • The INVALID_ARGUMENTS / not-admitted conflation is a source-inspection observation. Its effect on a real model is untested.
  • T4 correction: versioned fixture or exclusion, still to be done by the implementation stream.

EXPERIMENT PENDING. This chapter reports source inspection and review findings within their stated scope, plus the executed §5.7 interface-cost accounting. No live-model interface comparison has been measured.

The tools in this chapter only read. A read-only interface can waste budget, but it cannot change the world it describes. The next chapter adds the first tool that writes, and with it a new requirement for the interface. The model must be able to say which version of the world its proposal was based on, and the harness must refuse proposals whose basis has gone stale.

Previous: Chapter 4: A Trace Is Not an Outcome.

Next: Chapter 6: Reliable Editing and Stale Preconditions.