Skip to content
Promptnic
#16 overall#2 in Coding & DevBeginnerConstraint-First

Strict JSON Extractor With Self-Check

Pulls structured data out of messy text into an exact JSON schema, with nulls instead of made-up values.

Open in:ChatGPTClaudeGrokPerplexity

The prompt

Extract data from the source text into exactly this JSON schema: [JSON_SCHEMA] Rules: - Return only valid JSON. No markdown fences, no commentary. - Never invent values. If a field is missing or unclear, use null and add a short reason to "extraction_notes". - Normalise dates to YYYY-MM-DD and amounts to numbers without currency symbols. - If the source contains a total, check that the line items add up to it and set "totals_match" to true or false. Source text: [SOURCE_TEXT]

Fill in the variables

The prompt above updates live. Nothing leaves your browser.

Remix it

One-click variations. Stack them, then copy.

Open in Prompt Lab →

Why this prompt works

Putting the schema first primes the model for structure, and the null-not-guess rule stops the most dangerous extraction failure: confident fabricated numbers. The built-in totals check catches OCR and parsing errors before they hit your database.

Framework: Constraint-First. Leads with what to avoid (banned phrases, limits) to kill generic output.

Example

Illustrative, not a real model output

Example input

[JSON_SCHEMA]
{"vendor": "string", "date": "string|null", "items": [{"desc": "string", "amount": "number"}], "total": "number|null", "totals_match": "boolean", "extraction_notes": "string"}
[SOURCE_TEXT]
ACME Hosting - Inv dated Nov 14 2026 - VPS $40, Backups $8 - TOTAL $48

What a good answer looks like (abridged)

{"vendor": "ACME Hosting", "date": "2026-11-14", "items": [{"desc": "VPS", "amount": 40}, {"desc": "Backups", "amount": 8}], "total": 48, "totals_match": true, "extraction_notes": ""}

How to use it

  1. Replace [JSON_SCHEMA] with your exact JSON schema and [SOURCE_TEXT] with the text to parse.
  2. Run the prompt with temperature set to 0 for deterministic output.
  3. Check the returned JSON for null fields and the totals_match flag before importing.

ChatGPT tips

  • Use ChatGPT's function-calling mode to enforce strict JSON formatting.
  • Keep the schema simple; nested objects increase the chance of parsing errors.

Common mistakes

  • Leaving placeholder brackets in the prompt, causing the model to treat them as literal text.
  • Expecting the model to add comments or explanations outside the JSON object.
  • Assuming missing values will be guessed instead of returning null with extraction_notes.

Guide generated with AI (openai/gpt-oss-120b) on 2026-12-06.

Frequently asked questions

Which AI model works best with the Strict JSON Extractor With Self-Check prompt?+

It is tuned for ChatGPT and also works in Claude, Gemini, Grok, DeepSeek. Put the output format (schema, table columns) near the top: ChatGPT follows explicit structure very reliably.

How do I use this prompt?+

Copy it, replace the 2 [VARIABLES] (json schema, source text) with your details, then paste it into ChatGPT. You can fill the variables on this page and copy the finished version.

Is this prompt free to use?+

Yes. Every prompt on Promptnic is free to copy, adapt and use in personal or commercial work. A link back is appreciated, not required.

Why does this prompt work?+

Putting the schema first primes the model for structure, and the null-not-guess rule stops the most dangerous extraction failure: confident fabricated numbers. The built-in totals check catches OCR and parsing errors before they hit your database.

Related prompts