— AI & agents

LLM structured output validation

Provide schema validation and failed-output recovery examples. Practical scenarios, failure cases and tradeoffs for AI product teams.

3 min readUpdated 2026-11-04By AptixLabs studio
Irregular objects becoming validated structured cards. Conceptual illustration.AptixLabs · 2026-11-04

Original AI-generated conceptual illustration for AptixLabs; not a product screenshot.

Structured output makes a response easier to validate, but a valid shape can still contain a wrong value. Treat schema validation and domain validation as separate checks. An exercise recommendation might satisfy JSON types while referencing an exercise that does not exist or using an impossible duration.

The contract to define first

Validate required fields and types at the boundary, then resolve identifiers and check domain constraints against authoritative data. Keep validation errors machine-readable so repair attempts can target the problem. Bound repair loops and preserve the original request. Never let a repair instruction widen permissions or quietly change the user’s goal.

A worked scenario

A hypothetical plan contains three exercise IDs and session durations. The schema accepts the IDs as strings, but one ID is absent from the catalog. Reject or repair that reference before saving. The user should not discover the problem halfway through a workout.

An implementation and review sequence

  1. Define shape and domain checks separately
  2. Resolve identifiers before committing state
  3. Limit repairs and retain useful validation diagnostics

Failure cases worth testing

Provide schema validation and failed-output recovery examples. Use this matrix as a starting fixture and adapt the expected behavior to the documented product contract.
Condition or inputExpected behavior
Output is malformedReject before domain processing
JSON is valid but an ID is unknownFail the domain check
A repair repeatedly changes the requested planStop and ask for a recoverable next step

Download the illustrative acceptance checklist (JSON)

Tradeoffs and limits

Very rigid schemas can make exploratory tasks awkward. Use stricter contracts for persisted actions and allow clearly separated free-form explanation where the product needs flexibility.

Use the result to make a decision

The practical output is straightforward: provide schema validation and failed-output recovery examples. Keep the assumptions with the artifact so a product owner, implementer or prospective partner can review the same decision. A useful handoff states the supported scope, the evidence collected and the remaining dependency instead of treating a successful demonstration as proof of every operating condition.

Continue with related implementation detail

Related guide: A production prompt needs a testable contract.

AI action rollback and compensation

AI chat streaming that survives reconnects

References and current platform requirements

MCP specification and tool contracts

Google Cloud: AI security and safety for MCP

Platform capabilities, programme terms and access conditions can change. Check the linked primary references against the version and account you actually use; the patterns above do not establish a provider approval, certification or universal compatibility guarantee.

Discuss the workflow

Bring one workflow, its systems, and the actions requiring human approval.

Explore the relevant AptixLabs service

Send a scoped project enquiry

Does valid JSON guarantee a correct AI result?

Structured output makes a response easier to validate, but a valid shape can still contain a wrong value. Very rigid schemas can make exploratory tasks awkward.

Which failure cases should be included in the review?

Include these explicit cases: Output is malformed: reject before domain processing; JSON is valid but an ID is unknown: fail the domain check; A repair repeatedly changes the requested plan: stop and ask for a recoverable next step.

Need help with ai agent & automation development?

Tell us about your product, existing stack and the problem you need to solve. We can discuss integration scope, implementation tradeoffs and a practical first milestone.

Start a conversation