BT San Technology

29 January 2026

Preparing Company Documents for AI: Organize Your Data Before RAG

27 min read · AI for business · AI by department

Illustration: hands sorting three versions of a manual, the current one into a checked tray and the old ones into an archive box, binders behind
AI-generated illustration

A team fed the whole "manuals" folder to a chatbot. On the first day of the trial, the bot said employees get 10 days of vacation, although the new policy says 12, because the folder also held the old version. In another case, the bot quoted an employee's national ID number to someone who should not see it. Neither problem is in the model. Both are in what was put into it.

This article covers the step before our existing RAG and vector search examples. We write a script that checks "document readiness". It reads a folder and decides file by file whether each one is ready to ingest, needs masking first, or is held back, and why. It includes Node 24 code you can run yourself, real output and a test suite. A manager who reads only the explanations and tables will still see what this work is.

The real problem: AI answers from what we give it, not from what we meant to give it

A document search system does not know which version is the real one. It only sees the text most similar to the question. If old versions, drafts and copies sit in the same set, every one of them can be picked to answer. Once personal data has entered the index, removing it from the answer is not enough, because it stays in the index and may also be in the system's logs.

Consider three hypothetical situations. They are not BT San customer projects.

  • An electrical equipment trader: the sales chatbot answers prices from last year's price file, which is still in the same folder. A salesperson quotes a customer the wrong price without knowing it.
  • A mid-sized factory: there are three slightly different versions of the goods-receiving SOP, and nobody knows which one is approved. The bot switches between versions from day to day.
  • An accounting office: the employee contacts folder has ID numbers and bank account numbers mixed in. It was ingested together with the general manuals, and every employee who uses the bot is able to ask about them.

All three are fixed at the same layer: before ingestion. You need a document list that says who owns each document, which version is in use, who may read it, and whether it contains personal data. Code can check almost all of this. What remains is a human decision, which the script raises for a person to resolve.

What the references confirm, and what this example chose itself

TopicWhat the document saysEffect on our code
Mask before processingOWASP LLM02 (2025) recommends data sanitization so that user data does not enter the model, and using pattern matching to detect and mask confidential content before processingpii.ts masks the data before the file reaches the ingest folder
Limit access to what is neededThe same OWASP document states the principle of least privilege and says to restrict the model's access to external data sourcesEvery file must have an access value in the manifest; no value means fail
Data provenanceNIST AI 600-1 recommends recording data provenance, such as source, signatures and versions, in the GAI system inventoryThe manifest stores doc_id, owner, effective and hash for every file
Personal data riskNIST AI 600-1 lists Data Privacy as a risk: leakage or unauthorized use of personal dataCount the personal data items per file and keep them in the report
Collect only what is necessaryThe Personal Data Protection Act B.E. 2562 (2019) (English translation by the PDPC), Section 22, says collection must be limited to what is necessary for a lawful purpose, and Section 23 requires the data subject to be informed of details at the time of collectionThe reason we chose masking over ingesting whole files. Whether your company may do this is a question for a legal advisor
Shingle and JaccardWikipedia (W-shingling) explains that a shingle is a contiguous subsequence of tokens in a document, used to measure similarity between documents, and that resemblance is the ratio of the shared part to the combined set of shingles, which equals the Jaccard coefficientsimilarity.ts uses character 5-grams instead of words, because Thai is written without spaces
Summary of documents read on 2026-11-21. Read the full text of the PDPA and consult an expert for details. This is not legal advice.

Not taken from these references: the Jaccard threshold of 0.75, the document header format (doc_id, owner, access, effective, expires), the latest-version rule, and the checksum formula for the national ID number (the Wikipedia page we read says only that the 13th digit is a checksum and gives no formula). All of these are this example's proposals and must be adapted to your company.

Overview of the example

The code is in the examples/prepare-company-documents-for-ai/ folder. It uses only Node 24 built-ins, with no npm install and no network. TypeScript runs directly with node file.ts (Node strips the types without type checking, does not support enums or namespaces that need code generation, and, per the Node documentation, requires the .ts extension in import statements).

