Building a Personal Finance Assistant with Read-Only Data Access: Design Practices

    This article walks through the engineering design of a personal finance assistant that combines read-only account data with natural language Q&A. It covers the four-layer architecture, permission minimization, query processing pipelines, anomaly detection rules, interest estimation, dashboard outputs, result validation, and compliance considerations—showing how to keep every number traceable while letting the language model handle only intent understanding and expression.

    1. Problem Background

    Managing personal finances usually means switching between multiple banking apps to check balances, statements, and charges one by one. Manual summarization is time-consuming and makes it easy to miss subtle issues such as duplicate charges or slow price creep on recurring subscriptions.

    Combining natural language Q&A with account data lets users get a summary from a single question. But this capability depends on three preconditions: the data source must be reliable, the calculation process must be traceable, and conclusions must never be presented as absolute truth.

    This article explains the key design points of such systems from an engineering perspective, including permission boundaries, query pipelines, anomaly detection rules, metric calculations, and result validation.

    2. Overall Architecture

    A typical system can be divided into four layers:

    1. Data ingestion layer: obtains balances and transaction records in a read-only manner through compliant open banking APIs or account aggregation services.
    2. Normalization layer: unifies currencies, date formats, merchant names, and transaction types, converting raw data into a consistent internal model.
    3. Analysis layer: performs deterministic calculations such as categorized aggregation, anomaly detection, and interest estimation.
    4. Interaction layer: understands user questions, invokes analysis-layer results, and generates textual explanations, charts, and dashboards.

    The core principle: all monetary calculations are done by deterministic code, while the language model is only responsible for understanding user intent and organizing the output. Models computing amounts directly in their heads are prone to errors, whereas code-based results are reproducible and testable.

    A normalized transaction record can be represented with the following structure. Amounts are stored as integers in the smallest currency unit to avoid floating-point rounding errors.

    1. struct Transaction {
    2. account_id: string // masked account identifier
    3. posted_on: date // posting date
    4. amount: integer // integer amount in cents
    5. currency: string // three-letter currency code
    6. merchant: string // normalized merchant name
    7. category: string // category, e.g., dining, transport, subscription
    8. tx_type: string // "debit" or "credit"
    9. }

    3. Data Ingestion and Permission Minimization

    Read-only design is the first security boundary of such systems. Ingestion should follow these practices:

    • Request only read permissions for balances and transaction records—never transfer, payment, or account modification permissions.
    • Mask account and card numbers before storing them; the UI shows only the last four digits.
    • Encrypt raw credentials at rest, with encryption keys managed by a dedicated key management service.
    • When a user revokes authorization, immediately stop pulling data and delete caches according to the established policy.
    • Never log detailed amounts or account identifiers in logs.

    The authorization scope can be enforced at the entry point:

    1. ALLOWED_SCOPES = {"accounts:read", "balances:read", "transactions:read"}
    2. function assert_read_only(granted_scopes):
    3. unexpected = granted_scopes minus ALLOWED_SCOPES
    4. if unexpected is not empty:
    5. raise PermissionError("Permissions beyond read-only scope detected: " + unexpected)

    If any write permission sneaks in, the service should refuse to start rather than merely log a warning.

    4. Natural Language Query Pipeline

    Take the question “Where did my money go this month?” as an example. The system needs to complete these steps:

    1. Intent recognition: classify the question as a spending summary.
    2. Parameter extraction: determine the time range (current calendar month), the account scope (all linked accounts), and unify currencies.
    3. Deterministic query: aggregate spending amounts by category.
    4. Result generation: rewrite the aggregated results in plain language while preserving the source of every number.

    The core logic for spending summaries looks like this:

    1. function summarize_spending(transactions, year, month):
    2. totals = empty map from category to integer
    3. for t in transactions:
    4. if t.tx_type == "debit" and t.posted_on.year == year and t.posted_on.month == month:
    5. totals[t.category] += t.amount
    6. return totals sorted by amount, descending

    Two details are easy to get wrong here. First, refunds and reversal transactions should offset the corresponding spending, not be counted as income. Second, transfers between accounts owned by the same user should be excluded from income/expense statistics; otherwise both income and expenses will be double-counted.

    When the month’s statement is not yet finalized, the system must also state the data cutoff time. Pending transactions may not have posted yet, so results will change over time—this caveat should be noted in the answer.

    5. Anomalous Charge Detection

    Anomaly detection aims to surface issues users tend to overlook. Common rules fall into three categories.

    1. Duplicate charges

    The same merchant and same amount appearing multiple times within a short time window may indicate duplicate submissions or accidentally duplicated subscriptions.

    1. function find_duplicate_charges(transactions, window_days):
    2. debits = transactions where tx_type == "debit"
    3. sort debits by (merchant, amount, posted_on)
    4. hits = empty list
    5. for each adjacent pair (prev, cur) in debits:
    6. if prev.merchant == cur.merchant
    7. and prev.amount == cur.amount
    8. and days_between(prev.posted_on, cur.posted_on) <= window_days:
    9. add (prev, cur) to hits
    10. return hits

    Legitimate repeat purchases will also trigger this rule—for example, buying two identical drinks on the same day. Therefore, output should be framed as “candidates to verify” rather than direct conclusions.

    2. Abnormal fees

    Fee-type transactions should be tracked separately and compared against the account’s historical norms. Amounts significantly above the historical average, or fee types never seen before, are worth flagging.

    3. Slow price creep

    If periodic charges from the same merchant rise consecutively, it may reflect a price adjustment or plan change.

    1. function detect_price_increase(monthly_amounts, min_steps):
    2. // monthly_amounts: charges from the same merchant, sorted by time
    3. increases = count of i where monthly_amounts[i+1] > monthly_amounts[i]
    4. return increases >= min_steps and last(monthly_amounts) > first(monthly_amounts)

    Usage-based services have amounts that naturally fluctuate, so false positive rates are high. Before enabling the rule, distinguish these cases using usage data, and allow users to mark certain merchants as “known and normal.”

    6. Interest Estimation and Income/Expense Metrics

    APR (Annual Percentage Rate) is the nominal annual rate, representing interest as a proportion of principal over one year. With daily interest accrual, the approximate formula for a single day’s interest is:

    Daily interest = daily accrual balance × APR ÷ 365

    The total annual interest is the sum of daily interest.

    1. function estimate_interest(daily_balances, apr):
    2. // daily_balances in cents, apr as a decimal, e.g., 0.18 means 18%
    3. daily_rate = apr / 365
    4. total = 0
    5. for b in daily_balances:
    6. total += b * daily_rate
    7. return round(total) // returns an integer amount in cents

    This formula is only an approximation. Actual accrual rules may differ in compounding, grace periods, tiered rates, and rounding methods. Output should therefore be labeled as an “estimate,” with a recommendation that users verify against their official statements.

    Income vs. expense comparison also requires care. Before subtracting total expenses from total income, exclude internal transfers, refunds, and investment redemptions—non-operational flows. Otherwise, the answer to “did spending exceed income” will be noticeably off.

    7. Reports and Dashboard Outputs

    Analysis results can be delivered as three common artifacts:

    • Weekly spending chart: aggregate spending by calendar week and output the data series for a bar chart.
    • Upcoming bill calendar: derive reminder dates from statement and due dates, sorted by date.
    • Custom dashboards: save user configurations as declarative structures, recalculated and rendered each time they are opened.

    Dashboard configurations should be decoupled from calculation logic. Configuration only describes “what to show, grouped by which dimension, over what time range,” while the actual data is supplied uniformly by the analysis layer. This way, users can modify configurations without re-ingesting data.

    1. {
    2. "widget": "weekly_spend_chart",
    3. "period": "last_8_weeks",
    4. "group_by": "category",
    5. "exclude": ["internal_transfer"]
    6. }

    8. Result Validation and Explainability

    Financial outputs carry a high cost of error, so the system should validate at multiple stages:

    • Traceability: every summarized number can be expanded down to the underlying transaction details.
    • Consistency checks: aggregated results must equal the sum of details. If they mismatch, refuse to output and log the error.
    • Reconciliation prompts: any amount-based conclusion should explicitly remind users to verify against their bank statements.
    • Uncertainty labeling: anomaly detection results should be marked as “pending confirmation,” including the triggered rule and its evidence. Never present inferences as definitive conclusions.

    Explainability is valuable not only for reducing misunderstanding but also for helping developers locate bugs. When a user reports an incorrect number, the team can investigate at three levels: transaction details, rule versions, and data snapshots.

    9. Security and Compliance Essentials

    • Define functional boundaries clearly: the system only presents information and performs analysis—it never initiates transactions or provides investment advice.
    • Data minimization: retain only fields required for analysis, with explicit retention periods.
    • Access auditing: log every data read, but store no sensitive values in audit logs.
    • Regional compliance: different jurisdictions have different requirements for collecting, storing, and transferring personal financial data across borders. Have legal and compliance teams review each item before launch.

    10. Implementation Recommendations

    1. Offline evaluation first: test anomaly rules against masked historical data, measure precision and false positive rates, then decide on thresholds.
    2. Full coverage of edge cases: unit tests for amount calculations should cover cross-month transactions, refunds, reversals, cross-currency conversion, internal transfers, and pending transactions.
    3. Gradual rollout: open the system to a small user group first, monitor error rates, user feedback, and data consistency metrics, then expand once stability is confirmed.
    4. Continuous calibration: regularly update rules based on false positives flagged by users, and keep versioned rule records for traceability.

    The hard part of personal finance analysis is not making answers sound fluent—it is ensuring every number has a source and every conclusion can be verified.