DEV Community

henry
henry

Posted on

How I Built a Contract Review Chrome Extension That Grounds AI in Real Statutes

I signed a contract I didn't read. The auto-renewal cost me money I didn't have. So I built PactLens.

The hard part wasn't the AI. It was preventing hallucinations.

The Hallucination Problem

Ask an LLM "review this contract clause" and it will confidently cite laws that don't exist. I tested this — GPT-4 invented a "Fair Contract
Terms Act 2024" and gave it a fake section number.

The Solution: Statute Grounding

PactLens pre-loads 1,700+ real statutes across 8 jurisdictions. Before the AI generates any analysis, we:

  1. Extract clause semantics from the contract text
  2. Run keyword matching against the statute database
  3. Inject the top N matching statutes as context into the prompt
  4. Force the AI to cite ONLY from the provided statutes

Result: zero hallucinated laws. Every citation is verifiable.

Why Not a Vector Database?

Embedding 1,700+ statutes would make sense architecturally. But CF Workers doesn't have great vector support, and the statutes are stable
enough for keyword matching + TF-IDF. The simpler approach works better at this scale.

Stack

WXT + TypeScript for the extension. Hono + CF Workers for the backend. DeepSeek for AI inference. The entire statute database lives in CF KV
as JSON.

What I Learned

  • Chrome Web Store review takes 2-3 weeks. Submit early.
  • The statute grounding is what makes users trust the output. Without it, it's just another GPT wrapper.
  • Freelancers don't search for "contract review AI." They search for "is this NDA clause normal?" Meet them where they are.

Try it: pactlens.net/contract

Top comments (0)