Skip to content
RAGGovernmentAI Agents

AI document management for government: RAG that respects permissions

Malgary Labs· ·8 min read

Every ministry has the same quiet problem. The documents exist: policies, proposals, appraisal reports, cabinet summaries, minutes. Finding the right one, the latest version of it, and the paragraph that actually answers today’s question takes far longer than it should.

AI can fix a large part of that. It can also create a new problem if it is bolted on carelessly: an assistant that happily quotes a document the person asking was never cleared to read. This is a practical guide to doing it properly, based on what we built for MNFSR Documents, the document management system for Pakistan’s Ministry of National Food Security & Research.

Start with the boring part: structure

AI does not rescue a messy archive. Before any model is involved, a government document system needs three things in place.

  • An organisation tree. Ministry, wings, departments, sections. Every document belongs somewhere in it, because that is how access, reporting and accountability work in government. For MNFSR that meant 7 wings and 14 attached departments, each with its own sections.
  • Categories the ministry already uses. Policies, rules, proposals, appraisal reports, project completion reports. MNFSR started with 56 of them. A fixed vocabulary is what makes search, filters and dashboards meaningful.
  • Versions, not copies. A document is one record with a version history, not five files called final, final-2 and final-revised.

Get this right and the AI features have something solid to stand on. Skip it and you are asking a model to make sense of chaos.

Permission-aware RAG: answers with sources

The headline feature is the one everybody asks for: “let me ask the archive a question.” The technique behind it is retrieval-augmented generation (RAG). Instead of hoping a model memorised your documents, you search your own archive for the passages most relevant to the question, hand those passages to the model, and ask it to answer from them. (If RAG is new to you, our RAG vs fine-tuning guide covers the basics.)

In government, one rule matters more than any model choice:

Filter by permission before you retrieve, not after.

Permission-aware retrieval for a ministry document archive An officer's question is matched only against documents they are allowed to see. The most relevant passages go to the language model, which answers with citations to the source documents. Ministry archive red = no access Permission filter Retrieve passages LLM answer with citations Officer asks a question [1] Policy v4 · p.12 [2] Appraisal · p.3
Permissions filter the archive before retrieval, so the model only ever sees documents the officer may read, and every answer points back to its sources.

If an officer in one section asks a question, the retrieval step should only ever search documents that officer could open in the normal interface. The permission check runs first, on the same access rules as the rest of the system: ownership, shares, role and section. Only then are the matching passages ranked and passed to the model.

Doing it the other way round, retrieving from everything and hiding forbidden results afterwards, is how sensitive text ends up summarised inside an answer even though the source file never appears.

Three more rules make the answers trustworthy:

  1. Always cite. Every answer links to the document, the version and the page it came from. An officer should be able to check a claim in one click.
  2. Say “I don’t know”. If the retrieved passages do not answer the question, the assistant says so instead of guessing.
  3. Log every question. Queries go into the same audit trail as uploads and shares. In government, the record of who asked what is part of the system.

Version comparison: what actually changed

Policies go through drafts. The useful question is rarely “show me version 4”. It is “what changed since version 3?” Reading two long PDFs side by side to find a moved deadline is exactly the kind of work a language model does well.

In MNFSR Documents an officer picks two to eight versions and the model returns a short list grouped into added, removed and updated. A typical result: a lab accreditation deadline moved by six months, a new section on seed traceability, an interim exemption removed.

Two engineering details make this dependable:

  • Send the documents, not a description of them. The model gets the actual files, within sensible size limits, and a low temperature so it reports changes rather than inventing them.
  • Cache the result on the version. A comparison is computed once, stored, and written to the audit log. The next person sees the same answer instantly.

Smart filing: categories, tags and summaries on upload

Consistent filing is what makes everything else work, and it is the first thing that slips when people are busy. So the system does the tedious part.

When a file is uploaded, the AI suggests a category from the ministry’s own list, a few tags, a short summary and the owning section, and reads scanned pages with OCR. The officer accepts or edits the suggestions in one step. The human stays in charge; the AI just removes the blank form.

The key design choice is that suggestions come from a closed list. The model picks from the ministry’s 56 categories rather than inventing new ones, so the archive stays clean.

Security is the feature

AI gets the attention, but a ministry will judge the system on control. The basics we would not ship without:

  • Roles and per-user permissions. Three roles, with individual capabilities that admins can switch on or off per person.
  • Sharing with limits. Share with a person or a whole section as Viewer, Downloader or Editor, with an optional expiry. Public links get a password, an expiry and a download cap.
  • Short sessions. Short-lived access tokens, rotating refresh tokens, lockout after repeated failed sign-ins, and a forced password change for new accounts.
  • A complete audit trail. Sign-ins, uploads, shares, versions and AI queries, exportable for review.

None of this is glamorous. It is what makes it safe to put an AI assistant in front of official documents.

How to start

You do not need a two-year digital transformation programme. A sensible first release is:

  1. The organisation tree, categories, versions and sharing rules.
  2. Version comparison, the quickest AI win because it needs no index.
  3. Permission-aware RAG over one wing’s documents, then the rest of the ministry.
  4. Smart filing once there is enough history to check the suggestions against.

That is a few weeks of focused work for a senior team, and it can start as a 7-day MVP sprint on a slice of real documents. If you are planning an AI document system for a ministry or a regulated organisation, our AI development services page explains how we work, or you can book a free call.

2 sprint slots open this month

Got an idea worth building?

Book a free 30-minute consultation. We will scope it, price it, and tell you honestly whether we can deliver, or who can.

Book free consultation Or send a message
  • Reply within one business day
  • NDA on request
  • You own the code
What happens next Free
  1. 01
    30-minute call

    Walk us through the idea, the users and the deadline.

  2. 02
    Scope & architecture

    We map the smallest version worth building, and the stack.

  3. 03
    Fixed quote in writing

    Price, timeline and team. No obligation to go ahead.