Connecting LLMs to Personal Financial Data: Read-Only Architecture and Privacy Practices
How to safely connect large language models to personal financial data. This article covers a read-only authorization model, data minimization, layered architecture, transaction categorization and anomaly detection, boundaries for natural language queries, and privacy practices including encryption, data retention, and prompt injection defenses.
Why Personal Finance Needs a Dedicated Design
Personal financial data combines transaction details, account balances, spending habits, and residence information. A leak has far more severe consequences than a typical business data breach. Before connecting an LLM to this kind of data, designers need to answer three questions: What can the model see? What operations can it perform? How long is the data retained in the system?
These questions map to three boundaries: data visibility, operational capability, and data lifecycle. The rest of this article is organized around them.
Core Principles: Read-Only, Minimal, Revocable
Read-only authorization. The application should only request query-level permissions—never transfer, account modification, or payment initiation. When no write permissions exist at the authorization layer, even an incorrect model output cannot directly change the state of funds.
Data minimization. Fetch only the fields required for the task. For example, expense categorization needs amount, date, merchant description, and category—not full account numbers, ID numbers, or login credentials.
Revocability. Users should be able to disconnect authorization at any time. After disconnection, the application must stop calling account data APIs and delete cached derived data as agreed.
Reference Architecture
The diagram below shows a common layered structure. Account data is transformed by a processing layer, and the model only receives aggregated results—never raw transaction records.
Client│Application service ──> Authorization gateway ──> Account data API (read-only)│├──> Data processing layer (masking, categorization, aggregation, anomaly rules)├──> Language model (receives structured summaries only)└──> Encrypted storage and audit logs
The core value of this layering is that monetary calculations and anomaly checks are handled by deterministic code, while the model focuses on understanding questions and composing responses. Computed results can be verified, and errors in model output are easier to trace.
Authorization and Data Access
The authorization flow should use token-based delegated authorization. The user completes login and consent on a page provided by the bank; the application receives only an access token, never the user’s banking password. Tokens mustrod should have an expiration and support refresh and revocation.
Recommended practices for data scope:
- Authorize at the account level, letting.activation level, letting users select which accounts to include.
- Set a time window实际 set an upper limit on the transaction history window, for example the last twelve months by default. Older data requires separate user consent.
- Fetch fields such as balance, account type, and the last four digits of the account number on demand—avoid full data pulls.
Data Aggregation and Categorization
Categorization rules should be transparent and explainable. The following sample code assigns expenses to a few categories by keyword and accumulates amounts using high-precision decimal types to avoid floating-point errors.
from collections import defaultdictfrom decimal import DecimalCATEGORY_RULES = {"housing": ["rent", "property management"],"utilities": ["water", "electricity", "gas"],"dining": ["restaurant", "food delivery", "coffee"],}def classify(description: str) -> str:for category, keywords in CATEGORY_RULES.items():if any(k in description for k in keywords):return categoryreturn "other"def summarize(transactions):totals = defaultdict(Decimal)for tx in transactions:if tx["amount"] < 0: # Convention: expenses are negative amountstotals[classify(tx["description"])] += -tx["amount"]return dict(totals)
Keyword rules miss cases easily; production systems typically combine merchant codes and past categorization records. There should also be a manual correction entry point—once a user changes a category, the system should treat the corrected value as authoritative.
Anomaly and Duplicate Charge Detection
Common anomalies include duplicate charges, unexpected fees, and steadily rising recurring bills.
Duplicate charges can be detected by combining a time window with merchant and amount matching. Sample code:
from datetime import timedeltadef find_duplicates(transactions, window=timedelta(hours=24)):txs = sorted(transactions, key=lambda t: t["time"])flagged = []for i, a in enumerate(txs):for b in txs[i + 1:]:if b["time"] - a["time"] > window:breakif a["merchant"] == b["merchant"] and a["amount"] == b["amount"]:flagged.append((a["id"], b["id"]))return flagged
For recurring bills, compare the most recent amount against the average of previous periods and alert when it exceeds a threshold.
Rule results should be flagged as “pending verification” rather than presented as conclusions. Two identical charges from the same merchant may be legitimate, such as installments. The trade-off between false positives (annoying the user) and false negatives (losing money) must be weighed explicitly when setting thresholds.
Boundaries of Natural Language Queries
When a user asks a question, the system first identifies intent, then calls fixed query functions. The model should not construct query statements directly, nor perform amount calculations itself. This prevents injection attacks and keeps results traceable.
Answers should include:
- Data scope: which accounts and what time period are covered.
- Calculation methodology: categorization rules and aggregation approach.
- Term definitions: when a technical concept appears, define it first, then explain how it is calculated.
For example, annual interest rate questions can be explained with a simplified formula: interest ≈ principal × annual rate × days / 365. The formula is for illustration only; actual interest is subject to the bank’s statement.
When data is incomplete or rules cannot decide, the answer should state the uncertainty plainly rather than offering a confident-sounding guess.
Privacy and Security Design
Encryption. Data in transit should下载 encrypted channels in transit, encrypted storage at rest, and keys managed separately from data.
Masking. Keep only the last four digits of account numbers. Logs should not record raw transaction descriptions or amount details—only event types and latency.
Session isolation. Store and retrieve financial data query contexts separately from general conversation to prevent cross-session leakage.
Training data policy. By default, user financial data is not used for model.PostMapping used for model training, and this should be stated in the privacy policy. Any exceptions require separate, explicit consent.
Retention and deletion. Set retention periods for derived data. When a user unlinks an account, delete caches, indexes, and intermediate results in sync. Even retained audit records must be masked.
Audit. Record who accessed which type of data, when, and triggered by which feature, to support later traceability and compliance checks.
Key Risks and Mitigations
- Numeric errors: Link key figures back to original transactions and provide a verification entry point.
- False anomaly judgments: Flag rule results as pending verification; treat them as conclusions only after user confirmation.
- Unauthorized access: Validate token scopes on the server side, never rely on frontend controls.
- Prompt injection: Transaction descriptions come from external sources and are untrusted text. The system must treat them as data, not instructions.
- Context leakage: Financial data must never enter long-term memory shared with general conversations.
Pre-Launch Checklist
- Does the authorization scope include query permissions only?
- Is raw data masked and aggregated before entering the model?
- Do categorization rules and anomaly thresholds have test coverage?
- Can the unlink flow delete all derived data?
- Do logs contain no sensitive details?
- Do answers include data scope, calculation methodology, and disclaimer notices?
- Have dedicated tests been run for prompt injection and unauthorized access?
After confirming each item, proceed to a gradual rollout, and continuously monitor the false positive rate, user correction rate, and security incidents.
