half-logo

Case Study

AI Mortgage Guideline Assistant

90%+ compliance accuracy. Every answer cited to a specific page and paragraph. And when the answer isn't in the documents, the AI says so instead of guessing. TechEniac built a production RAG system that mortgage professionals trust with regulatory decisions.

AI Mortgage Guideline Assistant interface

The Challenge 

Mortgage lending runs on guidelines. Thousands of pages of them. 

 Fannie Mae's Selling Guide. Freddie Mac's Seller/Servicer Guide. FHA's Single Family Housing Policy Handbook. VA Lender's Handbook. USDA Rural Development guidelines. State-specific overlays. Investor-specific amendments. Stacking rules that change quarterly, sometimes monthly. 

 A loan officer evaluating whether a borrower qualifies for a specific loan product needs to check multiple guideline documents often cross-referencing sections across different publications. "Does a borrower with a Chapter 7 bankruptcy qualify for a conventional loan?" The answer depends on the discharge date, the waiting period, the extenuating circumstances documentation, the LTV ratio, and which investor's overlay applies. The answer lives across 4 different sections in 3 different documents. 

 Today, loan officers do this manually. They search PDFs. They bookmark sections. They maintain personal reference sheets. Senior underwriters carry the answers in their heads institutional knowledge that walks out the door when they retire. Junior staff spend 20–30 minutes per guideline lookup. At scale, this consumes hundreds of person-hours weekly across a mid-size lender. 

 The founder a mortgage industry veteran with 18 years of lending experience had watched this problem compound through multiple regulatory cycles. Every guideline update triggered weeks of retraining. Every new loan officer spent months building the pattern recognition that experienced underwriters had developed over decades. 

 Generic AI tools made the problem worse, not better. ChatGPT could generate plausible-sounding answers about mortgage guidelines but plausible and correct are different things in regulated lending. A loan officer who relies on a wrong AI answer about DTI limits or waiting periods creates a compliance violation that can cost the lender its agency approval. In mortgage lending, a wrong answer isn't just unhelpful. It's potentially career-ending. 

 The founder came to TechEniac with a non-negotiable requirement: build a system where every answer comes from the actual guideline documents cited to a specific page and paragraph and when the information doesn't exist in the documents, the AI declines to answer rather than fabricating a response. No hallucination. No general knowledge. No guessing. Only the guidelines. 

 

Product Discovery & Architecture Design 

TechEniac spent the first three weeks understanding how mortgage professionals actually interact with guideline documents not just what questions they ask, but how they verify answers, how they cross-reference across documents, and where the current process fails. 

 The discovery revealed five problems that standard RAG architectures don't address: 

  •  Mortgage guidelines aren't plain text. They contain tables, nested lists, cross-references ("see Section 4.2.3.1"), decision matrices, and embedded calculations. Standard text chunking destroys these structures. A table about LTV limits chunked mid-row produces meaningless fragments that the retriever returns as "relevant" but the generator can't interpret. 

  • The same question has different answers depending on context. "What's the maximum DTI?" depends on the loan type (conventional, FHA, VA), the LTV ratio, the borrower's credit score, and whether compensating factors apply. A system that returns one answer without accounting for context creates false confidence. 

  • Documents update frequently. Fannie Mae updates its Selling Guide monthly. FHA publishes Mortgagee Letters that amend the handbook. The RAG system needs to ingest updates, version documents, and ensure the retriever surfaces the most current version not the version from 6 months ago that's now been superseded.

  • Compliance requires citation, not just accuracy. A correct answer without a source is useless in lending compliance. The loan officer needs to verify the AI's answer against the original document before relying on it. Every response must cite the specific document, section, page, and paragraph not just "according to FHA guidelines."

  • Multiple document formats. Guidelines arrive as PDFs (scanned and digital), Word documents, HTML pages, and occasionally spreadsheets. Some historical guidelines are scanned image PDFs with no text layer. The ingestion pipeline needs to handle every format and extract structured content from all of them. 

 

Based on discovery, TechEniac designed a hybrid RAG architecture: dense retrieval (Qdrant) for semantic matching combined with BM25 for exact keyword and section reference matching, fused through Reciprocal Rank Fusion. Gemini serves as the generation model for its strong document understanding and cost efficiency. Google Document AI and Tesseract OCR handle multi-format ingestion including scanned documents. 

 Technical Solution 

