AIOctober 18, 20263 min

Validate structured AI output before using it

Validate a nested AI campaign brief with schema and semantic checks, using valid and invalid fixtures and an explicit rejection path before downstream use.

The cover shows machined titanium socket with a precisely keyed opening.

What does a structured output guarantee?

A schema can constrain structure; it cannot establish that a campaign idea is truthful or appropriate. Validate the nested object before rendering or sending it to another system, then apply task-specific semantic rules. A successful JSON parse proves only that the text is syntactically JSON.

OpenAI’s Structured Outputs documentation describes schema-constrained responses for supported configurations and warns that substantive mistakes can remain. It also requires handling refusals and incomplete outputs. The contract below is an illustrative application design, not a claim that every model supports every JSON Schema feature. [Structured model outputs]

A small nested campaign-brief contract

Illustrative valid shape; every evidence reference still needs an independent check.
{
  "campaignId": "spring-demo",
  "audience": {"segment": "operations teams", "excluded": ["existing customers"]},
  "offer": {"claim": "Book a product walkthrough", "evidenceId": "offer-01"},
  "assets": [{"format": "text-ad", "headline": "Review your reporting workflow"}],
  "unknowns": ["Approved launch date"]
}
Validation specification
LayerRuleFailure example
Object shapeRequired nested audience, offer and assets fieldsaudience is a plain string
Allowed keysReject unexpected executable or routing fieldspublishNow appears without being part of the contract
Value constraintsAsset format comes from the application’s allowed setAn unsupported format is returned
Evidenceoffer.evidenceId resolves to an approved source factModel invents evidence-99
ScopeDraft contains no unapproved price or launch dateA fluent sentence supplies a missing fee

Define constraints in the application, not just in the prompt. The renderer should not guess that a missing array was meant to be a paragraph. Reject the object with a useful internal error path, such as assets[0].format, and retain the original response only in an appropriate restricted diagnostic store.

Which fixtures should the gate reject?

  • Missing offer.evidenceId: reject the incomplete claim record.
  • A string where assets should be an array: reject before iteration.
  • An empty headline: reject before rendering a blank card.
  • A valid object containing “Guaranteed 30% savings”: fail the unsupported-claim rule.
  • A refusal or interrupted response: enter its explicit state rather than manufacturing a default brief.

The unsupported guarantee fixture is especially useful because it can pass structural validation. Compare each factual assertion with the supplied fact table. If the evidence only establishes that a walkthrough exists, the model cannot extend that into a quantified outcome. A citation identifier is not proof unless it resolves to the relevant evidence.

Keep normalization narrow and documented. Converting surrounding whitespace or an explicitly supported alias can be reasonable. Silently inventing missing fields changes the contract and hides production defects. When the input is genuinely incomplete, return a draft with named unknowns only if the downstream workflow allows that state.

Make rejection safe and useful

A rejected draft should not proceed to publication, billing or messaging. Return a recoverable status to the person supervising the workflow: which field failed, what evidence is missing and whether a corrected input or a new generation is needed. Avoid exposing raw provider errors or sensitive source material in the public interface.

I would test one complete object through the real renderer before scaling a batch. A type definition and a plausible example are insufficient when nested field names disagree. The useful result is a proven input contract, a rejection path and evidence that downstream actions stay blocked until both validation gates pass.

Sources

AI-assisted writing and an AI-generated editorial cover. Source links and checked dates are listed below; illustrative examples are labeled in the text.

More on the topic