← Portfolio Launch live assistant

Production case study

Oneida County Planning and Zoning — Grounded AI Workflow Assistant

Planning and zoning staff and citizens · Malad City, Idaho · Production case study

Citizens and county staff ask in plain language about permits, fees, land splits, and setbacks. The assistant answers from the county’s own ordinances, maps, and forms, with the official PDF attached, or it hands the question to the office.

The assistant answering how to build a house, with citations into the county development code and a building-permit checklist.
A cited answer, linked to the official county PDF.
The assistant home screen listing guided workflows for citizens and for planning and zoning staff.
Citizen and staff workflows on the home screen.

33Official ordinances, maps, and forms indexed

1,199Sentence-aware statutory chunks · 407 sections

22Guided citizen and staff intake workflows

6Top-ranked chunks, plus inline PDF citations per answer

68Automated Vitest security and guardrail invariant tests

0Unbounded hallucinations · deterministic zero-match routing

The constraint

A code this large breaks a blank chat box

Planning and zoning in Malad City is a counter, a code book, and a monthly meeting. The questions are concrete. What the permit costs. How a parcel can be split. How far a building sits from a line. Which form is missing. Who has to sign. Whether the neighbors must be invited first.

Those answers were given from memory. The paper behind them does not fit in one person’s head, and it does not forgive a miss. Development Code Ordinance 2022-08-01 runs 237 pages. An amended comprehensive plan sits beside it. Three maps cover zoning, fire risk, and land use. Twenty-seven applications and checklists carry the actual filings.

An applicant could turn in a packet that looked finished, then learn a form, a neighborhood meeting, or a signature was missing. The commission meets on a monthly cycle. A miss waits a month.

Thirty-three official county documents are in the index now, including that code, the plan, the maps, and the 27 filings. A general chatbot is the wrong instrument for the pile. Asked for a setback or a fee, it will compose a number from the shape of the question. A property line and a permit fee are the wrong place for a statute the county never wrote.

The architectural choice

A bounded workflow

Retrieval first. Temperature 0.3. Zero matches never reach the model.

Citizens ask about property rights, setbacks, and permit fees. The system that answers them is a deterministic, multi-stage grounded RAG and routing workflow. It does not give the model a goal and a set of tools to chase.

The order is fixed. Sanitize the question. Rank the corpus. Count the matches. Call Claude Sonnet 4.6 at temperature 0.3 only when that count is at least one, and only on passages wrapped in an XML trust boundary. When the count is zero, stop. The reply is a warm handoff to the Planning and Zoning Administrator: the office phone, the suite, and the hours. No tokens are spent, and no ordinance is invented.

An open autonomous loop would pick its next step as it went. The wait would wander, and a gap in the files could still come back written like a statute. The county gate is a number, checked before any prompt is built.

Runtime and ingestion

How a question moves

Three tracks run the assistant. Track A turns an official file into searchable chunks. Track B turns a question into a cited answer, or into a handoff. Track C shows staff which questions the documents missed, and lets them add the form without a deploy. Select a step to read it.

  • Process step
  • Decision gate
  • Human handoff

Scroll sideways to read the diagram.