FileRole
docs/12 fictional documents with deliberately bad files: an old version, an exact copy, a lightly edited copy, an expired price, a missing owner, two conflicting versions, and a file containing personal data
frontmatter.tsReads the document header and checks that it is complete
similarity.tsContent hash, shingles and Jaccard
pii.tsDetects and masks personal data, with an ID number checksum
scan.tsDecides file by file, following the rules in order
report.ts / demo.tsA human-readable report, and a script that writes manifest.json and the ingest folder
readiness.test.tsA node:test suite with 6 cases

Here is one sample file. The top part between the dashed lines is the header the team must fill in. The bottom part is the content.

hr-leave-v2.md
---
doc_id: HR-01
owner: ฝ่ายบุคคล
access: internal
effective: 2026-03-01
---
# นโยบายการลา (ฉบับ 2026)
ลาพักร้อน
พนักงานที่ทำงานครบ 1 ปี มีสิทธิลาพักร้อนปีละ 12 วันทำการ ต้องยื่นขอล่วงหน้าอย่างน้อย 3 วันทำการผ่านระบบ HR
ลาป่วยได้ไม่เกิน 30 วันทำการต่อปี ลาเกิน 2 วันติดต่อกันต้องแนบใบรับรองแพทย์
docs/hr-leave-v2.md: the four required header fields (expires is optional)

Step 1: the header: who owns it, who can read it, since when it applies

If a document has no owner, nobody can say whether it is still correct. If it has no access value, nobody knows who should see it. If it has no effective date, its versions cannot be ordered. So checkMeta returns a list of problems and holds back every incomplete file.

frontmatter.ts · lines 15–27
export const ACCESS_LEVELS = ["public", "internal", "hr-only", "finance-only"];
export const REQUIRED = ["doc_id", "owner", "access", "effective"];

/** คืนรายการปัญหาของหัวเอกสาร (ว่าง = ใช้ได้) */
export function checkMeta(meta: Meta): string[] {
  const problems: string[] = [];
  for (const k of REQUIRED) if (!meta[k]) problems.push(`ไม่มี ${k}`);
  if (meta.access && !ACCESS_LEVELS.includes(meta.access)) problems.push(`access ไม่รู้จัก: ${meta.access}`);
  for (const k of ["effective", "expires"]) {
    if (meta[k] && !/^\d{4}-\d{2}-\d{2}$/.test(meta[k])) problems.push(`${k} ต้องเป็น YYYY-MM-DD`);
  }
  return problems;
}
frontmatter.ts checks that the required fields are present, the access value is in the list, and dates are YYYY-MM-DD

Storing dates as YYYY-MM-DD means they can be compared directly as strings, with no date conversion. Agree on Gregorian years as well, because mixing in Buddhist-era years breaks the ordering in a way nobody notices.

Step 2: exact duplicates and near-duplicates

Files that differ only in line breaks should count as the same content, so we strip whitespace and lowercase the text before hashing. For files edited by a few words, a hash does not help. We measure similarity with shingles: cut the text into 5-character windows that overlap by one character, then see how many windows the two files share (Jaccard).

similarity.ts · lines 4–25
export function normalize(text: string): string {
  return text.normalize("NFC").toLowerCase().replace(/\s+/g, "");
}

export function contentHash(text: string): string {
  return createHash("sha256").update(normalize(text)).digest("hex").slice(0, 16);
}

// ภาษาไทยไม่มีเว้นวรรคระหว่างคำ จึงใช้ n-gram ของตัวอักษรแทนการตัดคำ
export function shingles(text: string, n = 5): Set<string> {
  const t = [...normalize(text)];
  const out = new Set<string>();
  for (let i = 0; i + n <= t.length; i++) out.add(t.slice(i, i + n).join(""));
  return out;
}

export function jaccard(a: Set<string>, b: Set<string>): number {
  if (a.size === 0 && b.size === 0) return 1;
  let inter = 0;
  for (const s of a) if (b.has(s)) inter++;
  return inter / (a.size + b.size - inter);
}
similarity.ts: normalize, hash, shingle and Jaccard
  • Why not segment Thai words: word segmentation needs a dictionary and gives different results in different libraries. Character n-grams do not need to know what a word is, and they catch lightly edited text well.
  • The size of n: if it is too small (2-3 characters), unrelated files share many windows. If it is too large, changing a single word breaks many windows and the score drops fast. The value 5 is an experimental value for this example.
  • Comparing every pair of texts is fine for a few hundred documents. For tens of thousands or more, use MinHash or locality-sensitive hashing so that you do not compare every pair.

