This page is the “why” and the judgment calls. The runnable, copy-paste implementation lives in the RAG grounding recipe, including the retrieval loop, the prompt, the citation check, and the tool-calling agent variant. Read this first, then go there for code.
Why grounding matters
A model with no retrieved context is answering from a compressed, lossy memory of its training data. For statutes that produces three predictable failures:- Fabricated citations. The model emits a section number that looks right but does not exist, or points to the wrong title or chapter.
- Misquoted text. Even when the citation is real, the quoted language drifts from the enacted text. Small wording changes matter in law.
- Overconfident coverage. The model answers a question the law does not actually address, rather than admitting the sources are silent.
The pattern
Four steps turn a raw question into a grounded, verifiable answer.1
Retrieve the relevant sections
Send the user’s question to
POST /us/statutes/search. Scope it with corpusType (and state for state-scoped corpora) so you search only the body of law that can answer it. Each result carries an actId, a citation, an excerpt, and a source URL.2
Fetch the authoritative text
The
excerpt is a ranking preview, not quotable text. Get the real thing either by setting includeBody: true on the search, which attaches each hit’s full text on body in the same call, or by calling GET /us/statutes/section/{actId}/body per section. Both bill 6 credits per body served, so this is a latency choice rather than a price one.3
Construct a grounded prompt
Build a prompt that gives the model the retrieved sections, each labeled with its citation and source URL, and instructs it to:
- answer only from the provided sections,
- cite each claim by its
citation, - say plainly that it cannot find support when the sources do not cover the question.
4
Link back to the source
Show the answer with its citations, and link each one to the official government source URL returned with the section. The user verifies against the primary record, not against the model.
Practical guidance
A few habits keep grounded answers accurate and cheap.Scope retrieval to the right corpusType
Scope retrieval to the right corpusType
Searching the entire corpus for a question that only a state penal code can answer pulls in noise that competes for the model’s attention. Pass the narrowest
corpusType that fits (for example USC for federal statutes, or STATE with state: "ca" for California codes).If you are unsure which corpora a jurisdiction has, call GET /us/statutes/coverage and read the corpora keys before you search. See Coverage.Never quote the excerpt
Never quote the excerpt
excerpt is windowed around whatever matched, so it can begin mid-section and drop a leading subsection marker. A passage that lost its opening (a) reads as the whole section and is not. Quote from body, which is the document as the publisher printed it, and treat excerpt as a ranking signal only.Keep the retrieved text verbatim
Keep the retrieved text verbatim
Do not summarize, clean up, or paraphrase a section before it reaches the model. Paraphrasing is where meaning quietly shifts, and it defeats the point of grounding. Pass the
plain text through untouched, and let the model quote from it directly.Carry the citation and source URL with every passage
Carry the citation and source URL with every passage
When you assemble the context block, keep each passage next to its
citation and its source URL (for example htmlUrl, stateHtmlUrl, or govInfoHtmlUrl). That lets the model attribute claims correctly and lets you render clickable, verifiable citations in your UI.Treat relevanceScore as a relative rank, not a threshold
Treat relevanceScore as a relative rank, not a threshold
relevanceScore orders results within a single response. It is not a calibrated confidence score and is not comparable across queries.Do not drop results below a fixed cutoff like 0.5 or trust a high score as proof of relevance. Use it to order what you show, and let the grounded prompt decide whether the sections actually answer the question.Verify the model's citations before showing the answer
Verify the model's citations before showing the answer
A grounded model should only cite sections you retrieved, but verify it anyway. Before rendering, check that every
actId or citation the model used appears in the set you passed in.Drop or flag anything that does not match. This catches the rare case where the model reaches back into its own memory instead of the provided context.Watch what retrieval costs you
Watch what retrieval costs you
A grounded turn is one search plus one body per section you cite. Four full bodies is 4 + 24 = 28 credits, and
includeBody: true on a 50-result page is 304. Cache on actId, which is a stable handle for a section, and read creditsConsumed on every response rather than computing cost from your page size.Related
RAG grounding recipe
The runnable version: retrieval loop, prompt, citation check, and the tool-calling agent variant.
Statute chatbot recipe
Build a multi-turn chatbot that stays grounded across a conversation.
MCP tool
Expose Vaquill AI statute lookups as tools inside an agent framework.
Best practices
Scope queries, choose a
matchType, cache coverage, and handle errors well.
