ModelRefs / JSON Mode — Prompt Pattern
JSON Mode — Prompt Pattern
Force the model to return valid JSON conforming to a schema. Use the provider's JSON / structured-output mode together with an explicit schema in the prompt.
Overview
Use the provider's JSON / structured-output mode together with an explicit schema in the prompt. Eliminates fragile regex parsing.
When to use it: Downstream code needs strict JSON, not prose-wrapped JSON.
Pattern details
| Pattern class | structured-output |
|---|---|
| Difficulty | beginner |
| Also known as | structured output, json schema prompt |
| Last reviewed | 2026-06-07 |
Known failure modes
- Markdown wrap — Output wrapped in ```json fence. Mitigation: Strip fence in post-processing or use native JSON mode.
- Schema drift — Extra keys or wrong types. Mitigation: Validate with Zod / Pydantic; retry on failure.
When not to use it
- Parsing unconstrained free text and hoping it's JSON.
Continue your research
Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to JSON Mode — Prompt Pattern.
Frequently asked questions
When should I use the JSON Mode prompt pattern?
Downstream code needs strict JSON, not prose-wrapped JSON.
What are common failure modes of JSON Mode?
Markdown wrap • Schema drift
Does JSON Mode work across models?
Yes when the anatomy is preserved — see model compatibility matrix on the pattern page.