An agent output that looks right can still break the next step when a field is missing or the wrong type. Validating the output against its schema before saving catches those errors at the cheapest point. Save only valid outputs, and log the invalid ones for fixing.
Checked on 2026-11-29. We did not run any tool for this guide. Every result below is an expected result, marked UNTESTED, for you to confirm on your own files.
Prerequisites
- The output schema with required fields and types
- The agent output to check
- A validator or a small script
Steps
1. Get the output as data
Ask the agent for structured output, or parse its reply into fields.
Expected result: The output exists as named fields, not free text.
2. Validate against the schema
Check each required field exists and each value has the right type.
Expected result: The output is marked valid or invalid, with each failure named.
3. Reject or fix the invalid output
If it is invalid, ask the agent to fix the named fields, or fill them by hand from the source.
Expected result: The output is fixed and re-validated, or rejected with the reason noted.
4. Save only the valid output
Save the valid output with the time and the schema version used.
Expected result: A saved file exists with only valid fields, dated and noted.
Worked example
A practice agent returned three order records. One had a missing field and was fixed before saving.
| Record | Fields present | Valid? |
|---|---|---|
| ORD-1041 | 4 of 4 | Yes |
| ORD-1042 | 3 of 4 | No |
| ORD-1043 | 4 of 4 | Yes |
| Records checked | 0 |
Expected result: Two records are valid and one is fixed before saving, so the saved file holds 11 of 11 required fields (UNTESTED – confirm it yourself.)
Verdict table
| Check | Expected result | Pass? |
|---|---|---|
| Get the output as data | The output exists as named fields, not free text. | – |
| Validate against the schema | The output is marked valid or invalid, with each failure named. | – |
| Reject or fix the invalid output | The output is fixed and re-validated, or rejected with the reason noted. | – |
| Save only the valid output | A saved file exists with only valid fields, dated and noted. | – |
Limits
- A valid schema does not mean the values are true; check figures against the source too.
- Strict validation can reject outputs that are fine but use a different spelling; keep the schema flexible where it can be.
Sources
- Model Context Protocol (Stanford CS329T slides) – checked 2026-11-29
- The Model Context Protocol (MCP) for compliance data – checked 2026-11-29
- What is the Model Context Protocol (MCP)? – checked 2026-11-29
- Ollama v0.9.1 release notes – checked 2026-11-29
