<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Taaha Rauf</title>
    <description>The latest articles on DEV Community by Taaha Rauf (@taaha161).</description>
    <link>https://dev.to/taaha161</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4259492%2F181ab007-dd5d-4094-9f74-c06fda18f74d.jpg</url>
      <title>DEV Community: Taaha Rauf</title>
      <link>https://dev.to/taaha161</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/taaha161"/>
    <language>en</language>
    <item>
      <title>LLMs misread bank statements. Here's how we catch it with arithmetic.</title>
      <dc:creator>Taaha Rauf</dc:creator>
      <pubDate>Mon, 23 Nov 2026 01:01:36 +0000</pubDate>
      <link>https://dev.to/taaha161/llms-misread-bank-statements-heres-how-we-catch-it-with-arithmetic-2o8i</link>
      <guid>https://dev.to/taaha161/llms-misread-bank-statements-heres-how-we-catch-it-with-arithmetic-2o8i</guid>
      <description>&lt;p&gt;Every PDF bank statement carries its own answer key. The running balance column, plus the summary box (opening balance, total in, total out, closing balance), let you check any extraction using arithmetic alone, with no second model and no human in the loop.&lt;/p&gt;

&lt;p&gt;I build Bank Statement Scanner (bankstatementscanner.com), which turns statement PDFs into Excel/CSV. Like most tools in this space we use an LLM for extraction. It's right most of the time, but "most of the time" isn't acceptable for financial data. These are the checks we run on every statement.&lt;/p&gt;

&lt;h2&gt;
  
  
  The balance chain
&lt;/h2&gt;

&lt;p&gt;Between any two printed balances, the rows in between must explain the step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;previous_balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;credits&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;debits&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;next_balance&lt;/span&gt;      &lt;span class="c1"&gt;# checking / savings&lt;/span&gt;
&lt;span class="n"&gt;previous_balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;credits&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;debits&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;next_balance&lt;/span&gt;      &lt;span class="c1"&gt;# credit cards (sign flips)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a step doesn't add up, the error is pinned to the rows between those two balances, rather than "somewhere in a 14-page statement".&lt;/p&gt;

&lt;h2&gt;
  
  
  The size of the gap tells you what went wrong
&lt;/h2&gt;

&lt;p&gt;Let &lt;code&gt;gap = printed_balance - expected_balance&lt;/code&gt;, and let &lt;code&gt;net&lt;/code&gt; be one row's signed effect. Then:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Gap&lt;/th&gt;
&lt;th&gt;Likely cause&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;gap == -2 * net&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;that row was read with the wrong direction (debit as credit)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;gap == -net&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;that row was read twice&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;anything else&lt;/td&gt;
&lt;td&gt;a row is missing, worth &lt;code&gt;abs(gap)&lt;/code&gt;, in direction &lt;code&gt;sign(gap)&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hint_for_break&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;brk&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;gap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;brk&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"gap"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;candidates&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;brk&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"rows"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;net&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signed_amount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;net&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;sign&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;candidates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"flipped_type"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sign&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;candidates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"duplicate_row"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;candidates&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;candidates&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;candidates&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;            &lt;span class="c1"&gt;# ambiguous: don't guess&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"missing_row"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;brk&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"from_row"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;brk&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"to_row"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details matter in practice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Return nothing when it's ambiguous.&lt;/strong&gt; If two rows could both explain the gap, a confident wrong hint is worse than no hint.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Identical duplicates are the exception.&lt;/strong&gt; If the candidates are the same date, description and amount, it doesn't matter which copy you flag. Point at the later one.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The summary box catches what the chain can't
&lt;/h2&gt;

&lt;p&gt;Some statements print no running balances. For those, compare the extracted totals against the summary box: the opening balance, total money in, total money out and closing balance all have to match. We also check that the summary box is consistent with itself, because OCR can misread the summary too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Say "can't check", never "passed"
&lt;/h2&gt;

&lt;p&gt;If a statement prints no balances and no summary, or covers several accounts on one PDF, we show &lt;strong&gt;"can't check"&lt;/strong&gt;. Reporting those as passed would be the easiest way to lose a bookkeeper's trust.&lt;/p&gt;

&lt;h2&gt;
  
  
  Across months
&lt;/h2&gt;

&lt;p&gt;The closing balance of March should equal the opening balance of April. Grouping saved statements by account (last four digits) and linking them month to month surfaces missing months and balances that don't carry over. That catches problems no single-statement check can.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this doesn't do
&lt;/h2&gt;

&lt;p&gt;None of this is book-to-bank reconciliation against your ledger. It answers a narrower question: did the rows we extracted add up to what the bank printed? It's cheap and deterministic, and it catches the failure modes LLM extraction actually has.&lt;/p&gt;

&lt;p&gt;If you're building something similar, steal the gap table. If you just have PDFs to convert, the first 10 pages are free with no account at &lt;a href="https://bankstatementscanner.com" rel="noopener noreferrer"&gt;bankstatementscanner.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>fintech</category>
      <category>llm</category>
    </item>
  </channel>
</rss>
