Building Intelligent Document Parsing Systems: Balancing AI Capabilities with Deterministic Fail-Safes Jawad Ul Hadi, a backend lead and architect, built a NestJS module that converts timesheets in six formats — PDF, DOCX, XLSX, XLS, PNG and JPG — into a fixed eight-column payroll export, using deterministic parsing as the primary path and an LLM only as a bounded, redacted, budget-capped fallback. The AI path redacts PII before any external call, runs at temperature 0 with forced tool use, and its output is re-parsed and re-scored by the same deterministic pipeline, winning only if it scores strictly higher. Hadi estimates the fallback fires on roughly 40% of documents, putting AI cost at about $22 per month for 10,000 documents, and notes an AI code review caught ten real bugs before merge. - Jawad Ul Hadi, Backend Lead / Architect — AI-First Systems Design I built a NestJS module that turns timesheets in six formats PDF, DOCX, XLSX, XLS, PNG, JPG into one fixed eight-column payroll export. "AI-first" meant weighing AI at every design decision, and then using it only where it pays for itself. Deterministic parsing does the work. An LLM is a bounded, redacted, budget-capped fallback that can never fail an upload. AI was also part of how the module was built: planning, implementation, and an AI code review that caught ten real bugs before merge. HR operations receive timesheets from client sites in whatever format each site uses: weekly grids with repeated In/Out/Hours blocks, individual timecards with dated punches, monthly day-numbered sheets, scans and phone photos. Payroll needs one thing: an eight-column workbook with one row per employee per worked day . Employee Number | First Name | Last Name | Full Name | Final Department | Employee Start | Final End | Final Hours 8092 | Jane | Doe | Jane Doe | Afternoon Shift | 8/24/2026 14:30| 8/25/2026 0:00 | 9.00 The rules are simple to state and easy to get wrong: - If the source has it, extract it. If not, leave it blank. Nothing is inferred and nothing is back-filled from the HR database. - AM/PM must survive. An overnight shift's end time moves to the next day. - Start and end are real Excel datetimes, not strings. Hours are decimals. AI-first does not mean "send everything to an LLM". It means AI is considered first at every design decision, and then placed where it earns its cost, latency and privacy risk. I applied that in two places. php flowchart TD U Upload -- V{Validate MIME + size} V -- R{Route by format} R -- XLSX / XLS / DOCX -- N Native table extraction R -- Digital PDF -- T Text layer to grid R -- PNG / JPG -- O OCR to grid N & T & O -- P Deterministic parser