# Consistent JSON Without A Schema Library

> Four prompt rules that took me from roughly 8 in 10 parseable to a failure rate I stopped monitoring.

- **Author:** [Abhay Pratap Mishra (@abhay)](https://www.promptabide.com/abhay)
- **Published:** 2026-08-20
- **Updated:** 2026-08-24
- **Tags:** `prompt-engineering`, `json`, `data-extraction`
- **Views:** 27300
- **Likes:** 1608

## Prompt

````
Structured output modes are the right answer when you have one. This is what to do when you do not - an older endpoint, a local model, a provider that does not offer it.

Four rules, in order of how much they bought me.

**1. Show the shape, do not describe it.** One filled-in example beats a paragraph of field descriptions. The example teaches key order, nesting and types in one go, and it is impossible to misread.

**2. Name the null case explicitly.** This was the big one. Half my parse failures were the model deciding that a missing value warranted prose - `"discount": "not specified in the input"` - instead of `null`. So: *"If a value is absent, use null. Never use a string to explain an absence."*

**3. Forbid the fence and the preamble in the same sentence.** "Return only the JSON object. No markdown fences, no explanation before or after." Split these into two rules and you get one of them obeyed.

**4. Put the schema last.** Whatever sits closest to the end of the prompt gets weighted most. The document goes first, the format goes last.

```
Extract the invoice fields. Return only a JSON object matching this
example exactly - same keys, same order, same types. No markdown
fences, no explanation before or after.

If a value is absent, use null. Never use a string to explain an
absence.

{
  "invoice_number": "INV-2041",
  "issued_on": "2026-03-14",
  "currency": "GBP",
  "total": 1284.50,
  "line_items": [
    { "description": "Design retainer", "quantity": 1, "unit_price": 1284.50 }
  ],
  "purchase_order": null
}
```

**Still keep the retry.** This got me to a failure rate I stopped tracking, not to zero. One re-ask with the parser error appended catches essentially all of the remainder. Do not build a parser that assumes success just because the prompt got good.
````

## Output

*Produced by ChatGPT · gpt-4-turbo.*

```
{
  "invoice_number": "2026-0417",
  "issued_on": "2026-04-02",
  "currency": "EUR",
  "total": 3960.00,
  "line_items": [
    { "description": "Platform licence, annual", "quantity": 1, "unit_price": 3600.00 },
    { "description": "Onboarding session", "quantity": 2, "unit_price": 180.00 }
  ],
  "purchase_order": null
}
```

---

Canonical HTML: https://www.promptabide.com/bides/consistent-json-without-a-schema-library
Agent guide: https://www.promptabide.com/llms.txt · https://www.promptabide.com/agent-instructions.md
Sitemap: https://www.promptabide.com/sitemap.xml
