Indian public procurement runs on dense, semi-structured PDFs. A single Government e-Marketplace (GeM), GAIL, or PSU Notice Inviting Tender (NIT) packet routinely mixes Hindi and English headers, embeds scanned stamped annexures inside native digital PDFs, encodes critical bid exemptions as Wingdings glyphs, and hides legally binding overrides inside external hyperlinked Additional Terms & Conditions (ATC) files.
While building TENDER_VOLKS during my internship at Volks Energies, our goal was straightforward on paper: ingest raw government tender PDFs and automatically populate a verified, 70+ column procurement evaluation sheet—including NIT Number, EMD Amount, Tender Fee, Submission Deadlines, PBG %, Payment Terms, and Eligibility Criteria—with block-level traceability and zero hallucinated numbers.
Here is a look under the hood at why naive "PDF-to-LLM" approaches broke immediately, and how a two-layer deterministic + generative architecture allowed us to process typical 6–8 page GeM tenders in under 81 seconds on CPU-only hardware.

Why Naive "Dump-to-LLM" Pipelines Fail on Procurement PDFs
Our earliest prototype extracted raw text from a PDF and passed it into an LLM prompt asking for structured JSON. In real procurement workflows, that failed across four failure modes:
- Silent Font-Map Corruption & Mixed Raster Pages: Many PSU tenders look selectable in a PDF viewer, yet calling standard text extraction yields garbled
(cid:14)(cid:29)glyph sequences or drops scanned stamp pages entirely. - Spatial Loss in Borderless Tables: Flattening two-column GeM bid tables into plain text scrambles key-value adjacency—causing an EMD amount from one row to associate with a Tender Fee label nearby.
- Wingdings Checkboxes: Critical yes/no flags (such as MSE/Startup EMD Exemption or Reverse Auction applicability) are frequently encoded as private-use Unicode glyphs (
\uf050vs\uf04f) rather than words. - Cross-Document Legal Precedence: A GeM bid summary may state standard payment terms on page 2 while linking to an external ATC PDF (
bidplus.gem.gov.in) whose clauses legally override the parent document.
To make extraction trustworthy for human bid-evaluation teams, every extracted field needed a bounding box, a confidence score, and deterministic source attribution.
System Architecture: A Two-Layer Hybrid Pipeline
Instead of forcing an LLM to read every page of every tender, TENDER_VOLKS separates spatial extraction from semantic fallback:
- Layer 1 (Deterministic Spatial Extraction): Classifies each page independently, runs multilingual Hindi-English OCR (
PaddleOCR+PP-StructureV3/eng+hinfallback) only where needed, reconstructs 2D table grids, resolves child ATC hyperlinks, and extracts 30+ core fields via spatial anchors and clause-scoped regex rules. - Layer 2 (Schema-Constrained LLM Fallback & Memory): Invokes structured LLM resolution exclusively on fields still marked
MISSINGorNAafter Layer 1, conditioned on persistent few-shot reviewer corrections and source-span anti-hallucination checks.
def extract_page_hybrid(page: fitz.Page, dpi: int = 300) -> PageResult: """Route each page to fast native extraction or 300-DPI multilingual OCR.""" raw_text = page.get_text("text") # Detect scanned pages or corrupted (cid:X) font glyph tables if is_scanned_page(raw_text) or has_corrupted_cid_glyphs(raw_text): pixmap = page.get_pixmap(matrix=fitz.Matrix(dpi / 72, dpi / 72)) preprocessed = enhance_contrast_and_sharpen(pixmap, contrast=2.0) return run_multilingual_ocr(preprocessed, langs=("en", "hi")) words = page.get_text("words") checkboxes = parse_wingdings_checkboxes(page) return reconstruct_spatial_blocks(words, checkboxes)
Hybrid Page Routing & CPU Speed
Rasterizing an entire 15-page tender at 300 DPI on CPU is expensive. By inspecting character density and (cid:X) corruption ratios per page using PyMuPDF, native digital pages bypass pixel rendering in milliseconds while scanned annexures receive contrast-enhanced (2.0x), sharpened 300 DPI OCR via PaddleOCR and PP-StructureV3.
For Wingdings checkboxes, we map private-use glyphs (\uf050 / \uf0fe → [X], \uf04f → [ ]) and pair each checkbox with its nearest clause label using 2D Euclidean distance over bounding-box centroids.
Cross-Document ATC Resolution & Precedence Rules
In GeM tenders, the most consequential commercial terms rarely live in the parent bid PDF—they live inside a hyperlinked Additional Terms & Conditions (ATC) attachment.
Our link extractor (pdf_link_extractor.py) inspects page.get_links() for fitz.LINK_URI annotations, warms up an HTTP session with bidplus.gem.gov.in, downloads child attachments, and verifies %PDF magic bytes before running the same Layer 1 pipeline on the child file. When both documents specify values for the same field, our merge orchestrator applies strict procurement precedence rules:
| Precedence Tier | Representative Fields | Resolution Strategy |
|---|---|---|
| ATC Authoritative | Payment Terms, Liquidated Damages (LD), Security Deposit, Consignee Contacts | Child ATC value overrides the parent GeM bid summary. |
| Main Document Locked | NIT / Bid Number, Bid End Date, PBG %, Bid Validity | Locked to the parent GeM summary to prevent annexure date collisions. |
| Ambiguous / Dual | Warranty Period, Delivery Timeline, Inspection Agency | Preserves both ({"main_tender": ..., "atc": ...}) for human verification. |
We also built domain-specific propagation rules—for instance, when an MSE/Startup Financial Criteria Exemption flag is detected as [X], downstream fields like Minimum Annual Turnover, Solvency Certificate, and Net Worth automatically resolve with traceable exemption metadata rather than triggering false MISSING alerts.
Layer 2: Hallucination-Safe LLM Fallback & Domain Fine-Tuning
When an unusual prose clause evades deterministic rules, Layer 2 (llm_field_resolver.py) steps in—but under strict guardrails:
- Delta-Only Execution: The model only receives unresolved fields and their surrounding clause slices, keeping prompts compact (~240 median input tokens).
- Continuous Few-Shot Reviewer Memory: Whenever a procurement analyst corrects a field in the React workspace UI, the
(anchor_text, corrected_json)pair is persisted toextraction_memory.json. Future tenders retrieve similar clauses as dynamic few-shot examples. - Source Grounding Verification: Extracted monetary values, percentages, and dates are cross-checked against normalized source text before merging; ungrounded generations are rejected rather than written to the database.
{ "nit_number": { "value": "GEM/2026/B/7306631", "confidence": 0.984, "source": "main_tender", "page": 1, "bbox": [312.4, 148.0, 518.2, 166.5], "verified": true }, "emd_amount": { "value": "₹1,94,177", "confidence": 0.961, "source": "main_tender", "page": 2, "bbox": [118.0, 402.5, 244.8, 419.0] } }
To eliminate prompt-preamble drift on local deployments, I also built an offline Domain Adaptation (DAPT + SFT) pipeline:
- Constructed a ~438 MB domain corpus from historical GeM/PSU tenders using 2D bounding-box table reconstruction that preserves Indian numbering units (
₹, Lakh, Crore). - Deduplicated ground-truth audits and reviewer memory via SHA-256 hashing into clean instruction-tuning splits (
dataset_sft.jsonl), auditing sequence lengths with theQwen/Qwen2.5-7B-Instructtokenizer (maximum 2,170 tokens, fitting comfortably inside a 4,096-token context budget for 4-bit LoRA training and GGUF quantization).
Async FastAPI Microservices & Production Results
Because OCR and child-PDF resolution are I/O- and CPU-intensive, synchronous HTTP endpoints would time out under concurrent uploads. We designed the backend around an asynchronous FastAPI job lifecycle:
POST /tenders/uploadvalidates PDF magic bytes, persists the raw artifact, initializes a thread-safe SQLite job state machine (pending→processing→completed/failed), and immediately returnsHTTP 201 Createdwith ajob_id.- Background workers stream live stage transitions to the React 19 workspace UI while persisting normalized
TenderInformationrecords (70+ columns) to PostgreSQL and generating stylized multi-tab Excel InfoSheets viaOpenPyXL.
Key Takeaways & Metrics
- Sub-81s CPU Latency: Typical 6–8 page bilingual GeM tenders process end-to-end in under 81 seconds on CPU-only hardware, avoiding mandatory GPU cloud bills for routine bid triage.
- Deterministic First, Generative Second: Handling ~85% of structured tables and checkboxes deterministically via PaddleOCR, PP-StructureV3, and spatial rules made LLM fallback faster, cheaper, and dramatically easier to audit.
- Human-in-the-Loop Compounding: Pairing bounding-box highlights in the UI with a persistent few-shot correction store meant every human review directly improved extraction accuracy on subsequent tenders from the same issuing authority.
You can explore the architecture and source code on GitHub at yuvrajsharmaaa/TENDER_VOLKS.