Contents
Section 01
Full Pipeline Architecture
Documents uploaded by advisors flow through an 8-step pipeline that ensures PII is stripped before any AI sees the content:
flowchart TD
subgraph CLIENT["Browser - Client-Side"]
A1["Advisor selects document\n(image/PDF)"]
A2["Browser upload client\n(direct-to-S3)"]
end
subgraph EDGE1["Supabase Edge Function\n(analyze-strategy)"]
B1["get_upload_url action\nGenerates pre-signed S3 URL\n300-second TTL"]
end
subgraph AWS["AWS Infrastructure"]
C1["S3 Bucket\nBlockPublicAccess\nAES-256 at rest"]
C2["Lambda Function\n(stateless)\nAWS Textract OCR for images\n→ Text + first redaction pass"]
end
subgraph EDGE2["Supabase Edge Function\n(extract-liabilities / extract-mortgage-statement / extract-fees)"]
D1["Read PDF text layer in-edge\nelse invoke Lambda\n(liabilities + statements only)"]
D2["In-boundary redaction\nregex + AWS Comprehend when enabled"]
D3["Claude Haiku 4.5 (primary)\nGemini 3.5 Flash (backup)\nStructured JSON extraction"]
D4["Usage tracking\n→ Privacy Guardrail audit write"]
end
subgraph GUARDRAIL["Privacy Guardrail Layer"]
G1["Text pattern scan\n6 PII pattern types"]
G2["Object key redaction\n10+ sensitive keys"]
G3["Audit write\nDouble-sanitize before store"]
end
subgraph DB["Supabase PostgreSQL"]
E1["AI audit log\n(sanitized payloads)"]
E2["Usage metrics\n(token counts, costs)"]
end
A1 -->|"1. Request upload URL"| B1
B1 -->|"2. Return signed URL + object key"| A2
A2 -->|"3. PUT file directly to S3\n(browser to S3, no app server)"| C1
C1 -->|"4. Edge reads the object"| D1
D1 -->|"5. No text layer: edge invokes Lambda"| C2
C2 -->|"6a. Returns OCR text"| D2
D1 -->|"6b. Text-layer PDF text"| D2
D2 -->|"7. Redacted text sent to model"| D3
D3 -->|"8. Structured JSON returned"| CLIENT
D4 --> GUARDRAIL
GUARDRAIL --> E1
D4 --> E2
style CLIENT fill:#1e293b,stroke:#3b82f6,color:#e2e8f0
style AWS fill:#0f172a,stroke:#f59e0b,color:#e2e8f0
style EDGE1 fill:#1e293b,stroke:#22c55e,color:#e2e8f0
style EDGE2 fill:#1e293b,stroke:#22c55e,color:#e2e8f0
style GUARDRAIL fill:#1e293b,stroke:#ef4444,color:#e2e8f0
style DB fill:#0f172a,stroke:#8b5cf6,color:#e2e8f0
Section 02
Step-by-Step Data Flow
Upload Request (Browser → Edge)
The browser requests a pre-signed URL from the analyze-strategy edge function. No file data is transmitted in this step. Only the filename and MIME type.
Pre-Signed URL Generation (Edge → S3)
The edge function generates a time-limited, 300-second pre-signed URL for one object key. The URL authorizes a PUT to that key in the S3 bucket and nothing else, and it expires 300 seconds after it is issued.
Direct Upload (Browser → S3)
On the way in, the file goes directly from the browser to S3 in WealthLens's AWS account. The upload does not pass through the application server, the Supabase edge function, or any intermediary. The S3 bucket has BlockPublicAccess enabled and uses AES-256 encryption at rest.
OCR Processing (Edge → Lambda → Textract)
For a PDF with a genuine text layer, the edge function reads the text itself and skips OCR. What happens otherwise depends on the importer. The liability and mortgage statement importers (extract-liabilities, extract-mortgage-statement) fall back to a stateless AWS Lambda in our account: for an image upload (PNG or JPEG), including a pasted screenshot, which is uploaded to the bucket as an image, it runs AWS Textract OCR, and for a PDF it re-reads the file with a Python PDF parser. The fee importer (extract-fees, Loan Estimates and Closing Disclosures) has no OCR path: it reads the PDF text layer only, and a scanned or image-only PDF is rejected with a message asking for the original text PDF. The Lambda execution environment is stateless. It is destroyed after processing.
PII Sanitization (Privacy Guardrail)
Before any document text reaches an extraction model, it is redacted inside our AWS boundary: the Lambda strips SSNs, labeled borrower names and street addresses from what it returns; the edge function then runs an AWS Comprehend entity-detection pass (names, addresses and other personal identifiers) when enabled for the project and, always, a regex pass for SSNs, labeled names and street addresses. The conversational and analysis functions run the Privacy Guardrail instead, which sanitizes at two levels: pattern-based text scanning and key-based object redaction. See Section 03 for the full redaction specification.
AI Extraction (Claude Haiku 4.5, Gemini 3.5 Flash backup)
The redacted text is sent to Claude Haiku 4.5 (Anthropic) with a strict system prompt that demands one JSON shape. If that call fails or returns an unusable shape, the same redacted text goes to Gemini 3.5 Flash (Google) as the backup, with thinking disabled. Neither model receives the file or image: both see only redacted text (balances, rates, payments, fee amounts), with identifiers replaced by [REDACTED_*] tokens.
Audit Trail (Guardrail → AI Audit Log)
Every AI interaction is logged to an immutable audit log with double-sanitized payloads. The input is sanitized once before the AI call and again before the database write (defense in depth).
Results Returned to Browser
Structured JSON (liabilities, statement fields or fees) is returned to the browser. The advisor sees extracted financial data in the UI. The document text and the model's request context live in memory for the duration of the request and are not written to any WealthLens table. The audit row records the storage key, the file name (liabilities and statements) or the document type (fees), which model served the call, the token counts, and the first 2,000 characters of the model's structured JSON reply (creditor names, balances, statement fields, fee labels and amounts); the document text itself is never stored. WealthLens does not delete the uploaded file as part of the import; it remains in the encrypted, private S3 bucket in WealthLens's AWS account until removed by us or by a bucket retention setting, and it is never exposed publicly.
Section 03
Privacy Guardrail Deep Dive
The Privacy Guardrail is the shared sanitizer used by the conversational and analysis functions (WealthLens IQ, AI Architect, Lens Guide, Client IQ) before the model call, and by every AI audit-log write. The document importers redact inside the AWS boundary first (Step 5); when their audit rows are written, this layer sanitizes the input payload, while the model's structured reply is stored as returned.
Level 1: Pattern-Based Text Scanning
| # | PII Type | Pattern | Replacement |
|---|---|---|---|
| 1 | SSN | \b\d{3}-\d{2}-\d{4}\b | [REDACTED_SSN] |
| 2 | [a-zA-Z0-9._%+-]+@....[a-zA-Z]{2,} | [REDACTED_EMAIL] | |
| 3 | Phone | US formats: (555) 555-5555, etc. | [REDACTED_PHONE] |
| 4 | Credit Card | 13 to 16 digit sequences | [REDACTED_CC] |
| 5 | Date of Birth | MM/DD/YYYY and YYYY-MM-DD | [REDACTED_DOB] |
| 6 | Address | Number + words + street suffix | [REDACTED_ADDRESS] |
Level 2: Key-Based Object Redaction
Any JSON object passed through the guardrail has these keys auto-redacted regardless of value:
All values for these keys are replaced with [REDACTED]. All other string values are run through the text pattern scan. Objects and arrays are recursed into.
Level 3: Audit Log Sanitization
Even after the above two layers, the audit log write performs a third sanitization pass on the input payload before database insertion. Defense in Depth.
Section 04
AI Edge Function Integration
Every user-facing AI edge function on this page writes its audit row through the Privacy Guardrail (which sanitizes the input payload; the model's reply is stored as returned), and the conversational and analysis functions sanitize their payloads with it before the model call; the document importers redact inside the AWS boundary first (Section 02, Step 5). WealthLens runs a multi-model stack: conversational and analysis reasoning runs on Anthropic Claude (Haiku 4.5 / Sonnet 5.5), document extraction runs on Claude Haiku 4.5 with Google Gemini 3.5 Flash as the backup, and Guideline Gary runs on Anthropic Claude Sonnet 5.5 with web-search grounding. Every vendor is used under zero-retention, no-training API terms.
flowchart LR
subgraph FUNCTIONS["Edge Functions Using Guardrail"]
F1["analyze-strategy\n(WealthLens IQ)\nClaude Haiku 4.5"]
F2["strategy-architect-v3\n(AI Architect)\nClaude Sonnet 5.5"]
F3["extract-liabilities /\nextract-mortgage-statement\n(Doc Parser)\nClaude Haiku 4.5\nbackup Gemini 3.5 Flash"]
F4["extract-fees\n(Fee Extractor)\nClaude Haiku 4.5\nbackup Gemini 3.5 Flash"]
F5["lens-guide\n(Advisor Help)\nClaude Haiku 4.5"]
F6["client-chat-v3\n(Client AI)\nClaude Haiku 4.5"]
F7["guideline-gary\n(Guideline Expert)\nClaude Sonnet 5.5\n+ web search"]
end
subgraph GUARDRAIL["Privacy Guardrail"]
G1["Sanitize payload\nBefore AI call"]
G2["Audit write\nAfter AI call\n(double-sanitized)"]
end
subgraph AUDIT["AI Audit Log"]
A1["Sanitized input_payload\nOutput summary\nToken usage\nUser/Session ID"]
end
F1 --> G1
F2 --> G1
F3 -->|"in-boundary redaction first;\naudit input sanitized,\nreply stored as returned"| G2
F4 -->|"in-boundary redaction first;\naudit input sanitized,\nreply stored as returned"| G2
F5 --> G1
F6 --> G1
F7 -->|"audit-log sanitize only"| G2
G1 --> G2
G2 --> A1
style FUNCTIONS fill:#1e293b,stroke:#3b82f6,color:#e2e8f0
style GUARDRAIL fill:#1e293b,stroke:#ef4444,color:#e2e8f0
style AUDIT fill:#0f172a,stroke:#8b5cf6,color:#e2e8f0
| Function | Purpose | Model | Guardrail Usage |
|---|---|---|---|
analyze-strategy | WealthLens IQ analysis, deep dives, FAQs | Claude Haiku 4.5 (Anthropic); legacy per-action paths on Gemini 3.5 Flash (Google) | Payload sanitization + audit log |
strategy-architect-v3 | Conversational strategy builder | Claude Sonnet 5.5 (Anthropic) | Payload sanitization + audit log |
extract-liabilitiesextract-mortgage-statement | Document → liability extraction; mortgage statement → loan fields (same pipeline) | Primary Claude Haiku 4.5 (Anthropic), backup Gemini 3.5 Flash (Google) | In-boundary redaction (Lambda regex + AWS Comprehend when enabled + edge regex), AWS Textract OCR for images, sanitized input payload in the audit log; the structured reply is stored as returned |
extract-fees | Document → fee extraction (text-layer PDFs only, no OCR) | Primary Claude Haiku 4.5 (Anthropic), backup Gemini 3.5 Flash (Google) | In-boundary redaction (AWS Comprehend when enabled + edge regex), sanitized input payload in the audit log; the structured reply is stored as returned |
lens-guide | Advisor help assistant | Claude Haiku 4.5 (Anthropic) | Payload sanitization + audit log |
client-chat-v3 | Client-facing AI concierge | Claude Haiku 4.5 (Anthropic) | Payload sanitization + audit log |
guideline-gary | Agency guideline expert (FHA/VA/USDA/Fannie/Freddie), web-search grounded | Claude Sonnet 5.5 (Anthropic), web search and fetch on the agency source list | Usage tracking + audit write |
Want this same architecture protecting your client files?
WealthLens is live. Start now: $1 today, 30-day trial, then $149 a month until you cancel. Or book a free demo first.
Start your trial for $1 Book a Free DemoSection 05
Document Types Supported
Liability Extraction (extract-liabilities)
| Input | Output Schema |
|---|---|
| Liability statements, credit reports, 1003-style PDFs | { liabilities: [{ type, name, balance, monthlyPayment, interestRate, toBePaidOff }] } |
Supported types: CREDIT_CARD, AUTO_LOAN, STUDENT_LOAN, PERSONAL_LOAN, OTHER
Fee Extraction (extract-fees)
| Input | Output Schema |
|---|---|
| Loan Estimates, Closing Disclosures, Good Faith Estimates, Fee Sheets | { fees: [{ label, amount, section, isApr }], credits: { lenderCredits, sellerCredits, earnestDeposit } } |
Fees are auto-categorized into: ORIGINATION, SERVICES, TITLE_GOV, PREPAIDS, ESCROWS, OTHER
Document type is auto-detected from the document text (e.g., presence of "Loan Estimate" string).
Mortgage Statement Extraction (extract-mortgage-statement)
Monthly servicer statements ride the same pipeline as liability extraction: the same text-layer fast path, the same Lambda OCR fallback for images, the same in-boundary redaction, and the same model pair (Claude Haiku 4.5 primary, Gemini 3.5 Flash backup).
Section 06
Data Lifecycle Summary
flowchart TD
subgraph EPHEMERAL["Ephemeral - Destroyed After Use"]
E1["Raw document file\n(in browser memory)"]
E3["Lambda execution\n(stateless, destroyed)"]
E4["Document text\n(text layer or OCR, in-memory only)"]
E5["Model request context\n(not stored by WealthLens;\nvendor zero-retention terms)"]
end
subgraph PERSISTED["Persisted - Encrypted at Rest"]
E2["Uploaded file\n- S3 object in our AWS account\n- AES-256, BlockPublicAccess\n- not deleted by the import; stays\nuntil removed by us or a bucket\nretention setting"]
P1["AI audit log\n- Sanitized input\n- Output summary\n- Token usage"]
P2["Usage metrics\n- Per-function totals\n- Cost tracking"]
P3["Client file record\n- Extracted financial fields\n- Scenarios and settings"]
end
subgraph NEVER["Never Stored"]
N1["SSN / Tax ID"]
N2["Full account numbers"]
N3["Dates of birth"]
N4["Street addresses\n(in AI context)"]
N5["Email / Phone\n(in AI context)"]
end
E1 -->|"Signed URL PUT (300s)"| E2
E2 -->|"Edge reads text layer"| E4
E2 -->|"Lambda reads (images, and PDFs\nwith no text layer via pypdf;\nliabilities + statements)"| E3
E3 -->|"Textract OCR"| E4
E4 -->|"Redacted, then model extracts"| E5
E5 -->|"Sanitized logging"| P1
E5 -->|"Token tracking"| P2
E5 -->|"Extracted fields\napplied to UI"| P3
style EPHEMERAL fill:#1e293b,stroke:#ef4444,color:#e2e8f0
style PERSISTED fill:#0f172a,stroke:#22c55e,color:#e2e8f0
style NEVER fill:#44403c,stroke:#78716c,color:#a8a29e
Section 07
Security Stack
| Layer | Protection | Implementation |
|---|---|---|
| Upload | Pre-signed URL (300s TTL) | Time-limited signed PUT to one object key |
| Storage | AES-256, BlockPublicAccess | AWS S3 bucket in WealthLens's account; the import does not delete the file, it remains until removed by us or by a bucket retention setting |
| OCR | AWS Textract (image uploads) | Inside our AWS account, liabilities and statements only; the fee importer reads text-layer PDFs only |
| Processing | Stateless Lambda | Destroyed after execution |
| PII Redaction (conversational AI + audit log) | 6 regex patterns + key-based | Privacy Guardrail layer |
| PII Redaction (document imports) | Lambda regex + AWS Comprehend (when enabled) + edge regex | Inside the AWS boundary, before any model call |
| AI (Reasoning) | Zero-retention Claude Haiku 4.5 / Sonnet 5.5 | Anthropic API, no-training terms |
| AI (Document extraction) | Zero-retention Claude Haiku 4.5 primary, Gemini 3.5 Flash backup | Anthropic API and Google API, no-training terms |
| AI (Guideline Search) | Claude Sonnet 5.5 (Anthropic) | Web-search grounded, no-training terms |
| Audit | Double-sanitized immutable logs | Immutable audit log |
| Transit | TLS 1.3 | All Supabase + AWS API calls |
| At Rest | AES-256 | PostgreSQL (Supabase) + S3 |
| Access Control | RLS + JWT + auth checks | Row-level security on all tables |
| Secrets | Supabase Secrets | AWS keys and API keys, never in .env |
| Injection Defense | System prompt guardrail | Injection-defense directive |
| Infrastructure compliance | SOC 2 Type II (Supabase, AWS) | Provider attestations, not a WealthLens audit |
Section 08
Prompt Injection Defense
The conversational AI system prompts (AI Architect, Lens Guide, Client IQ) include a hardened injection-defense directive against attempts to extract system prompts or override AI behavior:
WealthLens is live.
Start now: $1 today, 30-day trial, then $149 a month until you cancel. Or book a free demo first.