Draft a purchase approval memo and recheck the quote table
Draft a purchase approval memo from three quotes, take the table as CSV, and recompute net, VAT and total with a script that flags figures not in the quotes.
Three quotes and the one-line request "Compare the three quotes below and write a purchase approval memo", run three times. The totals were right every time. What was wrong was the numbers next to them: "Vendor C is $113.12 less than A and $61.42 less than B", "leaves $263.52 of the budget unused". None of those figures is on any quote. They are correct, but if the approver asks where $113.12 comes from, there is no quote to point at. So the check does two jobs: recompute the totals, and count figures that are not in the quotes.
[1] Save the request. It is an invented 12-monitor replacement. Vendor B's unit price includes VAT, and Vendor C gives 3% off for 10 or more units with free delivery if the discounted net is $2,000.00 or more. Keep the same numbers as quotes.en.csv (vendor, unit price, VAT included?, quantity, discount, delivery, free-delivery threshold); that file is the basis for the recomputation.
Subject: Replace 12 office monitorsCurrent situation: the 12 monitors in use are 7 years old, and 4 screen-flicker reports came in this yearApproved budget: $2,500.00 (VAT included)Three quotes:- Vendor A: $178.00 per monitor (VAT excluded), 12 units, no delivery charge, delivery within 5 business days of ordering, 3-year warranty- Vendor B: $189.20 per monitor (VAT included), 12 units, delivery charge $25.00 (VAT excluded), delivery within 3 business days, 2-year warranty- Vendor C: $169.00 per monitor (VAT excluded), 3% off the unit price for orders of 10 or more, 12 units, delivery charge $66.00 (VAT excluded; free if the net amount after the discount is $2,000.00 or more), delivery within 7 business days, 3-year warranty[2] Build the prompt. The calculation order is fixed as numbered steps, which Anthropic's be clear and direct guidance recommends when order matters.
<instructions>Write a purchase approval memo draft from the three quotes in <request>.Sections: Title / Subject / Background / Purchase details / Vendor comparison table / Recommendation / Expected benefits / Budget required Work out each vendor's amounts in this order.1. Decide the unit price. If a quantity discount applies, the unit price is the listed price minus that percentage.2. Unit price x quantity. If the unit price includes VAT, divide this by 1.1 to get the net amount; if it excludes VAT, this value is the net amount.3. Add the delivery charge (VAT excluded) to the net amount. If there is a free-delivery condition and it is met, do not add it.4. VAT is 10% of the step 3 value, rounded to the cent. Total = step 3 value + VAT. Rules:- Do not write any discount, fee or amount that is not in the quotes. Do not write new calculated values such as differences, percentages or savings either.- Do not invent numbers (%, hours, money) under Expected benefits. Use only facts from the request.- (cheapest-vendor amount must match the table; no approval date, author or approval line, since the request has none: two rules shortened)- After the memo, repeat the comparison table as CSV in a ```csv block. The header line must be exactly `vendor,unit_price,vat,qty,delivery,net,vat_amount,total`. unit_price is the figure on the quote as given, vat is included or excluded, amounts are plain numbers with two decimals and no commas or currency signs. net and total must reflect the discount and delivery.</instructions> <request>[3] Append the request and run it three times.
$ { cat head.en.txt request.en.txt; echo "</request>"; } > prompt.en.txt$ claude -p --model claude-sonnet-5-5 --max-turns 1 --tools "" --setting-sources "" --strict-mcp-config < prompt.en.txt > out.en.1.txtThe recommendation from the first result, then the CSV at its end:
## RecommendationVendor C is recommended. It has the lowest total at $2,236.48 (VAT included), which is within the approved budget of $2,500.00, and it offers a 3-year warranty. Its delivery time of within 7 business days is the longest of the three quotes. …vendor,unit_price,vat,qty,delivery,net,vat_amount,totalA,178.00,excluded,12,0.00,2136.00,213.60,2349.60B,189.20,included,12,25.00,2089.00,208.90,2297.90C,169.00,excluded,12,66.00,2033.16,203.32,2236.48[4] Write the checking script. It recomputes the totals from quotes.en.csv, compares them with the CSV cell by cell (VAT column included; two rows for one vendor fail), and checks that every number in the body is in the request or the recomputation, that each total in a body table sits under the right vendor, and that the amount in the "cheapest" sentence is the lowest total.
#!/usr/bin/env python3"""usage: check.py quotes.csv request.txt draft.txtRecomputes net / VAT / total per vendor from quotes.csv and compares them with the draft."""import csv, re, sysfrom decimal import Decimal as D, ROUND_HALF_UPquotes = list(csv.DictReader(open(sys.argv[1], encoding="utf-8")))req = open(sys.argv[2], encoding="utf-8").read()txt = open(sys.argv[3], encoding="utf-8").read()cent = lambda x: x.quantize(D("0.01"), ROUND_HALF_UP)def nrm(s): # "2,236.48" and "2236.480" -> "2236.48"; "178" and "178.00" -> "178" return format(D(s.replace(",", "")).normalize(), "f") exp, mid = {}, set() # 1. recomputefor q in quotes: qty = int(q["qty"]) unit = D(q["unit_price"]) * (1 - (D(q["discount_pct_10plus"]) / 100 if qty >= 10 else 0)) net = cent(unit * qty / D("1.1")) if q["price_includes_vat"] == "Y" else cent(unit * qty) mid.update({cent(unit), net, cent(unit * qty), cent(unit / D("1.1"))}) # intermediate values may be written ship = D(q["delivery_ex_vat"]) if q["free_delivery_if_net_at_least"] and net >= D(q["free_delivery_if_net_at_least"]): ship = D(0) net += ship vat = cent(net / 10) exp[q["vendor"].replace("Vendor ", "")] = {"unit_price": D(q["unit_price"]), "vat": "included" if q["price_includes_vat"] == "Y" else "excluded", "qty": qty, "delivery": D(q["delivery_ex_vat"]), "net": net, "vat_amount": vat, "total": net + vat}cheapest = min(exp, key=lambda k: exp[k]["total"])fails = [] m = re.search(r"```csv\n(.*?)```", txt, re.S) # 2. compare with the CSV at the end of the draftbody = txt.replace(m.group(0), "") if m else txtif not m: fails.append("no csv block")else: rows = list(csv.DictReader(m.group(1).strip().splitlines())) if len({r["vendor"].replace("Vendor ", "").strip() for r in rows}) < len(rows): fails.append("csv has more than one row for a vendor") got = {r["vendor"].replace("Vendor ", "").strip(): r for r in rows} for name, e in exp.items(): if name not in got: fails.append(f"vendor {name} missing in csv"); continue for k, v in e.items(): try: ok = (got[name][k].strip().lower() == v) if isinstance(v, str) else D(got[name][k]) == v except Exception: ok = False if not ok: fails.append(f"{name} {k}: csv {got[name].get(k)} / recomputed {v}") num = lambda s: re.findall(r"\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?", s) # 3. numbers in the body must be in the request or recomputedallowed = {nrm(n) for n in num(req)} | {nrm(str(v)) for e in exp.values() for v in e.values() if not isinstance(v, str)} | {nrm(str(v)) for v in mid} | {"1.1", "10"} # the 1.1 divisor and the 10% rate are in the instructionstext = "\n".join(l for l in body.splitlines() if not l.lstrip().startswith("#"))text = re.sub(r"(?m)^\s*\d+[.)]\s", "", text)new = sorted({nrm(n) for n in num(text)} - allowed, key=D)if new: fails.append(f"numbers in neither the request nor the recomputation: {new}") totals = {k: nrm(str(e["total"])) for k, e in exp.items()} # 4. totals present in the body; cheapest-vendor sentencebody_n = {nrm(n) for n in num(body)}missing = [k for k, v in totals.items() if v not in body_n]if missing: fails.append(f"vendors whose total is not in the body: {missing}")cols = {}for line in body.splitlines(): # body tables: vendor columns + a "Total incl." row, or one row per vendor if not line.lstrip().startswith("|"): cols = {}; continue c = [x.strip(" *") for x in line.strip().strip("|").split("|")] names = {i: x.replace("Vendor ", "") for i, x in enumerate(c) if x.replace("Vendor ", "") in exp} if len(names) > 1 and 0 not in names: cols = names; continue if cols and re.match(r"(?i)total(?!.*excl)", c[0]): for i, k in cols.items(): if i < len(c) and [nrm(x) for x in num(c[i])] != [totals[k]]: fails.append(f"table: vendor {k} total cell {c[i]} / recomputed {totals[k]}") elif 0 in names and len(names) == 1: k = names[0]; ns = {nrm(x) for cell in c[1:] for x in num(cell)} if totals[k] not in ns or ns & {v for j, v in totals.items() if j != k}: fails.append(f"table: row of vendor {k} mixes in another vendor's total")low = [l for l in body.splitlines() if re.search(r"cheapest|lowest|least expensive", l, re.I)]if not low: fails.append("no cheapest-vendor sentence")for l in low: wrong = [n for n in {nrm(x) for x in num(l)} if n in totals.values() and n != totals[cheapest]] if wrong: fails.append(f"cheapest sentence holds a total that is not the lowest {wrong}: {l.strip()[:50]}") print("recomputed totals:", {k: str(e["total"]) for k, e in exp.items()}, "· cheapest:", cheapest)print("\n".join("FAIL " + f for f in fails) or "OK")sys.exit(1 if fails else 0)[5] Run it. All three results of the prompt above printed OK. The one-sentence results have no CSV and carry new figures:
$ python -I -X utf8 check.en.py quotes.en.csv request.en.txt naive.en.out.1.txtrecomputed totals: {'A': '2349.60', 'B': '2297.90', 'C': '2236.48'} · cheapest: CFAIL no csv blockFAIL numbers in neither the request nor the recomputation: ['21', '61.42', '113.12', '150.4', '202.1', '263.52', '2026']| How it was asked | All three totals right | Figures not in the quotes (dates excluded) | Date line |
|---|---|---|---|
| One sentence | 3 of 3 | 5, 8, 8 | 3 of 3 (Date: 2026-10-21) |
| The prompt above | 3 of 3 | 0 | 0 |
[6] Test whether the script catches bad input. I changed out.en.1.txt by hand in eleven ways (swapped totals, VAT column, duplicate CSV row and so on); nine were caught. One example: the recommendation switched to Vendor B with B's total next to "lowest". This file is not model output.
$ python -I -X utf8 check.en.py quotes.en.csv request.en.txt bad/e3.txtFAIL cheapest sentence holds a total that is not the lowest ['2297.9']: Vendor B is recommended. It has the lowest total aThe two misses: An extra 5% discount may be negotiable (the request already has a 5 in "5 business days") and a sentence naming the wrong cheapest vendor without any amount.
[7] These quotes were not the first set. A first set without discount or free-delivery conditions (Korean, six runs) was computed correctly every time, so I added the conditions. With them, all twelve runs (six Korean, six English) still had correct totals, and none applied the free delivery wrongly. In this experiment the script caught no arithmetic slip, only figures and dates that were not in the quotes.
[8] The sentences are for a person. Lines like The screen-flicker problem ... is addressed by the new units or Addresses the 4 screen-flicker reports (three of three runs) only reuse numbers already in the request (the 4 reports), so they pass, but nothing in the request says the monitors cause the flicker.