← Back to Projects

Structured Extraction Pipeline

intermediatePhase 06 · LLMsPythonOpenAI APIPydantic

Take raw messy text (like resumes or receipts), use an LLM API with function calling, and guarantee valid JSON extraction.

What you'll learn

  • Using the OpenAI or Anthropic Python SDKs
  • Defining strict data models using Pydantic
  • Utilizing LLM Tool/Function calling features
  • Handling rate limits and parsing errors gracefully

Architecture

Raw Unstructured Text (e.g., PDF text)
  → Pydantic Schema Definition
  → LLM API Call (with forced Tool Calling)
  → Validation
  → Clean JSON Database Insert

Steps

  1. Collect a small set of unstructured text examples (e.g., 5 sample invoices, or 5 short bios).
  2. Define the target schema using a Pydantic BaseModel. For an invoice, this might be Invoice(date: str, total_amount: float, vendor: str).
  3. Set up the OpenAI (or Anthropic/Gemini) Python client.
  4. Pass the text and the Pydantic schema to the model using its function/tool calling API (e.g., response_format or tools).
  5. Write an extraction loop that processes all 5 files, parses the model's JSON string back into a Pydantic object, and handles validation errors if the model hallucinates a bad format.
  6. Write the final structured data out to a .json or .csv file.

← Back to the roadmap