What is it?
There are several ways to get structured data from a model. Some just ask politely; some guarantee valid JSON; some guarantee your exact schema. The stronger the guarantee, the less your code has to defend against bad output — but the more it ties you to a provider or engine.
Also known as: JSON mode vs structured output, function calling vs structured output, best way to get JSON from LLM, structured output methods, pydantic vs json mode, which structured output method.
Technical definition
| Method | Guarantee | Portability | Notes |
|---|---|---|---|
| Prompt + examples | None; best-effort | Any model | Needs parse + retry |
| JSON mode | Valid JSON syntax (provider-defined) | Provider-specific | Schema not guaranteed |
| Schema-enforced structured output | Matches supported schema subset | Provider-specific | Check supported keywords |
| Function / tool calling | Arguments follow tool schema (strength varies) | Widely available | Best for actions; see Function Calling (Tool Calling) Explained |
| Constrained decoding (grammar/regex/schema) | Token-level validity | Local engines + some servers | See Constrained Decoding (Guided Generation) |
None of them guarantees the values are correct.
Entity type: concept · Freshness class: volatile.
When should I use it?
Choose the strongest guarantee your stack supports; add validation always.
Implementation patterns
- Use the strongest enforced mode available; add validation and retry as a safety net.
- Use function calling when the output triggers an action.
- Use constrained decoding with local models.
Technologies and frameworks
Commonly associated: provider SDKs, Pydantic, Zod, Outlines. Names are examples of what exists, not recommendations, and projects change quickly.
Practical guide
- Rank how costly a bad parse is.
- Check what your provider/engine supports.
- Pick the strongest feasible method.
- Validate and retry.
Common failure modes
- Treating JSON mode as schema enforcement.
- Skipping validation because the method "guarantees" shape.
Troubleshooting
- Sporadic parse failures — Move up the table to a stronger method and add validation.
Contrasted with
- Structured Outputs from LLMs — The overview.
- Constrained Decoding (Guided Generation) — The strongest token-level approach.
Questions this page answers
- What is the best way to get JSON from an LLM?
- JSON mode vs structured outputs: what is the difference?
- Should I use function calling to extract data?
- When do I need constrained decoding?
Typical goals: choose a method for reliable structured data; compare JSON mode with schema enforcement.
Sources and verification
Status: not independently verified. This entry was authored on 2026-10-06 from general technical knowledge, without live checking of the sources below. Treat every source as a lead to confirm (identifier, title, authorship, current version) before publication or citation.
Freshness class: volatile — Products, versions, protocols, benchmarks, leaderboards, regulations and dates. Verify against the primary source before relying on specifics; re-review every 3 months.
Time-sensitive claims to verify before relying on them:
- Current feature support and limits per provider.
Canonical sources (unverified leads):
- Provider structured-output and function-calling documentation (identify current pages) — locator to be identified
- JSON Schema specification — json-schema.org