Skip to content
Goal: Proficient✓ Sources verified 2026-11-24File UploadOCRWebhookObject Storage

Data Ingestion and File Parsing ​

The first link in the pipeline, "ingestion": normalize data from every source and format into one internal format.

Core concepts ​

SourceKey handling points
User uploadsSize and type limits, virus scanning (depending on compliance needs), store the original file in object storage
Mailbox pollingScheduled fetching, dedupe by Message-ID, split out attachments
Webhooks (pushed by customer systems)Signature verification, return 2xx quickly, process asynchronously, dedupe by event ID
Pulling from third-party APIsPagination, rate limits, incremental cursors, retry on failure

Unified output: Document { id, source, original_uri, mime, sha256, parsed_text, pages[], meta }.

How it works ​

  • Store the original before processing: write the original file to object storage (S3 / MinIO / OSS) and record its sha256. Every later step can be replayed from the original, and you can dedupe by hash.
  • Layered parsing:
    • Native digital PDFs: extract the text layer directly (e.g. PyMuPDF, pdfplumber)
    • Scans / images: OCR, or hand them straight to a multimodal model
    • Office documents: python-docx, openpyxl, or convert to PDF first
  • Webhook reliability: senders usually retry, so the receiver must be idempotent; verify the signature to prevent forgery (usually an HMAC over the request body).

In practice: receiving a webhook ​

python
import hmac, hashlib
from fastapi import Request, HTTPException

@router.post("/webhooks/erp")
async def erp_webhook(request: Request):
    body = await request.body()
    sig = request.headers.get("X-Signature", "")
    expected = hmac.new(settings.ERP_SECRET.encode(), body, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(sig, expected):          # constant-time comparison against timing attacks
        raise HTTPException(401, "invalid signature")
    event = ErpEvent.model_validate_json(body)
    created = await create_task_if_absent(idempotency_key=f"erp:{event.id}", payload=event)
    return {"accepted": True, "duplicate": not created}  # return immediately; a worker does the processing

Letting a multimodal model read the PDF directly ​

Both the Claude and OpenAI APIs accept PDFs as input (the model sees both the text and the page images). For tables and scans this is often simpler than a traditional OCR pipeline. Mind the page limits and token cost, and keep traditional parsing as a fallback.

Common pitfalls ​

  1. Doing slow work synchronously in a webhook: the sender times out and retries, causing duplicates. Return immediately and process asynchronously.
  2. Comparing signatures with ==: exposes you to timing attacks. Use hmac.compare_digest.
  3. Not keeping the original: after the parsing logic improves, you can't re-run historical data.
  4. Encodings and tables: garbled Chinese PDFs, tables broken apart. Spot-check parsing results.

Common interview questions ​

  1. How would you design an endpoint that receives third-party webhooks?
  2. How does parsing a scan differ from parsing a digital PDF?
  3. Why store the original file first? How do you dedupe?
  4. When should a multimodal model read the document directly, and when should you use traditional OCR?

Sources ​

Vin Amory · AI development × content creation · Technical notes cite official docs in each page’s sources section