One thing to know: the old and new versions of the same policy (hr-leave-v1 and v2) score 0.90, higher than the lightly edited copy, which scores 0.77. So similarity cannot tell you which file is newer. It only says a person should look. Choosing the version needs doc_id and the effective date, which is the next step.

Step 3: several versions of one document: the latest wins, conflicts go to a person

Files with the same doc_id are the same document in different versions. The rule is: the version with the latest effective date that is already in force wins. A version whose effective date has not arrived is held back for now. If two versions have the same effective date but different content, we cannot know which is right, so we hold both back and report a conflict.

scan.ts · lines 23–53
  // ลำดับเลือกไฟล์ที่จะ "เก็บ" เมื่อซ้ำ: ชื่อสั้นก่อน (ชื่อที่มี copy, final2 มักยาวกว่า) แล้วตามตัวอักษร
  const byName = (a: Entry, b: Entry) => a.file.length - b.file.length || a.file.localeCompare(b.file);
  const live = () => entries.filter((e) => e.status !== "blocked").sort(byName);

  // 1 หัวเอกสารไม่ครบ  2 หมดอายุ
  for (const e of entries) {
    const p = checkMeta(e.meta);
    if (p.length) block(e, "หัวเอกสาร: " + p.join(", "));
    else if (e.meta.expires && e.meta.expires < opts.asOf) block(e, `หมดอายุ ${e.meta.expires}`);
  }
  // 3 ไฟล์ซ้ำเป๊ะ: เก็บไฟล์ที่ชื่อมาก่อน
  const seen = new Map<string, string>();
  for (const e of live()) {
    const first = seen.get(e.hash);
    if (first) block(e, `ซ้ำเนื้อหาเดียวกับ ${first}`);
    else seen.set(e.hash, e.file);
  }
  // 4 หลายฉบับของ doc_id เดียวกัน: ฉบับ effective ล่าสุดที่เริ่มใช้แล้วชนะ
  const groups = new Map<string, Entry[]>();
  for (const e of live()) groups.set(e.meta.doc_id, [...(groups.get(e.meta.doc_id) ?? []), e]);
  for (const [id, g] of groups) {
    const inForce = g.filter((e) => e.meta.effective <= opts.asOf);
    for (const e of g) if (!inForce.includes(e)) block(e, `ยังไม่ถึงวันเริ่มใช้ ${e.meta.effective}`);
    if (inForce.length < 2) continue;
    const top = inForce.map((e) => e.meta.effective).sort().at(-1)!;
    const latest = inForce.filter((e) => e.meta.effective === top);
    for (const e of inForce) {
      if (latest.length > 1) { if (latest.includes(e)) block(e, `ขัดแย้ง: ${id} มี ${latest.length} ฉบับวันเริ่มใช้เท่ากัน ${top}`); else block(e, `ถูกแทนที่โดย ${id} ฉบับ ${top}`); }
      else if (e !== latest[0]) block(e, `ถูกแทนที่โดย ${latest[0].file}`);
    }
  }
scan.ts: the header step, expiry, exact duplicates, and grouping by doc_id

Note that the rules run in order, and each step looks only at files not yet held back. So an expired file does not compete to be the latest version. When two exact copies duplicate each other, the byName function keeps the file with the shorter name (names like copy or final2 tend to be longer). This is only an assumption that gives a stable result. In real use the document owner should choose.

scan.ts · lines 54–63
  // 5 ใกล้เคียงกัน (doc_id ต่างกัน) เก็บไฟล์ที่ชื่อมาก่อน ที่เหลือให้คนตัดสิน
  const kept: Entry[] = [];
  for (const e of live()) {
    const s = shingles(body.get(e.file)!);
    const twin = kept.find((k) => jaccard(s, shingles(body.get(k.file)!)) >= opts.nearThreshold);
    if (twin) {
      const j = jaccard(s, shingles(body.get(twin.file)!));
      block(e, `คล้าย ${twin.file} (Jaccard ${j.toFixed(2)}) ให้คนเลือกฉบับเดียว`);
    } else kept.push(e);
  }
