Classify and detect sensitive columns in Thai datasets (CID, PDPA)
Project description
thai-column-classifier
A Python library for detecting and classifying sensitive columns in Thai datasets, designed to support PDPA (Personal Data Protection Act) compliance.
Features
- CID detection — identifies Thai national ID (
เลขบัตรประชาชน) columns via exact match, fuzzy match, semantic similarity, and value pattern (13-digit checksum) - Sensitive column detection — classifies columns as
FULLNAME,PREFIX,FIRSTNAME,LASTNAME,EMAIL,ADDRESS_SHORT, orADDRESS_FULL - Pluggable LLM providers — Ollama (local), OpenAI, Claude, HuggingFace
- Pluggable semantic providers — local
sentence-transformersor HuggingFace Inference API - Privacy-first by default — all inference runs locally out of the box (Ollama + sentence-transformers); no data sent to external APIs
Detection pipeline
Each column goes through stages in order, stopping early if confident enough.
CID detector (เลขบัตรประชาชน):
- Exact match — keyword list
- Fuzzy match —
rapidfuzzratio / partial_ratio / token_sort_ratio - Semantic — embedding cosine similarity
- Guardrail — 13-digit checksum pattern on sample values
Sensitive column detector:
- Exact match — keyword list per category
- Fuzzy match —
rapidfuzzratio / partial_ratio / token_sort_ratio - Semantic — embedding cosine similarity
- LLM — prompt-based classification as final fallback
- Guardrails — email pattern and full address pattern on sample values
Output decisions
| Detector | Decision | Meaning |
|---|---|---|
| CID | auto_hash |
Column is a Thai national ID — hash it |
| Sensitive | masking |
Mask the entire value (****) |
| Sensitive | partial_masking |
Mask street-level part only, keep district/province |
| Both | pass |
Not sensitive |
Supported input formats
The classifier operates on a pandas DataFrame — it is file-format agnostic. The load_file() helper in main.py supports:
| Format | Extensions |
|---|---|
| CSV | .csv |
| Excel | .xlsx, .xls |
To support additional formats (Parquet, JSON, database queries, etc.), you only need to extend load_file(). The classifier itself works unchanged as long as you pass it a DataFrame.
Installation
pip install thai-column-classifier
Install with optional providers:
pip install thai-column-classifier[ollama] # Ollama (local LLM)
pip install thai-column-classifier[semantic] # local sentence-transformers
pip install thai-column-classifier[openai] # OpenAI
pip install thai-column-classifier[claude] # Anthropic Claude
pip install thai-column-classifier[all] # everything
Quick start
from thai_column_classifier import IDColumnClassifier, IDColumnInput
from thai_column_classifier import SensitiveColumnClassifier, SensitiveColumnInput, OllamaProvider
# CID detector
cid_clf = IDColumnClassifier()
result = cid_clf.classify(IDColumnInput(
column_name="เลขบัตรประชาชน",
sample_values=["1101700203451"]
))
print(result.decision) # auto_hash
# Sensitive column detector — fully local by default (LocalSemanticProvider + OllamaProvider)
sensitive_clf = SensitiveColumnClassifier()
result = sensitive_clf.classify(SensitiveColumnInput(
column_name="ชื่อ-นามสกุล",
sample_values=["สมชาย ใจดี"]
))
print(result.decision) # masking
Environment variables
HF_TOKEN=hf_... # for HuggingFace providers
OPENAI_API_KEY=sk-... # for OpenAI provider
ANTHROPIC_API_KEY=... # for Claude provider
Running tests
python test_check_id.py
python test_check_sensitive.py
python main.py
Project structure
.
├── thai_column_classifier/
│ ├── __init__.py
│ ├── classifier.py # Unified ThaiColumnClassifier
│ ├── thai_id_column_detector.py # CID classifier
│ └── thai_sensitive_column_detector.py # Sensitive column classifier
├── data/ # Test datasets
├── pyproject.toml
├── main.py
├── test_check_id.py
└── test_check_sensitive.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file thai_column_classifier-0.1.1.tar.gz.
File metadata
- Download URL: thai_column_classifier-0.1.1.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45156ec59a66bf9992f305d761d59aab27eb5e06c6dffcc42f37601542af4931
|
|
| MD5 |
ec9fabf5bd01ff95ee8f5a74bc18da24
|
|
| BLAKE2b-256 |
4f5e7d929ccb5a94fb5708f0582318054058b04f8ad3a301a6a2635bfa70c1f5
|
File details
Details for the file thai_column_classifier-0.1.1-py3-none-any.whl.
File metadata
- Download URL: thai_column_classifier-0.1.1-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f45a79eb675072c4a349520366e85a5368a13fd4f287b066d2a7b07a4e06f9f1
|
|
| MD5 |
e86014432194bc5bac4454c60178a805
|
|
| BLAKE2b-256 |
21dce9ea3ccdd83f123bcb162db7a2cc77c3ca321aae1e4657860b9342646bc3
|