Keeping a RAG chatbot inside one case file
On Legiflow, a lawyer's question could only be answered from the case file in scope. Why that constraint was the product, and why it lives in retrieval rather than the prompt.
Legiflow is an AI tool for legal documents that I worked on at Devsarch. Case files come in, entities and structure are extracted, and a lawyer can ask questions about a case. The chatbot had one rule above everything else: answers can only come from the case file in scope.
Why the constraint is the product
A general-purpose assistant that is mostly right is a liability in legal work. If an answer about one case quietly draws on a paragraph from another, the lawyer has no way to tell, and the mistake reads exactly as confidently as a correct answer. The useful property is not how much the model knows. It is what it is not allowed to see.
Where the boundary lives
The pipeline has two halves:
- Ingest: case files from Wasabi or S3 are extracted, chunked, embedded and stored in PostgreSQL, with metadata recording which case file each chunk belongs to.
- Ask: a question goes through retrieval scoped to a single case file, and only then to Gemini, which answers with a citation.
The scoping happens in retrieval, before the model is involved. Telling a model "only use documents from this case" in the prompt is a request. Filtering the chunks it receives is a guarantee: a chunk from another case that never reaches the context cannot leak into the answer.
Citations close the loop
Every answer comes back with a citation into the case file, so a lawyer can check the source instead of trusting the model. That turns the chatbot from something you have to believe into something you can verify.
What it changed
Together with extraction and structured storage, it reduced manual review time by 40%.