# JSON schema

> A formal description of the shape of a JSON document — keys, types, required fields, allowed values — used to constrain and validate model output.

Source: Promptea — https://www.promptea.me/en/glossary/json-schema · Language: English · Last updated: 2026-11-09

## What it means

- Definition: JSON Schema is a standard vocabulary for describing JSON: which keys exist, their types, which are required, enumerations, minimums and patterns.
- Why it matters: it is the contract between the model and your code. Even a simplified schema pasted in the prompt (keys plus types) makes the output far more consistent.
- How to apply it: in the prompt, give the schema, say 'return ONLY JSON' and say what to do with missing values (null, not a guess). Where the provider offers structured outputs, pass the schema there so the format is enforced at generation time.
- In production, always validate the result against the schema and retry or reject on failure; never assume valid JSON means correct content.

## Example

```text
Extract the order from the text. Return ONLY JSON that matches this schema:
{"orderId":"string","items":[{"sku":"string","qty":"number"}],"notes":"string|null"}
If a field is missing in the text, use null. Do not guess.

Text:
"""[paste]"""
```

[Open in Promptea](https://www.promptea.me/en/analyzer?prompt=Extract+the+order+from+the+text.+Return+ONLY+JSON+that+matches+this+schema%3A%0A%7B%22orderId%22%3A%22string%22%2C%22items%22%3A%5B%7B%22sku%22%3A%22string%22%2C%22qty%22%3A%22number%22%7D%5D%2C%22notes%22%3A%22string%7Cnull%22%7D%0AIf+a+field+is+missing+in+the+text%2C+use+null.+Do+not+guess.%0A%0AText%3A%0A%22%22%22%5Bpaste%5D%22%22%22&purpose=data&target=gpt)

## Frequently asked questions

### Is the schema in the prompt enough to guarantee valid JSON?

It makes valid JSON likely, not certain. For guarantees use the provider's structured-output feature where available and validate the result in code.

### Should I ask for markdown code fences around the JSON?

Not if a program reads it: say 'return ONLY JSON, no markdown' so the output can be parsed directly.

## Related

- [How to force valid JSON output (no markdown)](https://www.promptea.me/en/guides/json-output)
- [Structured output prompting: how to get reliable JSON, tables, and lists from any AI](https://www.promptea.me/en/guides/structured-output-prompting)
- [Few-shot prompting: how to show examples instead of just explaining](https://www.promptea.me/en/guides/few-shot-prompting)
- [Structured output](https://www.promptea.me/en/glossary/structured-output)
- [Few-shot prompting](https://www.promptea.me/en/glossary/few-shot)
