cd /news/artificial-intelligence/i-built-price-protection-that-pays-o… · home › topics › artificial-intelligence › article
[ARTICLE · art-177883] src=dev.to ↗ pub= topic=artificial-intelligence verified=true sentiment=↑ positive

I built price protection that pays out when AI validators agree on a web page

A developer built PriceGuard, a price-protection contract on GenLayer that uses LLM-backed validators to read product pages and agree on a purchase's current price to the cent, triggering automatic refunds from a funded pool without any claim filing. The contract runs a leader function that extracts the price and a validator function that independently re-reads the page, comparing a minimal record of status and price in cents with no tolerance band, and fails closed to no payout on UNAVAILABLE, AMBIGUOUS or UNREADABLE results. Deterministic canonicalization code requires the price to appear on the page with its currency symbol or code, so a model-invented number becomes AMBIGUOUS and pays nothing.

recommendation

Wrap LLM extraction in deterministic checks that confirm the value appears verbatim in the source and fail closed to no action when validators disagree on the exact figure.

more in playbook: Verifying model output
by read5 min views4 publishedNov 28, 2026

Credit cards used to give you money back when something you bought got cheaper a few weeks later. Most issuers quietly killed that perk. The reason wasn't fraud, it was cost: every claim needed a human to open a product page, find the right price, and compare it with a receipt.

That "look at a web page and decide" step is exactly what normal smart contracts can't do. So I built PriceGuard on GenLayer, where contracts are written in Python and can read the web and ask an LLM, with a set of validators who have to agree on the answer.

This post walks through how it works, the parts that were harder than I expected, and the code that keeps it honest.

An issuer (a card program, a fintech, a retailer) opens a plan and funds a pool. Purchases get registered: buyer, product page, item, variant, currency, price paid, date. During the protection window, anyone can call check on a purchase. Validators each read the product page, agree on today's price to the cent, and plain Python code refunds the drop from the pool. Nobody files a claim.

A product page is messy. The Raspberry Pi 4 page I tested on prints the 4 GB price next to the 8 GB price, plus eight add-on prices and a row of "featured products". My demo lamp page has a struck-through "Was $89.00", a member price, an instalment price and a different finish that costs more.

An oracle that scrapes "the first dollar amount" gets this wrong constantly. An LLM can tell which number is the current selling price of this exact variant. GenLayer lets me use that judgement inside the contract, and the validators check each other's work.

GenLayer's run_nondet_unsafe takes two functions. The leader does the non-deterministic work. Every validator runs its own copy and decides whether to accept the leader's answer.

def leader_fn() -> dict:
    rec, det = read_price(item, variant, cur, url, fence)
    return {"record": rec, "detail": det}

def validator_fn(leader_res) -> bool:
    if not isinstance(leader_res, gl.vm.Return):
        return False
    d = leader_res.calldata
    if not isinstance(d, dict) or not record_ok(d["record"]):
        return False
    mine, _det = read_price(item, variant, cur, url, fence)
    return mine == d["record"]   # EXACT: status and price in cents

res = gl.vm.run_nondet_unsafe(leader_fn, validator_fn)

The record they compare is tiny on purpose:

{"status": "PRICED | UNAVAILABLE | AMBIGUOUS | UNREADABLE", "price_cents": 12000}

No tolerance band. If validators don't land on the same status and the same cents, there's no payout. Out of stock, unclear and unreadable all pay nothing. It fails closed.

The model is good at picking the right price, but I don't let its answer through raw. Every validator reduces it with deterministic code against its own copy of the page:

def canonicalize(reply: dict, currency: str, text: str) -> dict:
    st = reply.get("status")
    if st == "UNREADABLE":
        return {"status": "UNREADABLE", "price_cents": 0}
    if st == "UNAVAILABLE":
        return {"status": "UNAVAILABLE", "price_cents": 0}
    if st != "PRICED":
        return {"status": "AMBIGUOUS", "price_cents": 0}
    cur = str(reply.get("currency", "")).strip().upper()
    cents = price_to_cents(reply.get("price"))
    if cur != currency or cents is None or cents <= 0:
        return {"status": "AMBIGUOUS", "price_cents": 0}
    if not price_on_page(cents, currency, text):
        return {"status": "AMBIGUOUS", "price_cents": 0}
    return {"status": "PRICED", "price_cents": cents}

price_on_page requires the price to be printed on the page with the currency sign or code right next to it. So $1120.00 can never certify 120.00, and a bare 120.00 points doesn't count. If the model invents a number, it becomes AMBIGUOUS and pays nothing.

A few more cheap guards before the model is even asked:

UNREADABLE. Consensus decides one fact: today's price. Everything else is boring code:

def refund_cents(paid, lowest, coverage_bp, min_drop, cap):
    drop = paid - lowest
    if drop <= 0 or drop < min_drop:
        return 0
    return min((drop * coverage_bp) // 10_000, cap)

The contract tracks the lowest price ever seen, so a deeper drop later pays only the extra difference, the same drop never pays twice, and a price that goes back up never claws anything back.

My first version tracked refunds in cents. A reviewer-style test exposed a bug: if the pool ran low and paid only part of a refund, a later top-up could pay out more than the purchase was entitled to.

The fix was to do the accounting in wei actually paid:

entitled_wei = cents_to_wei(due, int(p.wei_per_usd))
owed_wei = entitled_wei - int(c.credited_wei)
if owed_wei > 0:
    got = min(owed_wei, int(p.balance))

There's a regression test for it (TestPartialPoolRefill): a 2-cent drop is worth 20 wei; the pool pays 5, gets refilled, and the total stays at 20. If you build anything with partial payouts, test this case.

On GenLayer's studionet, against the real Adafruit Raspberry Pi 4 page and a clearly labelled demo store:

Purchase Validators read Refund
Pi 4, 4 GB, paid $135 PRICED $120.00 $15.00
Pi 4, 8 GB (same page), paid $199 PRICED $190.00, not the 4 GB price $9.00
Pi 4, 4 GB, paid $120 PRICED $120.00 $0, no drop
Demo lamp, paid $89 PRICED $69.00, ignoring the "was", member and instalment prices $20.00
Demo headphones, paid $149 UNAVAILABLE (sold out) $0

Every round reached consensus. The transaction hashes are in the repo's docs/LIVE_EVIDENCE.md.

You can run the whole flow in your browser in about a minute: open the live app, click Create / load test key (free faucet), register the demo lamp, click Check price, and withdraw your $20 test refund.

If this pattern clicks for you, the fastest way to start is GenLayer Studio (zero setup, runs in the browser). GenLayer also runs a builder program on its portal that tracks contributions such as deployed contracts, projects and tutorials. If you want to join, you can sign up through my link: https://portal.genlayer.foundation/?ref=JTR01FHP. Full disclosure: it's a referral link, so I get credit if you join and ship something. It costs you nothing, and I'm happy to answer questions in the comments.

What would you hand to a validator jury next?

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @genlayer 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/i-built-price-protec…] indexed:0 read:5min 2026-11-28 · —