Stop 12 · Prompt EngineeringProjects · 2/2

Structured Data Extractor

Part of the AI Engineer Roadmap

In short

Turn messy text like visiting cards, invoices or job posts into clean rows in a spreadsheet. This project teaches structured output, validation and retries, which are core skills for real LLM work.

A tool that pulls structured fields (names, dates, amounts) out of unstructured text like invoices or emails — a common, high-value real-world LLM application.

The blob takes visiting cards from a messy heap and files them neatly into a small wooden cabinet.

Think of it like this

Filing the visiting cards

After a college fest, you have a heap of visiting cards in every design. You read each one and file it: name, company, phone, email, in the same order every time. Your extractor does this for any messy text, at scale.

Watch it happen

One document through the extractor

Upload
App
Model
Sheet / DB

job_post.txt

1/6A user uploads a messy job post copied from a website.

The big ideas

What you need to know

Schema first

Decide the exact fields and types before writing prompts. The schema is the contract.

Validate and retry

Validate every result. Retry once with the error message, then flag for human review.

Nulls over guesses

If a salary isn't mentioned, it should be null, not a made-up number.

Measure accuracy

Hand-label 20 documents and compare field by field. Report accuracy per field, not just overall.

See it in code

Walk through the code

python
1from pydantic import BaseModel, ValidationError2 3class JobPost(BaseModel):4    title: str5    company: str6    city: str | None7    salary_lpa: float | None      # lakhs per annum, null if not stated8    skills: list[str]9 10def extract(text: str) -> JobPost | None:11    prompt = f"Return only JSON for this schema: {JobPost.model_json_schema()}\n<text>{text}</text>"12    for attempt in range(2):13        try:14            return JobPost.model_validate_json(ask_llm(prompt))15        except ValidationError as e:16            prompt += f"\nYour last JSON was invalid: {e}. Fix it."17    return None  # send to human review

1/3The schema with optional fields where data might be missing.

Schema, prompt, validate, retry once, then give up gracefully. ask_llm is your own helper.

Save yourself the pain

Common mistakes

Oops

Only testing on clean, well-formatted examples.

Do this instead

Include messy ones: missing fields, two salaries, Hinglish, extra emojis. That's what real data looks like.

Oops

Retrying forever when validation fails.

Do this instead

Retry once or twice, then flag for review. Endless retries waste money and hide real problems.

Your mission

First milestone: 10 rows

~45 min

Quick check

A job post doesn't mention salary. What should your extractor return for salary_lpa?

Go deeper

  1. 1Define a strict output schema and use structured-output mode to extract fields reliably.
  2. 2Test against messy, real-world input text, not just clean examples.
  3. 3Add validation and a fallback path for fields the model couldn't confidently extract.

More projects at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge