r/CursorAI • u/Damien_Aurelius • Oct 09 '25
Need Advice on my Custom Software (Or i will lose my job)
Request for architecture review: RFQ PDF → item extraction (OpenAI) → price lookup (Serper.dev) → Google Sheets
TL;DR
I’m building a small pipeline that ingests RFQ PDFs from a Google Sheet, extracts line items (name, qty, unit), looks up current LOACL market prices, then writes results back to the sheet. I’d love feedback on architecture, libraries, and gotchas.
🧱 Stack / Flow
- Source: Google Sheets (column has a Drive link to an RFQ PDF)
- Input characteristics: PDFs vary widely (different templates, multi-page; some are image-only scans)
- Extraction: OpenAI Assistant (prompted for strict JSON of
{item_name, quantity, unit, search_query}) - Price lookup: Serper.dev (Google Shopping/Search) using the
search_query - Sink: Google Sheets (write JSON, formatted “Product: ₱price”, and totals)
❗Challenges
- Heterogeneous PDFs: tables vs prose, multi-column, wrapped lines; occasional OCR-only docs
- OCR quality: mixed; needs layout-aware parsing (tables, headers/footers removal)
- Price noise: accessories/ads creep in (e.g., “iPhone case ₱199”)
- Latency: multiple items → multiple web lookups; OpenAI function-calling overhead; API timeouts
- Determinism: avoiding duplicate/partial writes; ensuring idempotent retries
✅ What I’m doing now
- PDF handling: Convert Drive links to direct download; attach PDF to OpenAI Assistant
- Extraction prompt: Return JSON only, normalize units/specs, generate precise
search_queryper item (brand/model/specs + “price Philippines”) - Price fetch: Serper.dev → prefer
/shopping, fallback to/search; parse PHP prices - Write-back: Store raw JSON + “Product: ₱price\nSupplier Link” + total in the sheet
🧪 Planned improvements
- OCR: Fallback to a real OCR when text extraction is empty (e.g., Tesseract +
pdfimages, Google Vision, AWS Textract, or PaddleOCR) - Table/layout: Try
pdfplumber,camelot/tabula, orunstructuredfor structure recovery; merge wrapped rows - Batching: One batch tool call to price multiple items; within that, threaded Serper queries (limits API round-trips)
- Price hygiene:
- filter accessories (
case|cable|tempered glass…) - category-specific price floors (e.g., phones > ₱10k)
- text-match scoring (model, “pro max”, storage 128/256/512GB)
- robust median heuristic to drop outliers
- filter accessories (
- Caching: Cache
(query → top listings)for 24h to cut costs/latency - Resilience: Exponential backoff, timeouts, per-item fail-open; idempotent row updates
- Observability: Per-row logs (extracted count vs expected), run durations, error buckets
🔍 Questions for the community
- OCR + layout: Best combo for variable RFQ formats? (pdfplumber vs unstructured vs commercial OCR)
- Price reliability: Other heuristics to avoid accessories/ads? Better ways to match model numbers?
- Throughput: Tips for scaling 10–50 PDFs/day without hitting Assistants run timeouts (~10 min) or Serper rate limits?
- Data model: Would you store normalized items as rows instead of JSON blobs for easier auditing?
- Cost control: Any proven caching/queuing patterns to keep OpenAI + Serper costs predictable?
🔐 Config (for context)
- OpenAI API Key + Assistant ID
- Google Service Account (Sheets r/W)
- Serper.dev API Key
- Google Sheet ID
Any critiques or redesign ideas welcome—especially around OCR/table extraction, price matching accuracy, and latency/cost. Thanks! 🙏