scan.ts: near-duplicate files with different doc_id; keep one file and let a person decide the rest

Step 4: personal data: detect, count and mask

A Thai national ID number has 13 digits, and the last digit is a check digit. The example uses the common formula: multiply the first 12 digits by 13 down to 2 and add them up, take the remainder after dividing by 11, then take (11 minus the remainder) modulo 10. The result must equal the 13th digit. The benefit is that most 13-digit numbers that are parcel or product codes fail the check, so they are not masked by mistake.

pii.ts · lines 3–16
/** เลขบัตรประชาชนไทย 13 หลัก: หลักที่ 13 = (11 - (sum(d[i]*(13-i)) mod 11)) mod 10 */
export function thaiIdValid(id: string): boolean {
  if (!/^\d{13}$/.test(id)) return false;
  let sum = 0;
  for (let i = 0; i < 12; i++) sum += Number(id[i]) * (13 - i);
  return (11 - (sum % 11)) % 10 === Number(id[12]);
}

/** สร้างเลขสมมติที่ checksum ถูกต้องจาก 12 หลักแรก (ใช้ในข้อมูลทดลองและเทสต์) */
export function makeThaiId(first12: string): string {
  let sum = 0;
  for (let i = 0; i < 12; i++) sum += Number(first12[i]) * (13 - i);
  return first12 + String((11 - (sum % 11)) % 10);
}
pii.ts: thaiIdValid checks the checksum, and makeThaiId creates fictional numbers for test data

The ID numbers in the sample files come from makeThaiId and start with 19999, so they are not real people's numbers. Masking runs in order: ID numbers first, then emails, phone numbers and account numbers. If the phone or account detector sees a 13-digit ID number first, it may cut it into the wrong pieces.

pii.ts · lines 21–38
const ID_RE = /\b(\d)[- ]?(\d{4})[- ]?(\d{5})[- ]?(\d{2})[- ]?(\d)\b/g;
const EMAIL_RE = /[\w.+-]+@[\w-]+(?:\.[\w-]+)+/g;
const PHONE_RE = /(?<!\d)(?:0[689]\d[- ]?\d{3}[- ]?\d{4}|0[2-7]\d?[- ]?\d{3}[- ]?\d{3,4})(?!\d)/g;
const BANK_RE = /(?<!\d)\d{3}[- ]\d[- ]\d{5}[- ]\d(?!\d)|(?<!\d)\d{10}(?!\d)/g;

export function redact(text: string): PiiResult {
  const counts: Record<PiiKind, number> = { thai_id: 0, phone: 0, email: 0, bank_account: 0 };
  let invalidId = 0;
  let out = text.replace(ID_RE, (m) => {
    if (thaiIdValid(m.replace(/\D/g, ""))) { counts.thai_id++; return "[THAI_ID]"; }
    invalidId++; // checksum ไม่ผ่าน: อาจเป็นรหัสอื่น ไม่ปิดบังแต่ให้คนตรวจ
    return m;
  });
  out = out.replace(EMAIL_RE, () => { counts.email++; return "[EMAIL]"; });
  out = out.replace(PHONE_RE, () => { counts.phone++; return "[PHONE]"; });
  out = out.replace(BANK_RE, () => { counts.bank_account++; return "[BANK_ACCOUNT]"; });
  return { text: out, counts, invalidId };
}
pii.ts: redact masks four types and counts them; a 13-digit number that fails the checksum is not masked but is counted separately

Why a number that fails the checksum is not masked: if we masked every 13-digit number, documents that contain product codes would lose content. But if we told nobody, we might miss an ID number with a single mistyped digit. So the example counts these as "for a person to check". This is a choice between two risks. A business with very sensitive data may choose to mask all of them.

