← Back to Projects
Structured Extraction Pipeline
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
- Collect a small set of unstructured text examples (e.g., 5 sample invoices, or 5 short bios).
- Define the target schema using a Pydantic
BaseModel. For an invoice, this might beInvoice(date: str, total_amount: float, vendor: str). - Set up the OpenAI (or Anthropic/Gemini) Python client.
- Pass the text and the Pydantic schema to the model using its function/tool calling API (e.g.,
response_formatortools). - 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.
- Write the final structured data out to a
.jsonor.csvfile.