Using AI to Extract Structured Data From Messy Text
Data extraction is one of the clearest uses for structured AI prompts. The key is to define the fields, show what missing information should look like and keep the original text available for checking.
1. Define the schema
List the exact fields you want and what each field means.
2. Specify missing-value behavior
Tell the assistant to use “Not found” or another fixed value instead of guessing.
3. Preserve source wording where needed
For important fields, ask for a short source excerpt so a reviewer can trace the extraction.
4. Use a stable format
JSON, a table or fixed labels can make repeated extraction easier to inspect.
5. Sample-check results
Compare a selection of outputs against the original documents before relying on the process at scale.
Example: extract support case fields
Fields might include issue type, product, customer goal, deadline and requested action. If the email does not contain a deadline, the result should say “Not found,” not invent one.
Extract the following fields from the text: issue type, product, requested action, deadline, and urgency. Rules: use only information stated in the source; write “Not found” when a field is absent; do not infer urgency from tone. Return a table with field, value, and supporting quote. SOURCE: [paste text]
Common mistakes
- Using vague field definitions.
- Allowing the model to infer missing values without saying so.
- Changing field names between runs.
- Skipping sample checks before using extracted data operationally.
FAQ
Can AI extraction replace a database parser?
It depends on the data and required reliability. AI can help with messy language, while deterministic parsing may be better for stable formats.
Why include a supporting quote?
It gives reviewers a quick way to trace an extracted value back to the source.
Worked scenario: Extracting invoice fields from supplier notes
This is an illustrative example, not a report of a live product test. Replace the sample details with source material you can verify.
Source note: “Northstar Supplies — invoice NS-1048 — total SGD 428.60. Please arrange payment next week.” No exact due date is stated.
Return JSON with supplier, invoice_number, currency, total, due_date and evidence. Use null for missing values. Do not convert “next week” into an exact date unless the source date and rule are supplied.
Check each value against the source. The due date should remain unknown or preserve the phrase as source text; do not guess a calendar date.
Extracting invoice fields from supplier notes
Use this as a starting instruction with your preferred AI assistant. Replace bracketed placeholders with your own source material; this is an illustrative template, not a report of a real-world test.
Validate the JSON syntax, compare every extracted value with the source and ensure missing values are null rather than guessed.