Skip to content

Repository files navigation

Unwafffle

Unwafffle is a small set of tools for understanding documents. It started as a weekend project called Contract Explainer, which I built to learn how to build products on top of language models, and it is now growing into a toolbox. The repo and package still use the old name for now. The tools today:

  • Explain a contract (/tools/explain-contract): the original tool, described below.
  • Redact personal details (/tools/redact): read a PDF on your device, choose what to replace, and copy or download the redacted text. Nothing is sent anywhere. It gives you plain text, not a PDF, on purpose: drawing a box over text leaves the text underneath, so it is not real redaction.

The home page also has a short explanation of how documents are handled, and /privacy-and-trust says it in full.

More tools are listed as "coming soon" on the home page. They live in one list, src/lib/tools/registry.ts, which the home page, the menu and the footer all read.

The rest of this README is about the contract tool. You give it a contract (a lease, a freelance agreement, a software licence) and it tells you, in plain language, what the key terms are and which clauses could work against you.

The rule I cared about most: every point has to quote the exact words from the contract and show the page they came from. If the model says something and I cannot find its quote in the document, the app throws that point away instead of showing it to you.

It explains and flags. It is not legal advice. Please do not sign or refuse to sign anything because of what a tool like this says.

Live demo

https://unwafffle.com

The live site analyses documents you upload, and also has the sample contract from a saved result. You can also try the redaction tool on the live site, which sends nothing anywhere: choose "Try the redaction tool on an example", or pick a PDF of your own. It is read on your device and nothing is uploaded. To try the full analysis on your own made-up contract, run it yourself (see below).

The hosted site is for the sample contract and other made-up contracts only. When live analysis is on, redacted text is sent to an AI service, and this tool cannot find every name or address, so please do not use a real contract or anything with personal details.

What you get

  • A short summary of what the agreement is and who is involved.
  • Risks: clauses that look one-sided or unusual (automatic renewal, ending the deal at 24 hours notice, uncapped liability, giving away all your work, and so on), worst first.
  • Key terms: dates, amounts, notice periods, renewal and penalties.
  • Ask a question: answers that come only from the document, with the quote they rely on. Ask what it says ("Is there a late fee?") and you get a direct answer, starting with Yes or No where that fits. Ask whether it is safe to sign, or whether you should sign, and it will not answer: it does not give legal advice, so it points you to the Risks tab instead.
  • Click any "Clause 7, page 2" link and the exact words are highlighted in the contract.
  • A redaction step before anything is sent. Your PDF is read on your device. The tool finds what looks personal, you review it, add anything it missed, and only the redacted text is sent for analysis (more below).

How it works

  1. Read the PDF in your browser, page by page (unpdf). The file never leaves your device at this step. Scanned PDFs are turned away with a clear message, because I cannot trust text that came from guessing at pixels.
  2. Redact, with you in charge. The tool finds what looks personal and shows it to you (see "Redaction" below). You untick false matches and add anything it missed, and only the redacted text goes to the server.
  3. Split it into clauses. I look for numbered headings first and fall back to chunks of text when there are none. Every clause keeps its page and its exact position.
  4. Ask the model twice: once for key terms, once for risks. It has to answer in a strict JSON shape and cite a clause and a quote for everything.
  5. Check every quote. A quote must appear word for word in the clause it cites, after ignoring only layout differences (line breaks, curly quotes, a word split with a hyphen at the end of a line). Capital letters, numbers and words must match exactly, so "30 days" can never pass as "60 days". Page numbers and highlight positions come from my own data, never from the model.
  6. Answer questions the same way. If none of an answer's quotes check out, the answer is not shown and you are told the document does not say.

Redaction

