The Challenge: 18,000 Pages of Legal Compliance

When starting a three-month technical internship at SkipCash, the designated task was auditing over 600 commercial merchant agreements. Each PDF was approximately 30 pages long, containing mandatory legal clauses, fee structures, signatory validation boxes, and regulatory attachments required by Qatar financial authorities.

Auditing this manually across 18,000 pages was projected to take 90 full working days. After manually reviewing the first 20 agreements to understand every pattern and edge case, it became evident that 85-90% of compliance criteria were deterministic rules that could be codified programmatically.

Architecture of the Hybrid Verification Pipeline

The automated solution was designed as a tiered processing pipeline in Python:

1. Deterministic PDF Text & Geometry Extraction: Using pdfplumber to extract both raw text streams and bounding boxes of signature fields, avoiding the overhead and potential hallucinations of vision models for clean vector text.
2. Regular Expression & Anchor Matching: Codified 34 distinct legal requirements into structured regex patterns with surrounding context windows to catch variations in merchant phrasing.
3. Structured JSON Validation Schema: Converted extracted clause values into a rigid Pydantic data model.
4. Selective LLM Fallback: For ambiguous paragraphs or scanned pages with OCR noise, passed the candidate text snippet to a local language model with strict JSON formatting instructions.

# Conceptual extraction pattern for mandatory indemnity clause
import re
from pydantic import BaseModel, Field

class AgreementAuditResult(BaseModel):
merchant_id: str
jurisdiction_clause_valid: bool
settlement_terms_days: int
signature_block_present: bool
missing_clauses: list[str] = Field(default_factory=list)

Results & Production Outcomes

Auditing Velocity: Rapid automated execution across hundreds of commercial contract pages.
Accuracy: High reliability in flagging missing signature fields and clause discrepancies when cross-checked with physical paperwork archives.
Timeline Reduction: Transformed a 3-month manual review into a 3-week project (including full physical verification).

Key Technical Lessons

Rule-First, AI-Second: Deterministic code should always perform the initial filtering. Using LLMs for basic pattern matching increases latency and cost without improving accuracy.

  • Ground-Truth Calibration: Manually reading the first 20 documents was the most valuable investment because it exposed real formatting quirks before any code was written.