Skip to main content
Build a chatbot that answers “what does the law say” questions from statute text and a source link. Each user message runs one search, gets the best section’s text, and returns an answer with a link to the official source. It works in Slack, Discord, a web widget or a terminal. Endpoints: POST /us/statutes/search, GET /us/statutes/section/{actId}/body. Ground an LLM answer in statutes covers multi-source answers and prompt design. To answer in one call, pass "includeBody": true with "limit": 1. The price is the same. Keep the two-call version below if you rank three candidates and ground on one.

The loop

1

Search on the user's message

Send the message to POST /us/statutes/search. Scope with corpusType and state if your bot already knows the jurisdiction.
2

Pull the best section's text

Take the top result and fetch its full text with GET /us/statutes/section/{actId}/body.
3

Reply, grounded and cited

Give an LLM the section text and citation. Have it answer only from that text. Add the official source link.
The Python version is find_section() in the function below.

The full chatbot in one function

Python
To use the loop in Slack or Discord, call answer() from your message handler and post the result.

Tips

If your bot serves one state, pass state on every search. If users can switch states, pass the two-letter state code from the conversation. Omit corpusType and state to search all US law.
When search returns nothing or the body is unavailable, say so, as answer() does above.
Last modified on November 11, 2026