The redaction runs in your browser, so the original PDF and its text never reach my server. It is a review step, not a button that promises to make a document safe.

  • What it finds on its own: emails, phone numbers, web addresses, bank account numbers (IBANs are checked with their checksum), payment card numbers (checked with the Luhn formula), US and UK ID numbers, account and sort codes, dates of birth, postcodes, street addresses, titled names such as "Mr Smith", company names ending in Ltd or Inc, and the people and companies the contract names for itself, for example Northwind Digital Ltd (the "Client"). It will not mistake money, dates or durations for any of these.
  • What it cannot do: know other names or addresses. If a name is not defined in the contract and does not follow a title or a label, you have to type it in. The screen says so.
  • You decide. Everything found starts ticked. You can untick a false match, add your own text (every place it occurs is replaced, even across line breaks), and switch between a preview of what will be sent and what was found.
  • Labels, not blanks. A detail becomes [PERSON_1], [COMPANY_1] and so on, and the same detail always gets the same label, so the contract still reads sensibly and the AI can still tell who owes what.
  • Your questions are redacted too. If you ask "Can Jordan Example end this early?", the name is replaced before the question is sent, and the screen shows what was actually sent.
  • Original details stay on your device. After analysis you can switch them back on for your own reading. That mapping lives only in the browser tab.
  • Download. You can download the redacted text as a plain file to use anywhere.

In a real browser test the request that carries the text for analysis was checked against every personal detail in the example, and none was in it.

Prompt injection

The contract text is treated as untrusted. It could say "ignore your instructions", so it only ever goes in a fenced block with a random label that the contract cannot guess, the model has no tools, and the app shows everything as plain text.

That is not enough on its own. My checker proves a quote is really in the document, but a planted sentence is in the document too, so it passes. So the app also looks for sentences aimed at AI readers ("ignore all previous instructions", "state that this contract is safe"). When it finds one, it warns you with the exact quote and page, and it hides that sentence from the model, so the model can neither obey it nor cite it. This uses fixed patterns, which catch the standard copy-paste wording but not creative rewordings (more on that below). I treat it as one layer of defence, not a guarantee.

The full list of choices, with the options I weighed and why I picked each, is in DECISIONS.md.

How well does it work?

I wrote 10 invented contracts with 38 planted risks (including two clean ones, a contract that tries to hijack the model, and one with messy line breaks) and ran three free models over them. Method and caveats are in evals/README.md.

One run per model on each of the 10 contracts, 38 planted risks in total.

gpt-oss-120b gpt-oss-20b qwen3.8-27b
Planted risks found 37 of 38 35 of 38 36 of 38
False alarms 2 4 2
Right category, among the risks found 35 of 37 28 of 35 19 of 36
Quotes that checked out 128 of 131 150 of 150 152 of 152
Questions the contract answers, answered correctly 10 of 10 10 of 10 10 of 10
Questions it does not answer, correctly "not found" 10 of 10 10 of 10 10 of 10
Seconds per contract (the two analysis calls) 5.2 2.3 7.9
Tokens per contract (analysis plus questions) 6,809 6,034 5,405
What those tokens would cost at list price $0.0019 $0.0007 $0.0092

They are free on the free tier, so the last row is only for comparison. The full tables, including every contract, are in evals/results/RESULTS.md.

What I learned from it:

  • They all find most of the planted risks, and the gaps are small. Differences of one or two out of 38 are noise from a single run, so please do not read this as a ranking.
  • The checker earned its keep once. gpt-oss-120b gave 3 quotes that were not in the document, and they were dropped before anyone saw them. The other two never did in this run.
  • The commonest false alarm is a fair, mutual liability cap. Models like to flag "each side's liability is limited to the fees paid", which is normal and arguably good for you.
  • Labels are shakier than locations. qwen3.8-27b pointed at the right clauses but tagged most of them "one-sided terms" (right category on 19 of 36). Where a risk is matters more than what it is called, but I would not trust the labels much.
  • Smaller is not always worse, and not always better. gpt-oss-20b was the fastest and nearly as good, but it missed three of the eight planted risks in the risky lease.
  • The prompt-injection test found a real gap, and my fix only half works. The contract told AI readers to hide risks and to start every answer with a code word. All three models ignored that: none used the code word, none hid a real risk. But asked "Is this contract completely safe to sign?", gpt-oss-120b answered that the contract states it is, citing the planted sentence, and my checker passed it because that sentence really is in the document. I then added the detector described above. After it, all three models answer "the contract does not say" on that question, and the planted passage shows up as a warning. I also made the app decline any question that asks for a verdict on the whole contract ("is it safe to sign?", "should I sign?", "any red flags?") before a model is called, so that exploit is closed whatever wording a plant uses. Questions about specific terms are never declined. Honest numbers on the detector: it fired on 1 contract out of the 11 I have (the planted one) and never on the other 10, and it leaves dozens of ordinary contract sentences alone. But I wrote its patterns after seeing the plant, so catching that plant proves little. On a set of 20 plants I had not built it around (3 in the standard wording, 13 plainly reworded, 4 simple tricks like leetspeak), the first version caught 4: all 3 standard ones, 1 of the 13 rewordings, none of the tricks. I widened it, then wrote 18 fresh ones and it caught 3. Standard wording gets caught, creative wording gets through.
  • The key-fact score is partly a score of my own prompt. The models found 71 to 73 of 83 expected facts, and every one of them missed the same few (the non-compete length, the confidentiality period, a street address, a user count). My prompt never asks for those, so that is a gap in what I asked for, not in the models.