Oneida County assistant architecture Track A ingests official files into a TF-IDF index. Track B ranks a question, and either hands it to the Planning and Zoning Administrator or answers from the top six chunks through an XML trust boundary. Track C logs pseudonymized questions, ratings, and citation gaps for staff to close by uploading the missing form. TRACK A Secure document ingestion Multi-format upload .pdf .docx .xlsx .rtf .txt Magic-byte sniff file-type signature before any parse Sandboxed parser Page budget Time budget Sentence chunker 1,000 characters 200-char overlap Statutory index PostgreSQL JSONB In-memory TF-IDF A file is indexed only after the signature, the parser budget, and the chunker agree. TRACK B Query, routing, and grounding User / staff question Plain-language ask Sanitize and limit 12 per minute 300 per day TF-IDF rank Top 6 statutory chunks Logarithmic IDF Decision gate Matches > 0? 0 MATCHES Deterministic short-circuit The model is not called. Zero tokens. Zero hallucination. Handoff: phone, suite, and office hours. 1+ MATCHES Grounded generation XML trust boundary, then the model. Claude Sonnet 4.6 at temperature 0.3. Four steps below build the reply. 1+ MATCHES · THESE FOUR STEPS XML trust boundary <document_context> <user_question> Claude Sonnet 4.6 Temperature 0.3 Grounded generation Regex output parser Answer and citations Three follow-up chips Grounded answer Official PDF pills 3 follow-up chips A miss stays with the office. A hit quotes the top six chunks and links the official PDF. TRACK C Admin loop and knowledge gaps HMAC-SHA256 log anon: + 16 hex Thumbs-up or down Rating on each answer No-docs-cited flag Uncited replies Admin dashboard /admin Log, ratings, and gaps Add the missing form Drag and drop /documentation Three signals meet on /admin. A file added at /documentation re-enters Track A. Rows older than 365 days are purged.

Select a step. Track A is ingestion, Track B is the question path, and Track C is the admin loop.

Read each step

Track A — Secure document ingestion

  1. Multi-format upload accepts .pdf, .docx, .xlsx, .rtf, and .txt.
  2. Magic-byte sniffing (file-type) checks the signature before a parser runs.
  3. The parser is sandboxed, with a page budget and a time budget.
  4. A sentence-boundary chunker cuts 1,000-character windows with a 200-character overlap.
  5. Chunks land in PostgreSQL as JSONB and in an in-memory TF-IDF inverted index.

Track B — Query, routing, and grounding

  1. A citizen or a staff member asks a question.
  2. Sanitization runs, then a dual-window rate limiter: 12 per minute, 300 per day.
  3. TF-IDF statutory ranking keeps the top 6 chunks.
  4. The decision gate asks whether the match count is greater than zero.
  5. Zero matches bypass the model. The reply is a warm handoff to the Planning and Zoning Administrator, with phone, suite, and hours.
  6. One or more matches enter an XML trust boundary: <document_context> and <user_question>.
  7. Claude Sonnet 4.6 answers at temperature 0.3.
  8. A regex parser extracts the answer, the citations, and three follow-up chips.
  9. The screen shows the grounded answer, clickable official PDF pills, and the three chips.

Track C — Admin observability and knowledge gaps

  1. The question log stores an HMAC-SHA256 pseudonym, anon: plus 16 hex characters, after query strings are stripped.
  2. Thumbs-up and thumbs-down ratings are kept as an eval signal.
  3. A zero-citation detector flags replies with no documents cited.
  4. Staff read the log, the ratings, and the gaps on /admin.
  5. Staff drag the missing form onto /documentation. It re-enters Track A.

In production

Five pillars

