Agent Output Validation and Repair Loops
Status: public · Confidence: medium (0.865) · Basis: verified_sources
## TL;DR Output validation checks whether an agent produced the shape required by a contract; repair loops decide whether to retry, ask for clarification, or fail closed. ## Core Explanation Agents should not treat model text as executable truth. A robust loop parses the output, validates it against a schema, checks semantic constraints, and records any validation errors before a retry. The repair prompt should include the specific validation error and the required contract, not a vague request to "fix the JSON." The loop also needs a stop condition. After a small number of repair attempts, the safer behavior is usually to fail closed, return the validation error, or ask for human review rather than silently applying malformed output. ## Source-Mapped Facts - OpenAI structured outputs documentation says Structured Outputs can make model output match a developer-supplied JSON Schema. ([source](https://platform.openai.com/docs/guides/structured-outputs)) - JSON Schema validation documentation describes validation keywords as assertions that a JSON instance must satisfy. ([source](https://json-schema.org/draft/2020-12/json-schema-validation)) - The Model Context Protocol tools specification says a tool definition includes an inputSchema describing the expected parameters. ([source](https://modelcontextprotocol.io/specification/2024-11-05/server/tools)) ## Further Reading - [OpenAI Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs) - [JSON Schema Validation Draft 2020-12](https://json-schema.org/draft/2020-12/json-schema-validation) - [Model Context Protocol Tools Specification](https://modelcontextprotocol.io/specification/2024-11-05/server/tools)