When to use it
When you need to pull fields out of messy text (an email, a request form, an invoice, a review) and put them into a database/table/API. The AI's role is a parser. Output: clean JSON matching your schema that won't break the code in the next step — no "Sure, here's the data:" and no invented fields.
The prompt (copy and paste)
Extract data from the TEXT strictly into JSON following the schema below. Return ONLY a valid JSON object, with no explanations and no markdown.
SCHEMA (keys and types are fixed):
{
"<field1>": "string",
"<field2>": "number | null",
"<field3>": "YYYY-MM-DD | null",
"<field4>": ["string"] // array, [] if there's nothing
}
Rules:
1. Use EXACTLY these keys. Don't add new fields and don't rename anything.
2. If a value is missing from the text or ambiguous — put null (for an array, []). Do NOT guess or invent.
3. Numbers — no units or spaces (1500, not "1 500 ₽"). Dates — ISO YYYY-MM-DD.
4. Copy values as they appear in the text (names, addresses), don't translate or tidy them up.
TEXT: "<PASTE THE TEXT>".
The technique: a fixed schema plus the rule "no data → null, don't invent" is the manual equivalent of strict structured outputs; in an API you're better off enabling json_schema with strict so the format is guaranteed by the engine.
Filled-in example
Schema: { "name": "string", "amount": "number | null", "due_date": "YYYY-MM-DD | null", "items": ["string"] }. Text: "Invoice for Romashka LLC for 12,500 rubles, payable by June 15. Line items: hosting, domain."
What the AI should come back with: {"name":"Romashka LLC","amount":12500,"due_date":"2026-06-15","items":["hosting","domain"]} — and nothing besides that object.
Variations
- An array of objects. "Return a JSON array: one object per order line" — for parsing tables and lists.
- With confidence. Add a
"confidence": "high|medium|low"field to each extraction — to catch the shaky ones. - Via the API. In OpenAI and compatible APIs —
response_format: { type: "json_schema", strict: true }; describe the schema in Pydantic/Zod, and invalid JSON simply won't be generated.
Pro tips
- In code, don't rely on the prompt alone — turn on strict mode (json_schema), otherwise on long texts the model will occasionally add a preamble and break
JSON.parse. The prompt rules are for chat, where strict isn't available. - Mark optional fields as "type | null" and explicitly require null when missing — otherwise the model will paint in a plausible value and you'll get a silent data error.
- Ask it to COPY values rather than normalize them (numbers and dates aside): auto-"correcting" names and addresses is a common source of data corruption during extraction.