The diagram is five decisions, carried through on the live assistant.

  1. 01

    Context engineering and statutory TF-IDF retrieval

    The ranker is custom logarithmic TF-IDF over the statutory chunks. In this corpus the words county, permit, and application show up almost everywhere, so they are weak signals. The score pushes them down. It pushes the terms that mark a real rule up: setback, variance, probate, floodplain, and the 180-day temporary placement limit.

    That is how a two-page checklist can outrank a passage from the 237-page development code. Length does not win. The words that distinguish the rule do. A question about a 180-day temporary placement should surface the short passage that states it, rather than every chunk that merely says county and permit.

    The chunks are sentence-aware. Ingestion splits each official file on sentence boundaries into overlapping windows of 1,000 characters, with a 200-character overlap, so a rule sliced by a cut still appears whole in one window. The index holds 1,199 chunks across 407 sections, from 33 official PDFs. They sit in PostgreSQL as JSONB and in memory as an inverted index. Ranking finishes before a model is called. The model may see the top 6 chunks, and each citation links to the official county PDF.

  2. 02

    Deterministic routing and dual-persona workflows

    A blank box is a weak front door for a permit. The assistant opens on 22 deep-linked workflows, split evenly between the public and the counter.

    11

    Citizen guides

    Includes building a house, a family or agricultural land split set against a subdivision, a variance, a conditional use permit, a neighborhood meeting, floodplains, and a Right-to-Farm agreement.

    11

    Staff checklists

    Includes conditional use intake, setback tables for the A-1, R-1, RR, C, and I zones, public hearing notice radiuses, division-right research, and fire protection plans.

    Both personas use the same corpus, the same ranker, and the same gate. The workflows differ because the jobs differ. A citizen needs to know what to file. Staff need to know what to check.

    Every question is sanitized first. A dual-window rate limiter then allows 12 questions a minute and 300 a day, so a script cannot walk the code book through the model. TF-IDF returns its matches. The gate reads the count.

    Zero matches skip the model and return the warm handoff to the Planning and Zoning Administrator, with the phone, the suite, and the hours. One or more matches take the grounded path: the top 6 chunks, the XML boundary, Claude Sonnet 4.6 at temperature 0.3, a regex parser, and a reply the interface can render. The person sees the answer, clickable pills to the official PDFs, and three next-step chips.

  3. 03

    Defense-in-depth guardrails and trust boundaries

    The realistic attack on a document assistant is a sentence inside a file that tells the model to drop the county and follow new orders. Retrieved text is sandboxed in XML. Passages sit inside <document_context>. The person’s question sits inside <user_question>. The model is instructed to treat the document tags as source material.

    Uploads are identified before they are parsed. Magic-byte sniffing, via file-type, checks that the bytes match a PDF, a Word document, a spreadsheet, an RTF file, or plain text. The parser then runs in a sandbox with a page budget and a time budget, so a hostile file cannot pin the process. Session changes are checked with timing-safe CSRF tokens.

    Anonymous citizens. An ephemeral session, held in memory. Asking a question does not open a standing county record.

    Signed-in staff. A persistent history in PostgreSQL, so the counter can keep the thread.

    Model output is not drawn onto the page as free HTML. A regex parser keeps the answer, the citations, and the three chips.

  4. 04

    Privacy by design and municipal governance

    Staff need a log. They need to see which questions the documents could not answer. A raw IP address does not belong next to a question about someone’s land.

    • The address is keyed with HMAC-SHA256 and stored as anon: plus 16 hex characters. The same visitor can be counted. The address itself is not written down.
    • Query strings are stripped from URLs before a row is stored, so tokens and search parameters stay out of the table.
    • A purge deletes log rows older than 365 days.

    The admin view at /admin is where that log becomes useful. Adding the missing form is a drag-and-drop on /documentation, not a change to the code.

  5. 05

    Closed-loop evals and build-time verification

    Every answer can be marked thumbs-up or thumbs-down. A separate check flags replies that cited nothing, labeled “No docs cited.” Those signals, with the pseudonymized question, are what staff see on /admin. A run of uncited questions is a missing form, a missing map, or a missing page. Staff upload that file. Track A indexes it. The next person to ask is ranked against a fuller corpus.

    The same boundaries were checked before the system shipped. The codebase was audited across 10 security domains and hardened with an evaluator-optimizer loop. 68 Vitest tests lock the security and guardrail invariants from that pass, including the zero-match short-circuit, the trust boundary, the rate limits, the pseudonym, the upload sniff, and the retention purge. A change that breaks one of those does not ship.

Production stack

Built with

App
  • React 18 + TypeScript
  • Wouter
  • Tailwind
  • shadcn/ui
Agentic RAG
  • Claude Sonnet 4.6
  • Custom TF-IDF Statutory Index
  • XML Trust-Boundary Sandboxing
  • Deterministic Fallback Routing
Corpus & Eval
  • 33 Official PDFs (1,199 Chunks)
  • 22 Citizen & Staff Workflows
  • Admin Gap Telemetry & Thumbs Eval
Data & Infra
  • Node.js + Express
  • PostgreSQL (Supabase) + Drizzle
  • HMAC-SHA256 Privacy
  • Render
  • 68 Vitest Security Tests

Live

Open the assistant

Citizens and county staff can ask a real planning or zoning question. The assistant answers from the county documents, or it hands the question to the office. The live app is at oneida.m80.ai.