scan.ts · lines 64–73
  // 6 ข้อมูลส่วนบุคคล: ปิดบังแล้วจึงนำเข้าได้
  for (const e of live()) {
    const r = redact(body.get(e.file)!);
    e.pii = r.counts; e.invalidId = r.invalidId;
    if (totalPii(r.counts) > 0 || r.invalidId > 0) {
      e.status = "redact"; e.redactedText = r.text;
      e.reasons.push(`พบข้อมูลส่วนบุคคล ${totalPii(r.counts)} จุด ปิดบังก่อนนำเข้า`);
      if (r.invalidId) e.reasons.push(`เลข 13 หลักที่ checksum ไม่ผ่าน ${r.invalidId} จุด ให้คนตรวจ`);
    }
  }
scan.ts: a file with personal data gets the redact status, and the masked version is kept

A real run: twelve files, seven held back

demo.ts scans the docs folder with the check date fixed at 2026-11-21 so that results are repeatable. It writes out/manifest.json and out/ingest/, then prints the report.

demo.ts · lines 9–23
const entries = scanDocs(loadDir(`${here}/docs`), { asOf: AS_OF, nearThreshold: 0.75 });

rmSync(out, { recursive: true, force: true });
mkdirSync(`${out}/ingest`, { recursive: true });
for (const e of entries) {
  if (e.status === "ready") copyFileSync(`${here}/docs/${e.file}`, `${out}/ingest/${e.file}`);
  // ไฟล์ที่ปิดบังข้อมูลแล้ว: เขียนฉบับที่ปิดบังลง ingest ไม่แตะต้นฉบับ
  if (e.status === "redact") writeFileSync(`${out}/ingest/${e.file}`, e.redactedText!);
}
const manifest = entries.map(({ redactedText, ...m }) => m);
writeFileSync(`${out}/manifest.json`, JSON.stringify({ asOf: AS_OF, summary: summary(entries), files: manifest }, null, 2));

console.log(renderReport(entries, AS_OF));
console.log("\nฉบับที่ปิดบังแล้วของ contacts-hr.md:");
console.log(entries.find((e) => e.file === "contacts-hr.md")!.redactedText!.split("\n").slice(-4).join("\n"));
demo.ts: scan, write the manifest, send ready files to ingest, and print the report
output.txt
รายงานความพร้อมของเอกสาร (ณ 2026-11-21)
ไฟล์ทั้งหมด 12  พร้อมนำเข้า 4  นำเข้าหลังปิดบังข้อมูล 1  ถูกกันไว้ 7

REDACT contacts-hr.md  [hr-only] เจ้าของ: ฝ่ายบุคคล
         - พบข้อมูลส่วนบุคคล 8 จุด ปิดบังก่อนนำเข้า
         - เลข 13 หลักที่ checksum ไม่ผ่าน 1 จุด ให้คนตรวจ
         - ปิดบังแล้ว: thai_id=2 phone=2 email=2 bank_account=2
BLOCK  hr-leave-v1.md  [internal] เจ้าของ: ฝ่ายบุคคล
         - ถูกแทนที่โดย hr-leave-v2.md
BLOCK  hr-leave-v2-copy.md  [internal] เจ้าของ: ฝ่ายบุคคล
         - ซ้ำเนื้อหาเดียวกับ hr-leave-v2.md
BLOCK  hr-leave-v2-edited.md  [internal] เจ้าของ: ฝ่ายบุคคล
         - คล้าย hr-leave-v2.md (Jaccard 0.77) ให้คนเลือกฉบับเดียว
READY  hr-leave-v2.md  [internal] เจ้าของ: ฝ่ายบุคคล
BLOCK  policy-security-a.md  [internal] เจ้าของ: ฝ่ายไอที
         - ขัดแย้ง: SEC-01 มี 2 ฉบับวันเริ่มใช้เท่ากัน 2026-06-01
BLOCK  policy-security-b.md  [internal] เจ้าของ: ฝ่ายไอที
         - ขัดแย้ง: SEC-01 มี 2 ฉบับวันเริ่มใช้เท่ากัน 2026-06-01
BLOCK  price-2025.md  [internal] เจ้าของ: ฝ่ายขาย
         - หมดอายุ 2025-12-31
