We rebuilt PromptSewa — and your prompts were reset

Lesson 11 · 5 min

Extraction prompts: getting facts out cleanly

Pull structured fields from messy text without inventing the gaps.

Extraction is the most reusable prompt pattern in business work: take an email, an invoice, a transcript or a job posting and return named fields. It is also where invented data does the most damage, because an extracted value looks authoritative. The whole design of an extraction prompt is about making absence explicit and making the shape unmissable.

Name the fields and their types

List every field with the expected type: string, number, date, one of a fixed set, nullable. Types do the work of a specification. A field declared as a date will be normalised; a field declared as an enum cannot wander. Where a value is a choice, list the choices in the prompt. Where a field is optional, say so and say what to return when it is missing.

Make absence a value

The critical instruction is what to do when the source does not contain a field. Without it, the model fills the slot with something plausible, and a plausible invoice number is worse than no invoice number. Require an explicit sentinel: null, "not stated", or an empty list. Then treat the sentinel as data downstream rather than a missing key, so the pipeline can distinguish "absent" from "we forgot to parse it".

Constrain the source

Say that the answer must come only from the provided text, and repeat the rule where it matters. A model with general knowledge will happily complete a company name from context, which is exactly the failure that makes extraction risky. If a field may be inferred rather than quoted, mark those fields separately so a reviewer knows which values are evidence and which are guesses.

Example: "Return JSON with keys: vendor (string), invoice_number (string or null), total (number or null), due_date (ISO date or null). Use only text from {{document}}. If a value is not present, use null. Do not infer a total from line items."

Handle repetition and ambiguity

Two invoices in one file, two totals on a page, a name that appears in both the sender and the recipient. Decide in advance: return a list, return the first, return the most prominent with a note. Ambiguity is not rare, so the prompt needs a rule rather than a hope. A good rule is boring and predictable, which is exactly what a downstream system needs.

Check the shape, then the values

Validate the shape first: are all keys present, are types correct, is the JSON parseable. Then spot-check values against the source. Shape failures are cheap to fix with a stricter instruction; value failures usually mean the absence rule was not strong enough. Keep a stored sample of accepted output — it doubles as documentation and as a regression case.

Checklist

  • Is every field named with a type?
  • Is missing data represented by an explicit sentinel?
  • Is the source restricted to the provided text?
  • Is there a rule for duplicates and ambiguity?

Finished this lesson?

Mark it complete to generate a certificate you can print or save as a PDF. We ask for an email only so you can be reached — no account is created.

All lessons