AI Assistant Bank Account Spending Analysis: A Technical Practice

    This article describes how to build an AI assistant that analyzes personal spending from bank account transactions that users have explicitly authorized. It covers a layered architecture with read-only access, data normalization, transaction classification, LLM-based insight generation constrained by aggregated facts, anomaly alerts, and privacy and compliance engineering.

    1. Background and Problem Definition

    Some AI assistant products have recently begun gradual rollout testing of a capability that connects to a user’s bank accounts and analyzes their personal spending. Setting aside specific product designs, the core of this scenario is as follows. With the user’s explicit authorization, transaction data from scattered accounts is connected to an AI assistant. After cleaning, modeling, classification, and aggregation, a large language model (LLM) or a rule engine generates readable spending insights. The system also alerts users to abnormal transactions, budget deviations, and similar situations.

    For developers, the difficulty is not simply calling a model to generate a paragraph of analysis. The real challenge is balancing privacy, security, compliance, and accuracy. Personal financial data is highly sensitive. Any design flaw can lead to data leaks, misjudgments, or loss of user trust. A workable solution should therefore have these characteristics: minimum-privilege access, end-to-end auditability, explainable classification results, bounded insight generation, and fallback paths for anomaly detection.

    2. Overall Architecture

    We recommend a layered architecture that separates data access from intelligent analysis. This keeps the model away from raw sensitive data.

    1. Authorization and access layer: Manages user authorization, token management, account binding, and revocation. It requests read-only permissions only. Tokens are short-lived and support rotation.
    2. Data normalization layer: Converts transaction records from different sources into a unified internal transaction model. It standardizes time zones, currencies, amount signs, and refund linking.
    3. Feature and classification layer: Uses rules, statistical features, and small models to normalize merchants, classify transactions, identify subscriptions, and detect recurring payments.
    4. Insight generation layer: Receives only masked, aggregated metrics and classification results. An LLM then generates natural language explanations. The model never accesses full account numbers, names, or other direct identifiers.
    5. Security and governance layer: Covers encryption, masking, access control, audit logs, and data retention and deletion policies.
    6. Observability and gradual rollout layer: Uses feature flags, sample evaluation, and metric monitoring to control release scope and support fast rollback.

    The core principle of this architecture is that raw data stays inside the secure domain, and the model only consumes the minimum necessary information. The AI assistant is responsible for explanation and interaction. It does not store raw data.

    3. Authorization Flow and Data Minimization

    Bank account access must be based on the user’s informed consent. From an engineering perspective, the authorization process can be designed as a state machine with five states: unbound, authorizing, authorized, expired, and revoked. Every state change is written to an audit log that records the time, operation type, and result, but never plaintext sensitive data.

    1. State machine diagram:
    2. UNBOUND -> AUTHORIZING -> AUTHORIZED -> EXPIRED
    3. \-> FAILED
    4. AUTHORIZED -> REVOKED

    Data access should follow the principle of minimization. By default, the system only retrieves necessary fields: transaction time, amount, currency, merchant description, and transaction direction. Account numbers, national ID numbers, and similar fields should be truncated or hashed. Personal notes in merchant descriptions should be filtered out. Synchronization can be event-driven or based on scheduled pulls, but it must be idempotent to prevent duplicate transactions from distorting statistics.

    4. Transaction Data Modeling and Cleaning

    A unified data model is the foundation for later analysis. We recommend defining tables for transactions, accounts, merchant normalization, and classification results. Each transaction record should keep a masked version of the original description, a normalized merchant name, the amount direction, the category label, a confidence score, and the data version.

    1. {
    2. "transaction_id": "hash_id",
    3. "account_ref": "masked_ref",
    4. "occurred_at": "2025-01-01T12:00:00Z",
    5. "amount": -42.50,
    6. "currency": "CNY",
    7. "direction": "debit",
    8. "merchant_raw": "masked merchant description",
    9. "merchant_norm": "normalized merchant name",
    10. "category": "Dining",
    11. "confidence": 0.91,
    12. "schema_version": "v1"
    13. }

    The cleaning process focuses on four types of issues: duplicate transactions, refunds and reversals, time zones and currencies, and noise in merchant descriptions. Refunds should be offset against their original transactions, not simply counted as income. For cross-currency transactions, the system should record the original currency and the conversion rule. Transaction numbers and store IDs in merchant descriptions should be removed so they do not interfere with classification models.

    5. Transaction Classification and Merchant Normalization

    We recommend a hybrid strategy for transaction classification: rules first, models as a supplement, and a feedback loop. The rule layer handles high-confidence cases, such as fixed keywords and fixed-amount recurring payments. The model layer handles long-tail merchants. User feedback corrects classifications and builds labeled data over time.

    1. function classify(tx):
    2. rule_result = apply_rules(tx.merchant_norm, tx.amount, tx.occurred_at)
    3. if rule_result.confidence >= 0.95:
    4. return rule_result
    5. model_result = small_classifier(tx.features)
    6. if model_result.confidence < 0.6:
    7. return {category: "Other", need_review: true}
    8. return merge(rule_result, model_result)

    Every classification result must include a confidence score. Low-confidence samples should go to manual review or a user confirmation flow. Subscription detection can rely on periodicity and amount stability. However, the system should avoid mistaking one-time purchases for subscriptions. All category labels should be versioned so that results can be traced and evaluated.

    6. Insight Generation and Boundary Control

    The insight generation layer should not read raw transaction details directly. Instead, it should consume aggregated results, such as monthly category shares, month-over-month changes, budget deviations, frequent merchants, and anomaly lists. Prompts or templates should explicitly constrain the model. It may explain only the metrics it receives. It must not infer the user’s identity, invent transactions that were not provided, or give investment or credit advice.

    1. Input: {period, category_summary, budget_delta, anomaly_list}
    2. Constraints: explain only the provided data; keep amounts to two decimal places;
    3. explain the trigger reason for each anomaly item;
    4. do not provide investment advice;
    5. do not output full account numbers or sensitive merchant notes.
    6. Output: structured insights + natural language summary

    To prevent plausible-sounding but unsupported output, the system can use a structured intermediate representation. A rule engine first produces a set of facts, and then the model organizes them into language. If the model output conflicts with the fact set, the system should flag a validation failure and fall back to a template-based summary.

    7. Anomaly Detection and Alert Strategy

    Anomaly detection can combine statistical baselines with rule-based safeguards. During cold start, the system uses global distributions and user confirmation. Once enough data accumulates, it switches to the user’s own historical baseline and accounts for seasonality. Alert frequency should be limited so that false positives do not lead users to turn off notifications. Each anomaly alert should include the trigger reason, the amount involved, the time range, and an actionable entry point.

    Evaluation metrics should include classification accuracy, insight adoption rate, anomaly false positive rate, authorization success rate, end-to-end latency, complaint rate, and the completion rate of deletion requests. Gradual rollout can expand by region, subscription tier, and user sample. A one-click kill switch should remain available throughout.

    8. Privacy, Security, and Compliance Engineering

    Security design should cover encryption in transit and at rest, field-level masking, access control, and audit logging. Raw transaction data and model services should be deployed in isolation. The model side should only receive aggregated and masked results. Data retention policies must define a minimum retention period. The system must support deletion of data and derived artifacts after a user revokes authorization. Audit logs should record who accessed which type of data and when, without storing plaintext sensitive information.

    9. Summary

    For an AI assistant that analyzes spending from bank accounts, the core of the technology is not a single model capability. It is an engineering system built around authorization, minimization, normalization, explainability, and rollback. Developers should place generative capabilities behind the security boundary, use structured facts to constrain model output, and use gradual rollout and metrics to control risk. Personal finance analysis can remain useful over the long term only when privacy compliance and accuracy are both under control.