AI Document Assistant: Cited Answers from Your Files by Mojtaba KarimiabdarAI Document Assistant: Cited Answers from Your Files by Mojtaba Karimiabdar

AI Document Assistant: Cited Answers from Your Files

Mojtaba Karimiabdar

Mojtaba Karimiabdar

Real screenshots: verbatim quotes with page links, and a finance manager who cannot see the HR salary sheet.
Real screenshots: verbatim quotes with page links, and a finance manager who cannot see the HR salary sheet.

The challenge

Companies keep their answers in contracts, invoices and policies that nobody has time to read. Generic AI chatbots guess, cannot show where an answer came from, and often let everyone see everything.

The solution

I built an AI document assistant (RAG) in Python. People ask questions in plain language and get answers with the exact page as proof, while every user only sees the documents they are allowed to.

Answers you can check

A finance manager asked about payment terms: the answer came from 3 documents, each quoted word for word with its page, at 92% confidence.
Every quote is checked against the document before it is shown.
Asked about the HR salary sheet, the same manager got "not enough information": the document never reached the manager's search.
A passage with a planted instruction to the AI was excluded automatically.
The real Deadlines page and the real evaluation run: 31 test questions, all 8 quality metrics at 1.000.
The real Deadlines page and the real evaluation run: 31 test questions, all 8 quality metrics at 1.000.

How it works

Upload: PDF, Word, Excel, CSV, text and Markdown, checked and parsed in a locked-down sandbox, then encrypted at rest.
Understand: structure-aware chunks, document type, sensitivity level and key fields such as parties, dates and amounts, each tied to a quote.
Search: keyword and meaning search combined (PostgreSQL full-text and pgvector), with permissions applied inside every query.
Answer: grounded answers with verified citations, or "not enough information" instead of a guess.
Deadlines: due dates and renewals come straight from the extracted fields, with no AI involved. The real run found an invoice due in 24 days and a contract expiring in 31 days, each with its quote and page.
Measured: the built-in evaluation asks 31 questions (17 answerable, 5 with no answer, 9 attacks) and scored 1.000 on all 8 quality metrics.
Built for confidential documents, plus the 3 bugs a live run found and fixed. 1,748 tests at 90% branch coverage.
Built for confidential documents, plus the 3 bugs a live run found and fixed. 1,748 tests at 90% branch coverage.

Security and quality

Each company kept apart: PostgreSQL row-level security on every table, least-privilege database roles and 5 user roles.
Prompt-injection defence: injected passages are scored and excluded, and the answering model has no tools.
Data governance: restricted text never goes to an outside AI provider, and personal data is masked first. This demo ran fully offline.
Encrypted and audited: AES-256-GCM at rest, MFA and a tamper-evident audit chain.
Tested on a live run: it found 3 bugs the tests had missed (the quality check throttled itself, a quote cut mid-word failed its own proof check, and the deadlines page broke on Windows). Each one is fixed with a test that fails without the fix.
1,748 automated tests at 90% branch coverage against a real PostgreSQL, plus ruff, mypy, import rules, bandit and CodeQL.
Tech stack: Python, FastAPI, PostgreSQL with pgvector, SQLAlchemy, Redis, Claude (Anthropic) or a local model, and Docker.
Want an AI assistant for your company's documents that shows its sources and respects permissions? Send me a message with the kinds of documents you have.
Like this project

Posted Oct 15, 2026

Ask contracts, invoices and policies in plain language and get answers with the exact page as proof. Per-user access. 1,748 tests.