An agent output that goes straight into the next step carries whatever mistakes the model made: a missing field, a wrong type, a value that looks right but is not. Validating the output against its schema catches those mistakes at the boundary, before they spread. MCP tools can declare an outputSchema for their structured results, and clients should validate structured results against it; the same discipline belongs on the agent’s own output. Write the schema first, check the output against it, and on failure send the error back to the agent for a correction instead of passing the bad output on.
What you need
- An output schema for the agent’s result: field names, types, and required fields
- A validation step between the agent and the next step
- One example of a bad output the agent has produced before
Step 1: Write the schema the next step needs
List each field the next step reads, with its type and whether it is required. A schema written from what the next step needs, not from what the agent happens to produce, is the one that catches real errors.
Step 2: Validate the output before passing it on
Check the agent’s output against the schema before the next step sees it. On failure, return the error to the agent with the failing fields named, so it can correct the output.
Step 3: Test with the known bad output
Feed the known bad output through the validation step and confirm it is caught and sent back, then confirm a good output passes through unchanged.
Worked example: synthetic output schema check
The table below is a synthetic example. It shows the expected result of output validation; no output was passed on.
| Output | Schema valid? | Passed on? |
|---|---|---|
| Order summary, all fields | Yes | Yes |
| Summary, price missing | No | No – sent back |
| Summary, price as text | No | No – sent back |
| Corrected output passes | Yes | Yes |
Expected result (UNTESTED). the good output passes on, the two bad outputs are caught and sent back, and the corrected output passes. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- Validation checks shape, not meaning: a well-formed but wrong value still passes.
- The schema and the next step must stay in sync, or the check rejects good outputs.
- Returning the error only helps if the agent reads it and corrects the output.
- An output with no schema cannot be validated this way; write the schema first.
