We build NostraCasa, an AI assistant for Polish housing communities (wspólnoty mieszkaniowe). Owners, boards and property managers ask questions in plain Polish ("can the board refuse to show me the invoices?") and expect an answer that points to the exact provision: the Act on Ownership of Premises (UoWL), the Civil Code, or the Construction Law.

Legal Q&A is a domain where a fluent but wrong answer is worse than no answer. Here is what we learned keeping the model honest about citations.

1. One article = one chunk

The corpus is the official consolidated text of the statutes (from ISAP / ELI). We chunk by article, not by token count. A legal article is the unit people cite, so retrieval returns something the model can quote as "art. 29 ust. 3 UoWL" without stitching fragments together.

Each row in Postgres keeps act_code, article, heading and body next to a pgvector embedding (1024-dim, mistral-embed). A single RPC returns the top matches for the user's question.

2. Retrieve more than you think

We started with the top 5 articles and moved to 8. Housing questions often touch two acts at once (e.g. the owners' resolution under UoWL plus a building inspection duty under the Construction Law). A wider context noticeably reduced answers that cited the right idea under the wrong article number.

3. Mark archival law explicitly

Some regulations get repealed while they are still the most searched text. Instead of deleting them, we keep the chunks and inject a note: archival text, do not apply as current law. Otherwise the model happily quotes a provision that stopped applying.

4. A second, cheaper model checks the citations

After the main answer is generated, a mid-size model gets the answer plus the retrieved articles and does exactly two jobs:

  • verify every cited provision (art. X, §, ust.) against the retrieved text and common knowledge, and fix the number when it is wrong,
  • repair broken text (stray foreign characters, mangled words) without rewriting correct Polish.

If everything is fine it returns OK, and the answer goes out unchanged.

5. Everything fails open

Embeddings down, empty corpus, verifier timeout, rate limit: the chat still answers, just without that layer. A legal assistant that blocks on infrastructure errors trains users to go elsewhere. Every layer has a hard time limit so it can't add many seconds to a response.

6. Quote laws, paraphrase books

Statutes can be quoted verbatim. Commentaries and guides in the knowledge base cannot. Asking the model nicely isn't enough, so after generation we look for word n-grams copied from protected passages, have the model rephrase just those sentences, check again, and drop whatever is still verbatim.

7. Gate the topic with a model, not a keyword list

Our first scope filter was a keyword whitelist. It rejected perfectly valid questions like "can my neighbour play loud music in the evening". A tiny LLM call that is biased toward allow (and also fails open) works much better.

If you work on RAG for legal or regulatory text, the biggest win for us was making the citation the unit of everything: chunking, retrieval, verification. You can try the assistant (Polish only) at nostracasa.pl.

Written by the NostraCasa team.