Private AI for sensitive documents
For engineers
Scenario lesson and practice set combining Running models locally, Workplace confidentiality, Vector search and Confidentiality and privilege. Completing it counts as evidence for every listed skill.
The one-sentence idea: when a team wants AI to work on confidential documents, decide first what the documents are and who allows what, then choose a setup where the text stays inside the firm, and enforce access in the database, not in the prompt.
The case
Hartley & Voss is a 14-lawyer firm. Its lawyers lose hours searching old leases, NDAs and call notes. An engineer is asked to build an assistant that finds the right clause and summarizes it. Last week an associate pasted a client's lease into a personal chatbot account to get a quick summary. It worked well, and that is the problem: the quickest route is also the one the firm cannot see, audit or delete from.
The firm's engagement letters promise confidentiality. One matter is under a court seal. An NDA with a counterparty says confidential information must stay on systems the firm controls. These facts, not the technology, set the design.
Why it matters
Four skills meet in this one project. If any of them is missing, the others do not rescue the result.
- Workplace confidentiality tells you what the material is and whether a tool may touch it.
- Confidentiality and privilege covers the tool tier, settings, consent and what to do after a slip.
- Running models locally lets the text stay on a machine the firm owns.
- Vector search makes the documents findable, and it holds the permission boundary between matters.
How to do it
- Sort the documents. List folders and ask what each holds, which contract or seal applies and who owns it. Client matters, NDA material and sealed files go on the strictest list. The firm's blank templates can go anywhere the firm allows.
- Pick the tool tier. A free or personal chatbot account has no firm contract, no admin controls and may train on chats. A business plan has a signed agreement and settings an admin can lock. A model running on the firm's own server sends nothing to a third party. For sealed and NDA matters, use the third.
- Run the model locally. Install a runner such as Ollama or llama.cpp, pull an open-weight model and set a context size big enough for the documents. Keep the API on
127.0.0.1and put an authenticated proxy in front of the chat UI. Read the load log: check GPU offload, context length and that the bind address is not0.0.0.0. - Index with pgvector. Store chunks and their vectors in the firm's existing Postgres, with a
matter_idcolumn. Use the distance operator that matches the embedding model, for example<=>withvector_cosine_ops. Take the allowed matter ids from the signed-in user's record on the server. Row-level security is a second lock. - Handle filters honestly. A filter on an approximate index can return fewer rows than asked for. Test a user who sits on one small matter, and use iterative scans, a larger
ef_search, partial indexes or partitions. - Control logs and consent. Prompts and answers are client records and may be ordered produced in a dispute. Set a retention period, limit who reads the logs and redact where you can. Where text must go to a hosted provider, get informed client consent that names the data and the provider.
- Plan for slips. Tell staff to report a wrong paste the same day. The partner decides whether the client must be told, so speed matters more than tidiness.
Before and after
Before: associates paste files into personal accounts, one shared vector table serves every user, the model API listens on every interface, and the prompt says "only use matter A".
After: sealed and NDA matters use the local model, its API listens on localhost behind sign-in, the search query filters by the matter ids the server looks up, logs have a retention rule, and staff know to report a slip at once.
What goes wrong
- A prompt used as a lock. The retrieval step has already put other matters' text in the model's context. Enforce access before retrieval.
- A local model that is open to the network. "Local" means where it runs, not who can call it. Bind it to localhost and authenticate in front of it.
- Silent truncation. A small context window drops the end of a long contract and the answer still sounds complete. Check the load log and compare answers with the source clause.
- Redaction that leaves rare facts. A unique detail can identify a client when names are gone.
- Hidden records. Chat logs and vectors are client data. They need the same retention and access care as the files.
Steps
Sort the folders by contract and seal
Before any tool is chosen, list each folder and note what it holds and which duty applies. Client matters, NDA material and sealed files need a tool where text stays under the firm's control. The firm's own templates carry no such limit.
Document sort for Hartley & Voss Folder Duty Allowed tools /matters (sealed) Court seal, engagement letter Local model only /matters (other) Engagement letter, NDA terms Local, or hosted with client consent /templates None Any approved tool Choose the tool tier and settings
Compare options by contract, not by brand. A personal account has no firm contract and may train on chats. A business plan has a signed agreement and admin settings. A local model sends nothing out. Lock training, history and sharing settings for any hosted tool the firm keeps.
Tool tiers compared Tier Contract Where text goes Personal chatbot account Consumer terms Provider cloud Hosted business plan Signed DPA, admin controls Provider cloud Local open-weight model None needed Firm server only Start the local model and read the log
Install a runner on the firm server, pull the model and set a context size large enough for contracts. Keep the API on localhost and let only an authenticated proxy reach it. Read the load log for three facts: GPU offload, context length and bind address.
Ollama setup on the firm server setup.sh
ollama pull llama3.1:8b# keep the default bind: 127.0.0.1:11434export OLLAMA_CONTEXT_LENGTH=16384ollama serveIndex chunks in Postgres with a matter column
Store chunk text, matter id and embedding in one table. Build an HNSW index with the operator class that matches the embedding model. The search query takes its list of matter ids from the signed-in user's record on the server.
Search query with matter filter search.sql
SELECT id, bodyFROM chunksWHERE matter_id = ANY($2)ORDER BY embedding <=> $1LIMIT 8;Test a user on a small matter
A selective filter on an approximate index can return fewer rows than asked for. Try a user with one small matter and count the results. If they are short, raise ef_search, enable iterative scans, or add a partial index or partition for that matter.
Set log retention and client consent wording
Prompts and answers are records that can be ordered produced. Decide how long they are kept and who reads them. If any text goes to a hosted provider, the engagement letter says so, names the data shared and tells the client they may object.
Teach the same-day report rule
Show staff what the approved route is and what to do after a wrong paste: report it that day to the confidentiality lead, with the tool and the text involved. The partner decides whether the client must be told.
Skills this scenario uses
Where to study
- Ollama documentation (opens in a new tab)DocsFree
How to pull models, set context length and run the local API.
- Ollama FAQ (opens in a new tab)DocsFree
Explains the default bind address and how OLLAMA_HOST changes it.
- llama.cpp (opens in a new tab)ToolFree
The runner for GGUF files, with llama-server flags for GPU layers and context.
- whisper.cpp (opens in a new tab)ToolFree
Local speech-to-text for call recordings that must not leave the firm.
- pgvector: open-source vector similarity search for Postgres (opens in a new tab)ToolFree
Distance operators, HNSW and IVFFlat indexes, and filtering notes.
- PostgreSQL: Row security policies (opens in a new tab)DocsFree
How to enforce per-user row access inside the database as a second lock.
- AI and cyber security: what you need to know (NCSC) (opens in a new tab)DocsFreeUK
Plain guidance on the security risks of using AI tools with organisational data.