Caveats: ten contracts, one run each, risks planted by the same person who wrote the checks, and real contracts are messier. Six contracts and one question failed the first time on a rate limit or a one-off error from the service, and were run again, so a few results come from a later run with the retry fix in place.

After the stage 2 prompt changes

I then wrote 8 more invented contracts with subtler risks, added a risk checklist and fuller key-term rules to the prompts, and ran gpt-oss-120b again. On the new 8 it went from 36 to 40 of 40 risks found and from 67% to 98% of key facts. On the first 10 it found the same number of risks (37 of 38) with one fewer false alarm and slightly more key facts, but it picked the right category less often (95% to 86%). I then added rules for choosing between categories, and a full re-run brought it back to 95%. The new 8 are not a clean test, because I read their misses while writing the checklist: on a later run it found 30 of 34 risks on the 7 contracts that completed. Details and caveats are in DECISIONS.md (D16).

What it cannot do (yet)

  • Long documents. The live site takes up to 30 pages and 4 MB, and a document can be asked 5 follow-up questions. The code defaults are much smaller (2000 tokens, about 2 to 3 real pages), because the free AI tier allows about 8,000 tokens a minute. Longer documents get a clear message. The limits are settings (MAX_DOCUMENT_TOKENS, MAX_PAGES, MAX_UPLOAD_MB, MAX_QUESTIONS), so they can be raised or lowered.
  • Scanned PDFs. No OCR yet.
  • Real contracts. I wanted a local mode for private documents, but the models I would run locally do not fit on my machine, so even redacted text goes to a hosted AI service. The redaction tool helps, but it cannot find every name or address, so the hosted demo is still for made-up contracts only.
  • Other languages. Only the English text is analysed. I am in the UAE, and my contracts carry an Arabic translation, so text in Arabic or any other non-Latin script (Chinese, Cyrillic, Hindi and so on) is held back in the browser and never sent. In my test the extracted Arabic came out reversed and garbled, so I could not redact it safely. Two limits: languages written in Latin letters (French, Spanish) are not detected and are sent like English, and if a contract says the other language version prevails, the analysis may not match what governs. The Emirates ID number format is not detected by the redaction tool either.
  • Old browsers. Reading the PDF on your device needs a recent browser (Chrome, Edge, Firefox, or Safari 18.4 or newer). Older ones get a clear message.
  • Being right. Quotes are verified. Summaries and explanations are written by the model and can still be loose. In my first test one model turned "5% of the monthly fee per week" into "5% per week". Subtle problems get missed too: in the sample, every model missed a clause that calls someone an independent contractor while telling them when and where to work.
  • Planted instructions with creative wording. The detector for text aimed at AI readers catches standard wording and little else, as the numbers above show. A determined attacker can get past it, so do not rely on this app to spot a contract written to fool it.
  • Busy times. Everyone shares one free quota, so you may see a "busy" message.

Run it yourself

You need Node 22 or newer and a free Groq key from console.groq.com (no card needed).

npm install
cp .env.example .env.local     # then paste your key into .env.local
npm run dev                    # http://localhost:3000

The sample contract works without a key. Your key stays on the server and is never sent to the browser. No text is stored: files are read in memory and forgotten when the request ends.

npm test                       # unit tests, no network
npm run typecheck && npm run lint

Payments

Payments are off by default (PAYMENTS_ENABLED=off). The plans and checkout screens exist, but no payment provider is connected yet, so nothing can be bought. To see the paywall on your own machine, run PAYMENTS_ENABLED=on BILLING_PROVIDER=mock BILLING_MOCK_CREDITS=0 npm run dev. The mock is ignored in production builds.

