Skip to content

7. Layer 2: Structured Output ​

Problem Solved ​

The model produces text, but the harness needs reliable decisions. Layer 2 defines the contract between what the model emits and what the system does. The model must produce output that follows the contract, whether by prompting alone or by guided generation at decode time (13).

Service Provided to the Layer Above ​

Layer 2 converts raw model output into typed intents:

IntentMeaning
Final answerThe agent believes the task is complete
Tool requestThe agent wants the harness to execute a tool
ClarificationThe agent needs more information from the user
Plan updateThe agent revises its multi-step strategy
AbortThe agent cannot or should not continue

The exact protocol may use JSON, XML, function-calling APIs, or another format. The architectural requirement is the same: the harness must be able to parse and validate the model’s intended action.

Model Proposes, Harness Disposes ​

This is a core principle.

text
+-------------+        +--------------+        +-------------+
| LLM Engine  | -----> | Output Parser| -----> | Validator   |
+-------------+        +--------------+        +-------------+
                                                |
                                   valid intent | | invalid intent
                                                 v v
                                           +-----------+
                                           | Harness   |
                                           | decision  |
                                           +-----------+

The model may propose an action. The harness decides whether that action is structurally valid, permitted, and safe to execute.

Tool-Call Contract ​

A tool request should specify:

FieldPurpose
Tool nameWhich declared tool is being requested
ArgumentsValues bound to the tool’s parameters
Intent classRead, compute, mutate, submit, abort
Optional rationaleHelps debugging and auditing, not execution

A common concrete shape: the contract is defined once in code, a class or function with typed arguments and a description. For the model, the harness serializes it to text, the tool name, the description, and a list of argument names and types. For the harness, the same contract maps to the code primitives it executes. The model sees the serialized form. The harness runs the code form.

The model can only pick a tool it understands. A tool name alone is rarely enough. The harness must provide a clear, detailed description of what the tool does, what it needs, and what will happen after it runs, both the wanted effects and the unwanted ones (14)(15). Poor descriptions lead to the wrong tool being picked, even when the right tool is available.

The contract must be checked before execution:

  • Tool name exists in the declared tool set.
  • Required arguments are present.
  • Argument types and values are valid.
  • Argument values satisfy policy constraints.
  • The caller is allowed to use that tool.
  • The action is within step, cost, and permission budgets.

Design Rules ​

  1. Keep the output protocol simple.
  2. Require an explicit final-answer intent.
  3. Reject unknown tools instead of guessing.
  4. Validate arguments before any side effect.
  5. Treat invalid output as a controlled error, not as executable text.
  6. Limit retry cycles for malformed output.
  7. Log the raw model output and the parsed intent separately.

Failure Modes ​

FailureExampleArchitectural fix
Malformed structureInvalid JSON or incomplete blockParser with controlled retry
Unknown toolModel invents a tool nameTool allowlist
Missing argumentTool called without required fieldSchema validation
Invalid argumentPath, ID, amount, or range out of boundsArgument policy checks
Ambiguous intentText contains both answer and tool requestExplicit intent priority rules
Silent refusalModel says it cannot act but provides no structured abortRequired abort/clarification intent