« All posts

Building a Compliance Answer Engine That Refuses to Hallucinate

How a Swiss compliance RAG system uses two-layer retrieval and mandatory citations to structurally block hallucinated numbers and claims.

Canton Compliance Hub is a free, multilingual tool built to untangle Switzerland's fragmented cantonal and federal compliance rules for foreign founders. The core engineering challenge wasn't content curation but trust: in a domain where a wrong number costs real money, answers had to be citable and hallucination-free. Instead of naive single-pass RAG, the team built a two-layer Postgres/pgvector system where raw chunks serve as the citation source of truth and distilled 'fact cards' are queried first, combined with hybrid BM25 plus vector search and canton/language metadata filters.

Rather than relying on prompt-level instructions to prevent hallucination, the system enforces structural controls: every factual claim must carry an inline citation marker, unmarked claims are flagged as defects, and any citation pointing outside the retrieved set triggers an automatic rejection and retry at temperature zero. The highest-leverage addition was a separate numeric verification pass, checking every rate, threshold, or CHF figure against retrieved evidence only and blocking publication of anything unsupported.

Content freshness is handled with plain engineering rather than AI: Last-Modified headers, ETags, on-page timestamps, and SHA-256 hashes determine whether an LLM needs to touch a page at all. Two byproducts, a canton minimum-wage comparison and an SME compliance deadline calendar, were released as open datasets under CC BY 4.0, and the underlying retrieval stack now also powers a free compliance self-check tool. The key takeaway: treat any missing or unverifiable citation as a build error, not a stylistic nuance, and verify numbers with a dedicated pass rather than trusting the draft model.

» SourceDev.to