Skip to main content
Even with schema-constrained generation, always validate output on your server.
  1. Request schema-constrained output.
  2. Parse JSON.
  3. Validate against your server schema.
  4. Retry once with a corrective prompt if invalid.
  5. Fallback to safe failure if still invalid.

Validation example (TypeScript)

Corrective retry prompt

When validation fails, send a short corrective instruction: Your previous output did not match schema. Return valid JSON only, with required fields and no extra keys.

Production guidance

  • Keep one schema per use case and version it.
  • Track validation failure rates by model id.
  • Alert on sudden schema failure spikes after model changes.
Last modified on July 26, 2026