DEV Community

AI Stack Lab
AI Stack Lab

Posted on

Auditing a pricing workbook without opening Excel: raw XML, Decimal, and a form that disagrees with the code

Originally published at aistacklab2026.blogspot.com — the full rebuild, with the paper-form comparison, lives there.

Disclosure up front: this is a kit our own shop sells for $1 on Gumroad. I am writing about the audit, not selling you the audit result. Every figure below came out of the shipped files, and the defects I found are the reason for the post.

The problem: a spreadsheet is a claim, not a proof

A pricing workbook is the easiest kind of software to lie about. It has formulas, so it looks computed. It has cached values, so it looks correct. And it ships with a page of prose explaining what it does, written by the same person who wrote the formulas, which means the prose and the code can disagree and nobody finds out.

So the honest way to review one is not to open it and squint. It is to throw away every number it printed, re-derive them from the constants, and diff.

I did that to a septic pumping business kit: twelve files, one XLSX, fourteen pricing constants, three worked examples. This post is about the two techniques that did the real work — raw-XML formula extraction, and rebuilding the engine in Decimal — plus the one defect those techniques exposed, which was not in the formulas at all.

Technique one: read the formulas, not the values

openpyxl is the reflex, and it is fine, but it needs installing and it re-implements the format. If all you want is the formula text and the cached value, the XLSX is a zip and the sheet is XML. Twenty lines of zipfile plus ElementTree gets you both, with no dependencies:

import zipfile
from xml.etree import ElementTree as ET

NS = '{http://schemas.openxmlformats.org/spreadsheetml/2006/main}'
z = zipfile.ZipFile(path)

# shared strings: cell type "s" stores an index, not text
sst = []
if 'xl/sharedStrings.xml' in z.namelist():
    for si in ET.fromstring(z.read('xl/sharedStrings.xml')).findall(NS + 'si'):
        sst.append(''.join(t.text or '' for t in si.iter(NS + 't')))

for row in ET.fromstring(z.read('xl/worksheets/sheet2.xml')).iter(NS + 'row'):
    for c in row.findall(NS + 'c'):
        v, f = c.find(NS + 'v'), c.find(NS + 'f')
        val = sst[int(v.text)] if c.get('t') == 's' and v is not None else (v.text if v is not None else None)
        print(c.get('r'), repr(val), '=' + f.text if f is not None else None)
Enter fullscreen mode Exit fullscreen mode

Two things this buys you that data_only=True does not:

It shows the cached value next to the formula. On the calculator sheet the total cell reads <f>ROUND(SUM(B13:B21),2)</f> with <v>508.75</v> beside it. That pairing is the whole audit in miniature: the formula says what should happen, the cache says what did happen when the author last saved. If you change an input and the cache is stale, you are looking at a value that no longer corresponds to anything.

It shows the data validation. The sales page said the nine inputs were validated. The <dataValidation> elements in the same XML confirm it, cell by cell — a "No,Yes" list on the four flag cells, type="whole" between 0 and 4 on the two count cells, operator="greaterThanOrEqual" on tank size and miles. Four rules, nine cells. That claim was true, and I could only say so because I read the XML instead of the marketing.

Technique two: rebuild the engine in Decimal, from the CSV

The kit also ships its rate card as a CSV — fourteen parameter rows. That is the better rebuild source than the spreadsheet, because a CSV cannot hide a formula and it is trivially machine-readable:

from decimal import Decimal as D, ROUND_HALF_UP

def q(x):
    return D(x).quantize(D('0.01'), rounding=ROUND_HALF_UP)

def line_items(tank, trav, disp, after, filt, risers, digs, locate, comm):
    base = K['b1'] if tank <= 1000 else (K['b2'] if tank <= 1500 else K['b3'])
    t = max(D(0), D(trav) - K['ftrav']) * K['tmil']
    d = K['drop'] + max(D(0), D(disp) - K['fdis']) * K['dmil']
    return [q(base), q(t), q(d),
            q(K['ah'] if after else 0), q(K['filt'] if filt else 0),
            q(D(risers) * K['riser']), q(D(digs) * K['dig']),
            q(K['loc'] if locate else 0), q(K['com'] if comm else 0)]
