Prompt Engineering Lesson 5: Getting Structured Output — Tables and JSON

📎 This article includes 1 downloadable practice file ↓

⏱ 2 min read

📘 Prompt Engineering Course · Lesson 5 of 8

In this article
  1. Tables for Excel
  2. CSV
  3. JSON with a schema
  4. Practice

Free-form paragraphs are hard to reuse. Ask for structure, and the output can go straight into Excel, a database or another program.

Tables for Excel

“Extract invoice number, date (dd-mm-yyyy), vendor, GSTIN and amount from the text below as a table.” Copy the table and paste into Excel; columns line up.

CSV

“…as CSV with a header row, comma-separated, amounts without commas.” Save as .csv or paste with Data › Text to Columns.

JSON with a schema

“`text
Return JSON only, no explanation, with exactly these keys:
{“invoice_no”: string, “date”: “YYYY-MM-DD”, “vendor”: string, “gstin”: string or null, “amount”: number}
If a value is missing, use null.
“`

Fixed keys, types and a rule for missing values make the output predictable. Many APIs also have a “structured output / JSON mode” that enforces the schema.

💡 Say how to handle missing or unclear data (null, “UNKNOWN”). Otherwise the model may invent a plausible GSTIN or date to fill the gap.
⚠️ Check extracted numbers against the source on a sample. Extraction is very good but not perfect, especially with scanned documents.

Practice

Try the three extraction formats with your own invoice or email text (remove anything confidential first).

📎 Practice files for this article

  • 📄
    Lesson 5 prompt worksheetCopy-paste prompts and exercises to try in ChatGPT, Copilot, Gemini or Claude.
    ⬇ TXT · 326 B

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong