---
name: "self-correcting-schema-agent"
description: "Repair structured output against a fixed JSON Schema with bounded retries. Use when the user needs: Get schema-valid output or an explicit failure with validation errors."
metadata: {"version": "2026-10-17.1", "category": "agents-workflows", "publisher": "AIDiveForge"}
---

# Self-Correcting Schema Agent

Get schema-valid output or an explicit failure with validation errors.

## Requirements

Requires the schema, a validator and an assistant capable of revising the output.

## Workflow

1. Validate the schema itself, then freeze it for the run; do not weaken requirements to make output pass.
2. Validate the proposed JSON and return concrete error paths to the repair step.
3. Repair only the failing structure while preserving supported source facts.
4. Repeat within the stated attempt budget and validate each result independently.
5. If the budget is exhausted, return failure and the last errors; never label invalid JSON successful.

## Worked example

Read `examples/input.txt` and `examples/expected.txt` before adapting the workflow.

## Acceptance checks

The repaired value is an integer supported by the source, the schema is unchanged and an independent validator accepts the result.

## Limits

Schema validity does not establish factual correctness. Retries and API costs remain the caller’s responsibility.

Worked example included. Model-specific performance and vendor compatibility have not been benchmarked.