Enter fullscreen mode Exit fullscreen mode

Decimal, not float, for one reason: money. 0.1 + 0.2 in binary floating point is 0.30000000000000004, and a kit that rounds a total with ROUND_HALF_UP will disagree with a rebuild done in floats at exactly the half-cent boundaries you care about. If you re-audit someone else's money math in floats, you will eventually report a defect that is your own arithmetic.

max(D(0), ...) is the other half of it. Both mileage lines have a free allowance, so the correct form is miles beyond the allowance, floored at zero. Write it without the floor and inside the free band you get a negative charge — which is exactly the defect below.

Result: three of three worked cases matched to the cent (508.75 / 220.00 / 1,069.80), and so did a seventeen-row startup ladder with its 10 percent contingency and first-month cash need. The engine is internally consistent. That is a narrow claim and worth stating precisely: given these inputs and this rate card, a stranger reproduces every intermediate value. It does not prove the constants are right for anybody's county.

The defect the rebuild exposed was in the prose

The workbook offsets mileage with MAX(0, miles − free). The kit's paper quote form prints the formula as plain arithmetic:

Travel surcharge:   (______ one-way miles − 15 free) × $1.25
Disposal:  $45.00 + (______ one-way miles − 12 free) × $0.85
Enter fullscreen mode Exit fullscreen mode

No floor. Inside the free band that subtracts. A nine-mile disposal run gives 45 + (9 − 12) × 0.85 = 42.45 instead of 45.00, and eight travel miles gives a negative travel charge. The kit's own filled example gets 45.00 because a human wrote "inside the 12 free" beside it — the formula above it would not.

I priced five jobs both ways:

Job Spreadsheet Paper form Delta
1,250 gal · 18 mi · 9 mi 293.75 291.20 −0.9%
950 gal · 8 mi · 6 mi 220.00 206.15 −6.3%
1,250 gal · 10 mi · 8 mi 290.00 280.35 −3.3%
950 gal · 5 mi · 4 mi 220.00 200.70 −8.8%
2,200 gal · 30 mi · 25 mi 399.80 399.80 0.00%

The last row is the tell. The form is exact when both mileage figures are past their free allowances and short whenever either is inside. That is a missing zero floor, not bad arithmetic — and the error always runs in the customer's favour, which makes it a margin leak rather than a support ticket.

The fix is two MAX(0, …) guards, or one sentence on the form. I did not edit the product. Pricing and listings belong to whoever owns the listing, and a reviewer who quietly "fixes" the artifact they are reviewing has destroyed the evidence.

What I would keep from this

  • Audit money in Decimal, always. Floats will manufacture defects at exactly the boundaries a pricing engine cares about.
  • Diff the prose against the code. This defect was invisible in the workbook and invisible in the sales page. It only appeared when I filled in the printed form literally and compared totals.
  • Print the effective unit price. Base ÷ tank capacity at 1,000, 1,250 and 2,200 gallons is 0.175, 0.196 and 0.148 dollars per gallon — all below the 0.30-to-0.70 range the kit's own rate card cites for very large tanks. Both readings can be defended (base vs. total invoice), but the table is what makes you notice there is a reading to choose.
  • A self-check that only prints PASS is decoration. Add a deliberately broken copy to your test run.

Where it stops

The kit is documentation, not software: no app, no CRM connector, no map or API integration, no invoicing engine — twelve files you read and edit, two CSVs, one spreadsheet. It is US-shaped, and every figure and compliance item has to be replaced locally. Example figures are illustrative planning inputs, not market rates and not earnings, and nothing here is legal, tax, insurance, licensing, or financial advice. There are no ratings, reviews, testimonials or sales figures in this post because the product has no confirmed sale worth quoting. The full rebuild, including the startup-ladder and break-even arithmetic, is on the blog.

Top comments (0)