Structured output is enforced when the application requests it
Why it matters
AI models that are prompted to return JSON do not guarantee valid, correctly-shaped JSON on every response. Without validation via Zod, JSON Schema, or SDK-level structured output, a malformed or schema-violating AI response will either throw an unhandled exception at JSON.parse() or silently corrupt downstream logic — writing unexpected data to a database, crashing a rendering component, or causing a downstream API call to fail. OWASP LLM09 (Misinformation) covers the class of failures where AI output is consumed uncritically. CWE-20 (Improper Input Validation) applies directly: structured AI output is external input and must be treated as such.
Severity rationale
Critical because unvalidated structured AI output directly exposes application logic to crashes, data corruption, and undefined behavior on every LLM response that deviates from the expected schema.
Remediation
Use SDK-level schema enforcement or Zod validation before consuming structured AI output. The preferred path is generateObject from the Vercel AI SDK:
const { object } = await generateObject({
model: openai('gpt-4o'),
schema: z.object({ summary: z.string(), tags: z.array(z.string()) }),
prompt: userMessage
})
If using raw JSON.parse, always wrap in safeParse and handle the failure branch explicitly before writing to a database or passing to a renderer.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the AI Response Quality Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-20 — Improper Input Validation
- owasp-llm:2025 · LLM09 — Misinformation
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-response-quality·automated