Read-Only Architecture for AI-Powered Personal Finance Analysis

    This article describes an engineering approach to AI-assisted personal finance analysis built on read-only account access. It covers design principles, a layered architecture, transaction normalization, expense summarization and classification, anomaly detection, APR and interest estimation, report generation, reliability controls, security and compliance, and rollout recommendations. The focus is on trusted data sources, deterministic calculations, traceable outputs, and a clear separation between numerical computation and natural-language explanation.

    I. Background and Requirements

    Personal finance management has long depended on manual work. Users need to open multiple bank applications separately, check balances, transaction details, and billing dates one by one, and then manually consolidate everything into a spreadsheet. This process is time-consuming and prone to missing small charges, duplicate charges, and service fees that quietly increase year after year.

    As natural-language interaction capabilities mature, a new type of requirement has emerged: users want to ask questions in everyday language, such as “Where did my money go this month?” and have the system perform data aggregation, categorization, and explanation. From an engineering perspective, the core of this capability is not the conversational interface but three things: trusted data sources, accurate calculation logic, and verifiable output results.

    II. Design Principles

    1. Read-only first. The system only needs to read account balances and transaction records. It should not have write capabilities such as transfers, payments, or investment orders. The smaller the authorization scope, the smaller the impact of operational errors and data leaks.

    2. Separate computation from language. Amounts, ratios, summaries, and other numerical values should be produced by deterministic code. The language model is responsible only for understanding questions and organizing explanatory text, avoiding direct mental arithmetic by the model.

    3. Traceable results. Every statistical number should be traceable to specific original transaction details so that users can verify it transaction by transaction.

    4. Explanation before conclusion. When professional terms are involved, such as annual percentage rate, the system should first provide the definition and calculation method, then output the value.

    5. No investment advice. Analysis results should describe historical data only and should not constitute judgments about future asset allocation. When related questions arise, the system should return general information.

    III. Overall Architecture

    The system can be divided into four layers, each with a single responsibility, making independent testing and replacement easier:

    1. [User natural-language question]
    2. │
    3. ▼
    4. [Intent recognition layer] Determine question type: expense summary / anomaly detection / interest calculation / report generation
    5. │
    6. ▼
    7. [Analysis engine layer] Category statistics, rule detection, interest estimation, trend calculation
    8. │
    9. ▼
    10. [Data access layer] Read-only authorization, multi-account aggregation, transaction standardization
    11. │
    12. ▼
    13. [Security and audit layer] Credential encryption, access logs, data masking

    3.1 Data Access Layer

    The data access layer obtains read-only data through institution-provided open APIs or compliant aggregation services. The authorization flow should use a standard token mechanism, with tokens that have an expiration time and can be revoked by the user at any time.

    Transaction fields vary significantly across institutions, so they need to be unified into an internal model. The example below shows the standardized transaction structure. Amounts use a fixed-point decimal type instead of floating point to avoid cumulative errors.

    1. from dataclasses import dataclass
    2. from datetime import datetime
    3. from decimal import Decimal
    4. @dataclass
    5. class Transaction:
    6. account_id: str # Account identifier; only the last few characters are retained in logs
    7. occurred_at: datetime # Transaction occurrence time
    8. amount: Decimal # Expenses are negative; income is positive
    9. currency: str # Currency code
    10. merchant: str # Standardized merchant name
    11. raw_description: str # Original transaction description, used for traceability
    12. category: str | None = None # Classification result; empty when unclassified

    IV. Key Feature Implementation

    4.1 Expense Summarization and Classification

    The basic expense summarization flow is: filter transactions by calendar month, exclude income and internal transfers, and then accumulate by category. Classification can first be done with rules, such as mapping merchant keywords to predefined categories. Transactions that rules cannot cover can then be handled by a model or manual labeling as a fallback.

    In practice, three types of transactions need special handling:

    • Refunds: these should offset the original spending category rather than being counted as new income.
    • Internal transfers: for example, transfers between accounts under the same user should not be counted as expenses.
    • Credit card repayments: the repayment itself is not spending. The corresponding purchase details are already recorded separately, and counting the repayment again would inflate the total.
    1. from collections import defaultdict
    2. from decimal import Decimal
    3. def summarize_expenses(transactions, start, end):
    4. totals = defaultdict(Decimal)
    5. for tx in transactions:
    6. if not (start <= tx.occurred_at < end):
    7. continue
    8. if tx.amount >= 0 or tx.category == "internal_transfer":
    9. continue
    10. totals[tx.category or "Uncategorized"] += -tx.amount
    11. # Sort from highest to lowest amount for direct display of top expense categories
    12. return dict(sorted(totals.items(), key=lambda kv: kv[1], reverse=True))

    4.2 Anomaly Detection

    Anomaly detection should not be a black box that makes a final judgment as soon as a rule is hit. Instead, it should output candidate alerts for user confirmation. Common rules include the following three types.

    Duplicate charges. If the same merchant and the same amount appear multiple times within a short time window, list them as candidates. The window length should be configurable, and transactions already identified as recurring subscriptions should be excluded to reduce false positives.

    1. from datetime import timedelta
    2. def find_duplicate_charges(transactions, window=timedelta(days=3)):
    3. last_seen = {}
    4. candidates = []
    5. for tx in sorted(transactions, key=lambda t: t.occurred_at):
    6. key = (tx.merchant, tx.amount)
    7. prev = last_seen.get(key)
    8. if prev and tx.occurred_at - prev.occurred_at <= window:
    9. candidates.append((prev, tx))
    10. last_seen[key] = tx
    11. return candidates

    Unknown fees. Transactions whose descriptions contain fee-related terms and whose amounts have no clear relationship to business volume should be listed separately.

    Hidden price increases. For the same subscription merchant, compare adjacent billing amounts by cycle. If the increase exceeds a configured threshold, such as 5%, and occurs for two or more consecutive cycles, alert the user. The threshold is a policy parameter and should be adjustable for different scenarios.

    4.3 APR and Interest Estimation

    The annual percentage rate (APR) is a nominal annual rate and usually does not include compounding effects. To calculate interest for a given period, the average daily balance method can be used:

    1. Interest ≈ Average daily outstanding balance × APR ÷ 365 × Number of interest-bearing days

    For example, with an average daily outstanding balance of 10,000, an APR of 18%, and 30 interest-bearing days, the interest is approximately 10,000 × 0.18 ÷ 365 × 30 ≈ 147.95.

    Note that actual interest rules are subject to the terms disclosed by the institution. When outputting estimated results, the system should state the calculation assumptions and remind users to verify them against the values on their statements.

    4.4 Report and Dashboard Generation

    Weekly reports, bill payment calendars, and custom dashboards are essentially different queries over the same standardized data. Reports should be stored as editable query definitions rather than fixed images. This way, when users adjust filter conditions, the system only needs to re-execute the query without fetching the data again.

    V. Reliability Controls for Results

    Conclusions generated by language models can be wrong, so engineering constraints are needed.

    1. All numerical values are calculated by deterministic code. The model does not directly output amounts that have not been calculated.
    2. Each conclusion is accompanied by a list of source transactions, which users can expand and verify transaction by transaction.
    3. Assumptions behind calculations, such as interest-bearing days and classification rule versions, must be stated explicitly.
    4. For terms that cannot be reflected in the data, such as undisclosed fee rules, the system should state that it cannot determine the answer rather than guessing.
    5. For key amounts, users should be reminded to rely on the bank’s official statement.

    VI. Security and Compliance

    • Credential management: Authorization tokens should be stored encrypted, with keys managed by a dedicated key management service. Credentials must not be written into code or logs.
    • Log masking: Account numbers should retain only the last few characters. Amounts and merchant names should be masked in logs.
    • Minimized retention: Analysis caches should have an expiration time. After a user revokes authorization, related data should be deleted within an agreed period.
    • Access auditing: Record the requesting subject, time, and data scope of each data access for later traceability.

    VII. Rollout Recommendations

    1. Start with a small pilot. Select a single market and major account types first to validate data quality and the coverage of standardization rules.
    2. Build a regression test set. Use de-identified historical data to validate anomaly detection rules, measure false positive and false negative rates, and then adjust thresholds gradually.
    3. Maintain a terminology library independently. Manage definitions and calculation explanations of professional terms as a separate module to reduce user comprehension costs and facilitate compliance review.
    4. Define monitoring metrics. Focus on the discrepancy rate between summaries and bank reconciliation, the proportion of users who revoke authorization, and the proportion of anomaly alerts confirmed by users. These three metrics directly reflect the accuracy and trustworthiness of the system.