Prompt Engineering Lesson 5: Getting Structured Output β€” Tables and JSON

Prompt Engineering Lesson 5: Getting Structured Output β€” Tables and JSON featured illustration

πŸ“Ž This article includes 1 downloadable practice file ↓

⏱ 1 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
  5. Continue learning

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

Advertisement

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

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.

Advertisement
πŸ’‘ 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