← all devlogs
AI·2026-08-20·4 MIN READ

Structured AI Output: The JSON-Only Prompt Pattern

How to get reliable, parseable output from LLMs by forcing JSON-only responses with schema validation and few-shot examples.

Free-form LLM output is hard to use in production. The fix is structured output — JSON that matches a schema.

The pattern

Output ONLY valid JSON matching this schema:
{"tagline": string, "description": string}

Do not include explanations, markdown, or code fences. ```

Why it works

  • No parsing free text
  • Directly populate form fields
  • Fail fast on invalid JSON

Add validation

const parsed = JSON.parse(response);
zodSchema.parse(parsed); // throws if invalid

The combination of constrained prompts + schema validation gives you production-reliable AI output.

AIPrompt EngineeringTypeScript