Structured Output and Bounded Repair
Parse, validate, reject
When software consumes an LLM response, request a narrow structured format such as JSON and validate it with ordinary code. Syntactic validity means the text parses. Schema validity means required keys, types, ranges, and enumerated values satisfy the contract. Semantic validity means the content also makes sense for the task.
model output -> JSON parse -> schema validation -> business-rule validation
fail fail fail
└------ controlled error or one bounded repair attempt
A repair prompt can show the validation error and ask for corrected structure, but retries need a small fixed budget and must never relax safety rules. Deterministic repairs such as trimming whitespace are safer than guessing missing values. Persist the original invalid output only when privacy policy permits and access is controlled.
Warning: Valid JSON is not trustworthy JSON. A model can return {'approved': true} in perfect syntax without authority to approve anything. Authorization and real-world constraints live outside the model.
Note: Tool calling is structured output whose schema names an action and arguments. The agent harness must allowlist the tool, validate arguments, and require approval before consequential execution, as the existing terminal-agents module teaches.