DEV Community

Cover image for I Tested My SMS Parser Against 200 Real-World Edge Cases — Here's What I Found
DEVANSHU PATIL
DEVANSHU PATIL

Posted on

I Tested My SMS Parser Against 200 Real-World Edge Cases — Here's What I Found

I Tested My SMS Parser Against 200 Real-World Edge Cases — Here's What I Found

Writing a regular expression to parse a clean, standard banking SMS is easy.

Any junior developer can write a regex that matches:

"Debited Rs. 500.00 from A/C 1234 to CAFE"

The real engineering challenge begins when the telecom provider delivers the messy, ambiguous, adversarial alerts that real banks generate every single day:

  • The OTP Trap: "Your OTP is 4921 for transaction of Rs. 1,450.00 at AMAZON. Valid for 10 mins. Do not share with anyone."
  • The Failed Transaction Alert: "Transaction of Rs. 2,500.00 on Card ending 8012 at STARBUCKS was DECLINED due to insufficient balance."
  • The Bill Generation Alert: "Your monthly statement for Credit Card XX4321 is Rs. 38,450.00 due on 15-NOV-26. Min due Rs. 2,000.00."
  • The Ambiguous Reversal: "Refund of Rs. 499.00 credited to A/C **1092 for failed UPI order."

If your parsing engine fails to differentiate between an actual expense and an OTP alert, your ledger will record an expense before the user has even authorized the payment. If it fails on a declined alert, it logs an expense for money that never left the account!

Here is how FinLedger constructed an automated test harness (SMSParserEngineTest.kt, SMSParserFailureReproductionTest.kt) to guarantee safety across hundreds of banking edge cases.

The Taxonomy of SMS Parser Failure Modes

In financial software, there are two distinct categories of parser bugs:

flowchart TD
    subgraph FalseNegative["Type 1: False Negative (Inconvenient)"]
        SMS1["Valid Bank Alert"] --> Missed["Parser Fails to Recognize Format"]
        Missed --> UserEnters["User Manually Enters Transaction:
        Minor friction, zero ledger corruption."]
    end

    subgraph FalsePositive["Type 2: False Positive (CATASTROPHIC)"]
        SMS2["OTP / Declined Alert / Bill Notice"] --> BadParse["Parser Incorrectly Detects 'Expense'"]
        BadParse --> CorruptLedger["Phantom Expense Injected into Ledger:
        Balance is wrong, budgeting breaks, trust destroyed!"]
    end

A False Negative (failing to detect an unusual format) is a mild inconvenience; the user can manually enter the transaction or adjust their settings.

A False Positive (logging an OTP, declined charge, or statement balance as a live expense) is an accounting catastrophe. It silently corrupts balances and destroys user confidence.

Therefore, our automated test suites prioritize Negative Assertions above all else: proving that non-transactional messages are rejected 100% of the time.

The Automated Test Architecture

To safeguard the parsing pipeline against regressions, FinLedger maintains a comprehensive test suite in app/src/test/java/com/finance/app/data/sms/:

flowchart TD
    subgraph TestSuites["FinLedger Automated SMS Test Harness"]
        direction TB
        Suite1["SMSParserEngineTest:
        Parameterized matrix of 200+ real bank formats across 50+ institutions"]

        Suite2["SMSParserFailureReproductionTest:
        Dedicated regression tests for every user-reported parsing failure"]

        Suite3["SmsPipelineComprehensiveSafetyTest:
        Negative assertion harness for OTPs, balance queries, and declined alerts"]

        Suite4["ConsentFirstSmsAutomationTest:
        Verification that pipeline never executes without user permissions"]
    end

Let's examine the specific edge cases covered by this harness:

1. The OTP and Security Code Guard

Banking OTP messages frequently mention the transaction amount:

"Use 829104 as your secret OTP to authorize payment of Rs. 1,299.00 to FLIPKART."

In SmsPipelineComprehensiveSafetyTest.kt, the suite asserts that any message containing keywords like OTP, verification code, one time password, secret code, or valid for immediately returns null or TransactionValidationResult.Invalid.

The test verifies that this rejection occurs in less than 50 microseconds, preventing expensive regex evaluation on authentication codes.

2. Declined and Failed Transactions

When a card transaction fails at a POS machine due to a network glitch or insufficient funds, the issuing bank sends an alert:

"Your transaction of Rs. 500.00 on ICICI Bank Card 4921 has DECLINED. Reason: Exceeded daily limit."

If a parser merely searches for Rs. 500.00 and Card 4921, it records an expense.

Our test harness exercises a dedicated keyword blocklist: declined, failed, unsuccessful, cancelled, rejected, and insufficient funds. The test asserts that messages containing these failure markers are discarded without touching ledger balances.

3. Credit Card Statement Notifications

Once a month, credit card issuers send billing summaries:

"Statement for your HDFC Card ending 1042 generated. Total Amt Due: Rs 42,190.00. Min Amt Due: Rs 2,500.00. Due Date: 12-NOV-26."

This is not a new transaction; it is an aggregate bill for transactions that occurred over the preceding thirty days.

The test harness asserts that keywords like total amt due, min amt due, statement generated, and payment due date are recognized as billing statements, preventing the app from double-counting thirty days of spending in a single catastrophic Rs. 42,190 entry.

4. Non-Breaking Spaces and Unicode Currencies

Telecom gateways often transmit messages using non-standard character encodings:

  • Non-breaking spaces (\u00A0) instead of standard ASCII spaces (\u0020).
  • Mathematical bold unicode characters (₹ vs Rs vs INR).
  • Zero-width non-joiners inserted between letters.

In SMSParserFailureReproductionTest.kt, every string undergoes unicode normalization (Normalizer.Form.NFC) and whitespace sanitization before regex matching. The test suite verifies that messages with hidden control characters parse with identical precision to clean ASCII text.

Continuous Regression Prevention

Whenever an edge case is discovered in real-world testing:

  1. The raw, anonymized SMS text is added directly to SMSParserFailureReproductionTest.kt.
  2. A failing test case is committed to the repository, proving the reproduction.
  3. The deterministic extraction pipeline is adjusted until the test passes.
  4. The test remains in the suite permanently, ensuring that future performance optimizations or feature additions can never reintroduce the regression.

Key Takeaway

You cannot build a reliable financial parser by testing a handful of happy-path strings on your own phone.

Real-world banking alerts are filled with security codes, declined alerts, billing summaries, and malformed encodings. By constructing a rigorous, parameterized test harness with strict negative assertions, FinLedger guarantees that automated parsing makes life easier without ever compromising the mathematical integrity of your ledger.


FinLedger is a privacy-first, offline-first personal finance application for Android that models bank accounts, credit cards, and cash without double-counting.

Explore FinLedger on Google Play: https://play.google.com/store/apps/details?id=com.devanshufinance.app

Top comments (0)