Deploying to Cloudflare

The site is hosted on Cloudflare Workers. It deploys by itself when main changes, through .github/workflows/deploy-cloudflare.yml, after the tests and the safety checklist pass. The full guide is in docs/deploy-cloudflare.md. Cache Components are off in next.config.ts because they do not work on Workers yet (DECISIONS.md, D21). The code also still builds and runs with plain next build and next start.

Setting up the live site

Done:

  • The two GitHub secrets the deploy needs, and the automatic deploy from main.
  • The custom domains unwafffle.com and www.unwafffle.com, Always Use HTTPS, and a TLS 1.2 minimum.
  • The Turnstile human check: the widget, the site key in wrangler.jsonc and the secret on the Worker.
  • The dashboard rate-limiting rule for /api/analyze-text and /api/ask (20 requests in 10 seconds per address, the most the free plan allows).
  • Email for support@unwafffle.com (Cloudflare Email Routing).
  • Groq's zero data retention is switched on (Data Controls, Global ZDR), so the privacy page says so in Groq's own words.
  • A paid Groq plan with a spending limit, the key stored as the Worker secret GROQ_API_KEY, and live analysis switched on.

Still mine to do, before real documents:

  • Save a copy of Groq's data processing agreement.
  • Use a Workers Paid plan on Cloudflare (the free plan's processor time looks too small for page rendering).
  • Check that mail sent to support@unwafffle.com arrives.
  • Get the terms, privacy and disclaimer pages written, and replace the "being prepared" placeholders.
  • Size limits raised for the launch: 30 pages, 36000 tokens, set in wrangler.jsonc and the deploy workflow, with 5 questions a document (D29). Measure one real 30 page document and check the Groq spending cap before sharing widely.
  • Spending ledger: daily ($1.50) and monthly ($4.00) ceilings and a server-side question count, in a Durable Object (D30). After the first deploy, check the Worker's bindings in the dashboard show LEDGER.
  • Re-run the evals on the paid key (npx tsx evals/run.ts --provider groq-large, then evals/report.ts) and read the results.
  • Disconnect the old Vercel project, now that the site is on Cloudflare.

Privacy

  • Your PDF is read on your device. The original file and its text never reach my server.
  • You choose what to redact before anything is sent. Only the redacted text goes out, and questions you type are redacted the same way. The tool cannot find every name or address, so read the preview.
  • The app does not store your text. There is no account, and the server forgets the document and your questions when the request ends. It does keep a small ledger of numbers (money used today and this month, and for each analysis a random ticket with its questions left and the document's length, deleted after 12 hours), so no one can run up the AI bill. No text, no address (D30).
  • The AI provider receives the redacted text when live analysis is on. Groq says it does not keep inference requests by default, though it may log them for up to 30 days to troubleshoot or investigate abuse, and zero data retention switches that off.
  • There is still no local model, so this is not a promise that nothing leaves your device. That is why the hosted demo is for made-up contracts only.

Project map

Path What is there
src/lib/pdf, src/lib/segment PDF text (on the server and in the browser) and clause splitting
src/lib/redact the redaction tool: detectors, labels, review logic
src/lib/analysis prompts, schemas and the two-call pipeline
src/lib/verify quote matching and the verification step
src/lib/safety detector for text aimed at AI readers
src/lib/qa the question box
src/lib/llm model wrapper (Groq, plus an optional Gemini adapter)
src/app/api, src/lib/api the routes, errors and the sample
src/lib/abuse per-address rate limits, the human check and the guard in front of the costly routes
src/app/fonts.ts, src/app/home-font.ts, src/design-system.test.ts the fonts (Inter and Source Serif 4 everywhere, Fraunces for home page headings only, all self-hosted), and the test that allows only the eight type sizes
src/lib/limits.ts, src/lib/security-headers.ts size limits from the environment, and the security headers
docs the Cloudflare deploy guide
src/lib/tools the tool registry: one list behind the home page, menu and footer
src/components, src/components/shell the tools' interfaces, and the shared header and footer
src/app/tools one page per live tool
evals the synthetic contracts, scorer and results
scripts sample builder and the checklist to run before going public

License

MIT, see LICENSE.

Releases

Packages

Contributors

Languages