Multi-Format Document Ingestion Pipeline 

Mortgage guidelines arrive in every format digital PDFs, scanned PDFs, Word documents, HTML, and spreadsheets. The ingestion pipeline normalises all formats into a unified structured representation. 

Digital PDFs are processed through Google Document AI, which preserves table structures, nested lists, and hierarchical headings that standard PDF parsers flatten. Scanned PDFs common for older guidelines and state-specific overlays pass through Tesseract OCR with pre-processing for skew correction, noise reduction, and resolution normalisation. 

The pipeline extracts not just text but structure: document title, section hierarchy, paragraph numbering, table contents with row/column relationships, and cross-reference links. This structural metadata becomes part of every chunk's retrieval context so when the AI retrieves a chunk, it knows which section it came from, what section precedes and follows it, and whether it's part of a table or a narrative rule. 

Document versioning tracks every update. When Fannie Mae publishes a new Selling Guide revision, the pipeline ingests the update, maps changed sections against the previous version, and flags which answers may be affected by the revision. The retriever always surfaces the current version with the option to query historical versions for audit purposes. 

Structure-Aware Semantic Chunking 

Standard character-based chunking destroys the meaning of structured documents. A DTI table chunked mid-row. A rule split from its exception. A cross-reference separated from the section it references. 

TechEniac built a structure-aware chunking strategy that respects document architecture. Chunks are defined by document structure section boundaries, paragraph boundaries, complete table units, and complete list items not by token count. A section that runs 2,000 tokens stays as one chunk if it represents one complete rule. A table is always chunked as a complete unit with its header row preserved. Each chunk carries rich metadata: document name, version date, section number, page number, paragraph identifier, and a parent-child relationship to its containing section. This metadata enables precise citation ("Fannie Mae Selling Guide, Section B3-5.3-01, Page 412, Paragraph 3") and scoped retrieval ("retrieve only from FHA guidelines" or "retrieve only from sections updated after January 2026"). 

Hybrid Retrieval with Reciprocal Rank Fusion 

Single-method retrieval fails in mortgage compliance for predictable reasons. 

Dense retrieval (embedding similarity) handles natural language questions well "Can a borrower with a bankruptcy qualify?" but misses exact reference lookups "Section 4.2.3.1" or "Mortgagee Letter 2025-07." The embeddings capture meaning but not identifiers. 

Sparse retrieval (BM25 keyword matching) handles exact references and specific terms "DTI ratio," "LTV limit," "Chapter 7 waiting period" but misses semantic rephrasing "How much debt can a borrower have?" doesn't match "debt-to-income ratio" through keywords alone. 

TechEniac implemented a hybrid retrieval system that runs both methods in parallel and fuses results through Reciprocal Rank Fusion (RRF). Dense retrieval via Qdrant captures semantic meaning. BM25 captures exact terminology and section references. RRF combines the ranked results, weighting each method based on query type analysis. 

A query classifier determines the optimal weight distribution per query. Natural language questions weight dense retrieval higher (70/30). Section reference lookups weight BM25 higher (30/70). Mixed queries "What does Section 4.2 say about bankruptcy?" receive balanced weights (50/50). 

This hybrid approach achieves 90%+ compliance accuracy measured against a golden test set of 150 real mortgage compliance questions with verified answers. 

Grounded Generation with Mandatory Citation 

Every response from MortgageLens AI cites its source document name, section number, page, and paragraph. This isn't optional formatting. It's architecturally enforced. 

The generation prompt structure requires Gemini to include inline citations for every factual claim. A post-generation validation step verifies that every cited section actually exists in the retrieved documents and that the cited content supports the claim. Responses with unverifiable citations are rejected and regenerated. 

The citation format is designed for compliance workflows. A loan officer reading the AI's answer can click the citation and navigate directly to the source section in the original document verifying the AI's interpretation against the guideline text in seconds, not minutes. 

Confident Refusal on Out-of-Scope Questions 

This is the feature that makes MortgageLens trustworthy in a regulated environment. 

