Skip to content

LMask

LLM에 계약서·이력서 같은 민감 문서를 보낼 때 개인정보가 그대로 외부 서버에 노출되는 문제를 해결하기 위해, 문서 내 PII(이름, 주민번호, 전화번호 등)를 자동 탐지하여 [[PII:NAME:3]] 같은 토큰으로 치환한 뒤 LLM에 전달하고, 응답에 포함된 토큰을 다시 원본으로 복원하여 사용자에게 돌려주는 시스템입니다.

Core trick

Regex, NER, and an LLM detect PII, swap it for numbered tokens, and restore originals after the response, with a Fernet-encrypted token map.

Tags

Description

LLM에 계약서·이력서 같은 민감 문서를 보낼 때 개인정보가 그대로 외부 서버에 노출되는 문제를 해결하기 위해, 문서 내 PII(이름, 주민번호, 전화번호 등)를 자동 탐지하여 [[PII:NAME:3]] 같은 토큰으로 치환한 뒤 LLM에 전달하고, 응답에 포함된 토큰을 다시 원본으로 복원하여 사용자에게 돌려주는 시스템입니다. Regex·NER·LLM을 결합한 하이브리드 탐지 파이프라인으로 정밀도를 높였고, 토큰 맵은 Fernet 암호화로 보호되며, "Show what LLM sees" 토글을 통해 LLM이 실제 개인정보를 전혀 보지 못했음을 시각적으로 증명할 수 있습니다.
minjcho/LLMredaction★ 00 forksPythonCreated Feb 28, 2026 · last push Feb 28, 2026

README excerpt

# LLM Redaction

**Automatically mask PII before it reaches the LLM — and restore it on the way back.**

When you send contracts, resumes, or other sensitive documents to an LLM, personally identifiable information (names, national IDs, phone numbers, etc.) is transmitted to external servers as-is. LLM Redaction solves this by automatically detecting PII, replacing it with tokens like `[[PII:NAME:3]]`, and forwarding only the masked text to the LLM. Tokens in the LLM response are then restored to their original values before reaching the user — so the user sees natural text while **the LLM never sees real personal data**. A hybrid detection pipeline (Regex + NER + LLM) maximizes precision, token maps are protected with Fernet encryption, and a "Show what LLM sees" toggle visually proves that no real PII was exposed.

## How It Works

```
Original Document → PII Detection → Token Replacement (Masking) → Send to LLM
                                                                       ↓
        User ← Original Restoration ← LLM Response (contains tokens)
```

1. **Upload** a document (TXT or PDF) — PII is detected and replaced with `[[PII:TYPE:id]]` tokens
2. **Chat** with the LLM about the masked document — the LLM only sees tokens, never real data
3. **Receive** a natural response — the server restores tokens to original values before returning
4. **Toggle** "Show what LLM sees" to verify the LLM never saw actual PII

## PII Detection Pipeline

The system uses a multi-stage 

Team