← All templates
PythonCoreApplied AI EngineerForward Deployed EngineerApplied AI Architect

Structured extraction to validated Pydantic objects

Extract invoices from text or PDF with structured outputs, then validate, check business rules and grounding, retry once with feedback, and run it all as a Message Batch.

Locked

The code is part of the full course

The file map and notes are open to everyone. Get lifetime access to every template's source, the .zip download and all four tracks for a one-time $249.

Run it

shell
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env  # add ANTHROPIC_API_KEY
python -m app.main check samples/invoice_acme.txt samples/invoice_acme.expected.json  # offline
python -m app.main extract samples/invoice_acme.txt
python -m app.main extract samples/invoice_bad_totals.txt  # needs_review
python -m app.main batch-submit samples/*.txt
python -m app.main batch-collect <batch_id>

Test it

shell
pytest -q

Offline: no API key or network needed.

Taught in