{"slug": "i-built-price-protection-that-pays-out-when-ai-validators-agree-on-a-web-page", "title": "I built price protection that pays out when AI validators agree on a web page", "summary": "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.", "body_md": "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.\n\nThat \"look at a web page and decide\" step is exactly what normal smart contracts can't do. So I built **PriceGuard** on [GenLayer](https://www.genlayer.com), 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.\n\nThis post walks through how it works, the parts that were harder than I expected, and the code that keeps it honest.\n\nAn 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.\n\nA 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.\n\nAn 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.\n\nGenLayer'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.\n\n``` php\ndef leader_fn() -> dict:\n    rec, det = read_price(item, variant, cur, url, fence)\n    return {\"record\": rec, \"detail\": det}\n\ndef validator_fn(leader_res) -> bool:\n    if not isinstance(leader_res, gl.vm.Return):\n        return False\n    d = leader_res.calldata\n    if not isinstance(d, dict) or not record_ok(d[\"record\"]):\n        return False\n    mine, _det = read_price(item, variant, cur, url, fence)\n    return mine == d[\"record\"]   # EXACT: status and price in cents\n\nres = gl.vm.run_nondet_unsafe(leader_fn, validator_fn)\n```\n\nThe record they compare is tiny on purpose:\n\n```\n{\"status\": \"PRICED | UNAVAILABLE | AMBIGUOUS | UNREADABLE\", \"price_cents\": 12000}\n```\n\nNo 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.\n\nThe 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:\n\n``` php\ndef canonicalize(reply: dict, currency: str, text: str) -> dict:\n    st = reply.get(\"status\")\n    if st == \"UNREADABLE\":\n        return {\"status\": \"UNREADABLE\", \"price_cents\": 0}\n    if st == \"UNAVAILABLE\":\n        return {\"status\": \"UNAVAILABLE\", \"price_cents\": 0}\n    if st != \"PRICED\":\n        return {\"status\": \"AMBIGUOUS\", \"price_cents\": 0}\n    cur = str(reply.get(\"currency\", \"\")).strip().upper()\n    cents = price_to_cents(reply.get(\"price\"))\n    if cur != currency or cents is None or cents <= 0:\n        return {\"status\": \"AMBIGUOUS\", \"price_cents\": 0}\n    if not price_on_page(cents, currency, text):\n        return {\"status\": \"AMBIGUOUS\", \"price_cents\": 0}\n    return {\"status\": \"PRICED\", \"price_cents\": cents}\n```\n\n`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.\n\nA few more cheap guards before the model is even asked:\n\n`UNREADABLE`.\nConsensus decides **one fact**: today's price. Everything else is boring code:\n\n``` python\ndef refund_cents(paid, lowest, coverage_bp, min_drop, cap):\n    drop = paid - lowest\n    if drop <= 0 or drop < min_drop:\n        return 0\n    return min((drop * coverage_bp) // 10_000, cap)\n```\n\nThe 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.\n\nMy 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.\n\nThe fix was to do the accounting in **wei actually paid**:\n\n```\nentitled_wei = cents_to_wei(due, int(p.wei_per_usd))\nowed_wei = entitled_wei - int(c.credited_wei)\nif owed_wei > 0:\n    got = min(owed_wei, int(p.balance))\n    # ... pay `got`, add it to c.credited_wei\n```\n\nThere'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.\n\nOn GenLayer's studionet, against the real Adafruit Raspberry Pi 4 page and a clearly labelled demo store:\n\n| Purchase | Validators read | Refund | \n|---|---|---|\n| Pi 4, 4 GB, paid $135 | PRICED $120.00 | $15.00 | \n| Pi 4, 8 GB (same page), paid $199 | PRICED $190.00, not the 4 GB price | $9.00 | \n| Pi 4, 4 GB, paid $120 | PRICED $120.00 | $0, no drop | \n| Demo lamp, paid $89 | PRICED $69.00, ignoring the \"was\", member and instalment prices | $20.00 | \n| Demo headphones, paid $149 | UNAVAILABLE (sold out) | $0 | \n\nEvery round reached consensus. The transaction hashes are in the repo's `docs/LIVE_EVIDENCE.md`.\n\nYou can run the whole flow in your browser in about a minute: open the [live app](https://yoyoblair333-wq.github.io/priceguard/), click **Create / load test key** (free faucet), register the demo lamp, click **Check price**, and withdraw your $20 test refund.\n\nIf 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](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.\n\nWhat would you hand to a validator jury next?", "url": "https://wpnews.pro/news/i-built-price-protection-that-pays-out-when-ai-validators-agree-on-a-web-page", "canonical_source": "https://dev.to/yoyoblair333wq/i-built-price-protection-that-pays-out-when-ai-validators-agree-on-a-web-page-22h0", "published_at": "2026-11-28 21:08:22+00:00", "updated_at": "2026-11-28 21:15:08.776134+00:00", "lang": "en", "topics": ["artificial-intelligence", "large-language-models", "ai-agents", "ai-tools"], "entities": ["GenLayer", "PriceGuard", "Raspberry Pi 4"], "also_reported_by": [], "takeaway": "Requiring every validator to independently re-read the page and canonicalize the LLM's answer against its own copy—rejecting any price not printed with its currency symbol—turns model hallucination into an AMBIGUOUS no-payout instead of a bad refund.", "recommendation": {"advice": "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.", "playbook": "output-verification", "playbook_url": "https://wpnews.pro/playbooks/output-verification"}, "alternates": {"html": "https://wpnews.pro/news/i-built-price-protection-that-pays-out-when-ai-validators-agree-on-a-web-page", "markdown": "https://wpnews.pro/news/i-built-price-protection-that-pays-out-when-ai-validators-agree-on-a-web-page.md", "text": "https://wpnews.pro/news/i-built-price-protection-that-pays-out-when-ai-validators-agree-on-a-web-page.txt", "jsonld": "https://wpnews.pro/news/i-built-price-protection-that-pays-out-when-ai-validators-agree-on-a-web-page.jsonld"}}