When a user asks a question that isn't covered by the ingested guidelines or when the retrieved documents don't contain a relevant answer the system declines to answer. It doesn't guess. It doesn't generate a plausible-sounding response from Gemini's general knowledge. It responds: "This question is not covered in the currently ingested guidelines. Please consult your compliance team directly." 

 A dual-gate system enforces this. First, the retrieval relevance score must exceed a configurable threshold if the best-matching chunk isn't sufficiently relevant, the system declines. Second, a term overlap check verifies that the retrieved content actually addresses the query's subject matter preventing the common failure where the retriever returns the "closest but wrong" section. 

The system declines approximately 8% of queries questions about topics genuinely not covered in the guidelines, questions about state-specific rules when only agency guidelines are ingested, and ambiguous questions that could apply to multiple loan types without sufficient context. 

That 8% decline rate is a feature, not a failure. Every declined answer is an answer that would have been fabricated by a system without this guardrail and in mortgage compliance, a fabricated answer is worse than no answer. 

 

Key Engineering Challenges 

Challenge 1 

Table Extraction Accuracy 

Mortgage guidelines rely heavily on tables DTI matrices, LTV limit grids, waiting period schedules, reserve requirement calculations. Standard PDF parsers extract table text but lose the row/column structure, making the data meaningless. 

TechEniac implemented Google Document AI's table extraction with a post-processing validation layer. Extracted tables are validated against expected column counts and data types (percentages, dollar amounts, time periods). Tables failing validation are flagged for manual review rather than ingested with incorrect structure. 

 Table extraction accuracy reached 94% on first pass, with the remaining 6% caught by the validation layer and corrected before ingestion. 

Challenge 2 

Cross-Reference Resolution 

Mortgage guidelines frequently reference other sections "Subject to the requirements in Section B3-5.3-01" without restating the referenced content. A chunk containing a cross-reference without the referenced content produces an incomplete answer. 

TechEniac built a cross-reference resolution layer that identifies section references within chunks, retrieves the referenced section, and appends it as supplementary context during generation. The AI sees both the original chunk and the referenced section producing complete answers that account for cross-dependencies. 

Cross-reference resolution increased answer completeness by 23% on questions involving multi-section rules. 

Challenge 3 

Guideline Version Conflicts 

When a guideline updates, the old version's chunks still exist in the vector database alongside the new version's chunks. Without version management, the retriever might surface outdated guidance telling a loan officer the waiting period is 4 years when the latest update changed it to 3 years. 

TechEniac implemented a version-aware retrieval system. Every chunk carries a version timestamp and document revision identifier. The retriever defaults to the most current version but supports explicit historical queries ("What was the DTI limit before the January 2026 update?"). When a new version is ingested, superseded chunks are flagged not deleted preserving audit trail while ensuring current guidance takes priority. 

 Zero instances of outdated guidance surfaced in production since version management was deployed.

Results

Measurable Impact

90%+
Compliance Accuracy measured against 150 real mortgage compliance questions with verified answers from certified underwriters
100%
Citation Rate every answer includes document name, section, page, and paragraph architecturally enforced, not optional
~8%
Confident Refusal Rate questions not covered in guidelines receive an explicit decline not a fabricated answer
94%
Table Extraction Accuracy on first pass, with validation layer catching the remaining 6% before ingestion
23%
Answer Completeness Improvement from cross-reference resolution multi-section rules answered completely, not partially
60%
Reduction in Repeat Query Costs semantic caching catches equivalent questions asked in different words

Technology

Tech Stack

AI / ML Gemini (generation + document understanding), LangChain (orchestration), Sentence-BERT (embeddings)
Retrieval Qdrant (dense vector search), BM25 (sparse keyword search), Reciprocal Rank Fusion (hybrid combination)
Document ProcessingGoogle Document AI (structured PDF extraction), Tesseract OCR (scanned documents), Whisper (audio guideline transcription)
Backend Python, FastAPI, PostgreSQL (metadata + versioning), Redis (caching)
Frontend React.js, TypeScript, Tailwind CSS
Cloud & DevOpsAWS ECS (Fargate), RDS PostgreSQL, S3 (document storage), GitHub Actions CI/CD

Ready to be the next case study?

Book a free 30-minute strategy session. We’ll review your product idea, discuss architecture options, and map a realistic path from idea to launch.