READY  price-2026.md  [internal] เจ้าของ: ฝ่ายขาย
BLOCK  sop-no-owner.md  [-] เจ้าของ: (ไม่มี)
         - หัวเอกสาร: ไม่มี doc_id, ไม่มี owner, ไม่มี access, ไม่มี effective
READY  sop-warehouse-en.md  [internal] เจ้าของ: Warehouse Team
READY  sop-warranty-claim.md  [public] เจ้าของ: ฝ่ายบริการลูกค้า

ต้องแก้ก่อนนำเข้า 7 ไฟล์:
  hr-leave-v1.md: ถูกแทนที่โดย hr-leave-v2.md
  hr-leave-v2-copy.md: ซ้ำเนื้อหาเดียวกับ hr-leave-v2.md
  hr-leave-v2-edited.md: คล้าย hr-leave-v2.md (Jaccard 0.77) ให้คนเลือกฉบับเดียว
  policy-security-a.md: ขัดแย้ง: SEC-01 มี 2 ฉบับวันเริ่มใช้เท่ากัน 2026-06-01
  policy-security-b.md: ขัดแย้ง: SEC-01 มี 2 ฉบับวันเริ่มใช้เท่ากัน 2026-06-01
  price-2025.md: หมดอายุ 2025-12-31
  sop-no-owner.md: หัวเอกสาร: ไม่มี doc_id, ไม่มี owner, ไม่มี access, ไม่มี effective

ฉบับที่ปิดบังแล้วของ contacts-hr.md:
สมชาย ตัวอย่าง เลขบัตรประชาชน [THAI_ID] โทร [PHONE] อีเมล [EMAIL] บัญชีเงินเดือน [BANK_ACCOUNT]
สมหญิง ทดลอง เลขบัตรประชาชน [THAI_ID] โทร [PHONE] อีเมล [EMAIL] บัญชี [BANK_ACCOUNT]
รหัสพนักงานเก่า 1-9999-00002-34-5 (ตรวจ checksum ไม่ผ่าน ไม่ใช่เลขบัตร)
Actual output, run on 2026-11-21 with node demo.ts (Node 24)

Reading the results one item at a time:

  1. The summary at the top: 12 files, 4 ready to ingest as they are, 1 to ingest after masking, 7 held back. So more than half of a set that "looked ready" was held back.
  2. contacts-hr.md gets the REDACT status: it contains 2 ID numbers, 2 phone numbers, 2 emails and 2 account numbers, all masked. The third 13-digit number failed the checksum, so it was left as is and flagged for a person to look at. The file stays hr-only in its header.
  3. hr-leave-v1.md was replaced by v2. hr-leave-v2-copy.md is an exact copy of v2, and hr-leave-v2-edited.md is similar to v2 at 0.77. All three were held back, leaving only v2.
  4. price-2025.md expired on 2025-12-31, so it was held back even though it is the only 2025 version. price-2026.md passes.
  5. policy-security-a and b share the same doc_id and the same effective date, but one requires a 12-character password and the other 8. The script does not guess. It holds both back, and IT must decide.
  6. sop-no-owner.md is missing doc_id, owner, access and effective, so it was held back at the first step.
  7. The end of the report has a "must fix before ingest" list of 7 files, each with the reason on its first line. Each owner can see what to do. manifest.json holds the same information in a machine-readable form.

So the out/ingest/ folder holds 5 files: the 4 ready ones, plus the masked version of contacts-hr.md. The original in docs is not modified. The rest wait for owners to fix them from the list.

Test suite

readiness.test.ts has 6 cases and runs with node --test readiness.test.ts. It covers the checksum (valid, invalid, and numbers made by makeThaiId), masking of the four types with an invalid 13-digit number left unmasked, shingles that ignore whitespace, header checks, the latest-version rule, expiry, exact duplicates, conflicts, and the masked version containing no real numbers. The tests build documents in memory and do not depend on the docs folder, so they do not break when someone edits the sample files.

Before using it in a real company

  • Scanned files and image PDFs: this script reads text only. Scanned files must go through OCR first, and Thai OCR output can contain wrong characters, which throw off the ID-number regex and the shingles. Spot-check by eye, and keep the original file together with the extracted text.
  • Tables and images in documents: text inside images is not checked, so personal data in a photo of an ID card can slip through. You need a separate check step.
  • Storage and permissions: if the files are on a file share or Drive with per-folder permissions, the access value in the header must match the real permissions, and the index must filter by access at search time, not only at ingest. This connects to our article on access control and prompt injection.
  • PDPA: if you need to bring documents with personal data into the system, look at the lawful basis and at informing the data subjects under Sections 22 and 23. Masking with a regex does not make data anonymous automatically, because names and context can still identify a person. Have your legal team or an advisor review the policy. This is not legal advice.
  • Re-run when documents change: store the hash in the manifest and compare it with the previous run. A file whose hash changed must be checked again and re-ingested. A file that has disappeared must be removed from the index, otherwise a retired document can still be found. Run it on a schedule too, because a file that passes today may expire tomorrow.
  • All thresholds are experimental: try about 50 real documents, and have the owners look at every file that was held back and every file that passed, to tune the Jaccard threshold and the types of personal data.

Hypothetical examples: adapting it to three businesses

A trader whose prices change every quarter

Put expires in every price file and run the check every night. When a version expires, the system removes it from the index by itself and sends the file name to the sales team. This is better than letting the bot answer old prices with nobody knowing.

A factory with several SOP versions

Tie doc_id to the SOP numbers of your existing quality system, and set effective equal to the approval date. The conflict report will point out two versions that both claim to be current. This is usually a problem in the approval process more than a problem with AI.

An office that keeps personnel documents

Separate the personnel documents from the general manuals from the start. Use hr-only for access and ingest them into an index that is separated by permission, not the same index that all employees search. Masking is the last line of defense, not a substitute for separating access.

Common mistakes, and a checklist

  • Using file names to indicate version, such as final2 or latest, and letting the script guess. Put the effective date in the header.
  • Treating similar files as duplicates and deleting them automatically. Old and new versions are very similar. A person must confirm any deletion.
  • Masking the data but keeping the original in the same folder the system reads. The original must be outside the scope of the ingest system.
  • Checking only ID numbers and forgetting account numbers, phone numbers, emails and free-text data such as addresses, names and health results, which a regex cannot catch.
  • Checking once at the start of the project and never again. Documents change every week.
  • Letting a file with no owner pass because it is "used often". No owner means nobody is responsible when the answer is wrong.
  1. List the document groups and their owners, then fill in the header fields doc_id, owner, access and effective for every file.
  2. Set expiry dates for documents that change over time, such as prices and promotions.
  3. Run the script, read the must-fix list, and have the document owners decide on every file that is duplicate, similar or conflicting.
  4. Review the personal data report and decide which files to mask and which should not enter the system at all.
  5. Set access in the index to match the header, and test with a user who has no permission.
  6. Ingest only the ingest folder, then test with the question set from the chatbot evaluation checklist.
  7. Set a schedule for re-runs, and decide who receives the report each time.

Cautions for this example: a regex catches only the patterns written for it. It does not catch names, addresses or data in images. It does not read PDF or Word files and does no OCR. Comparing every pair of files is not suitable for tens of thousands of files. There is no approval system or record of who decided what. All the data is made up. Use it as a learning model, not as a legal compliance tool.

References

  1. OWASP Top 10 for LLM Applications 2025: LLM02 Sensitive Information Disclosure (accessed 2026-11-21)
  2. NIST AI 600-1: Generative AI Profile (accessed 2026-11-21)
  3. PDPC: Personal Data Protection Act B.E. 2562 (English translation) มาตรา 22 และ 23 (accessed 2026-11-21)
  4. Wikipedia: W-shingling (accessed 2026-11-21)
  5. Wikipedia: Thai identity card (โครงสร้างเลข 13 หลัก ใช้ยืนยันเรื่องหลักตรวจสอบเท่านั้น ไม่ใช่สูตร) (accessed 2026-11-21)
  6. Node.js: TypeScript (type stripping) (accessed 2026-11-21)

Add us on LINE

Scan with the LINE app on your phone

QR code to add LINE @Bankoos

LINE ID: @Bankoos

Open LINE on this computer