Skip to main content

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, or ADDRESS_FULL
  • Pluggable LLM providers — Ollama (local), OpenAI, Claude, HuggingFace
  • Pluggable semantic providers — local sentence-transformers or 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 up to 4 stages (stops early if confident):

  1. Exact match — keyword list
  2. Fuzzy matchrapidfuzz ratio / partial_ratio / token_sort_ratio
  3. Semantic — embedding cosine similarity
  4. LLM — prompt-based classification as final fallback

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thai_column_classifier-0.1.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thai_column_classifier-0.1.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file thai_column_classifier-0.1.0.tar.gz.

File metadata

  • Download URL: thai_column_classifier-0.1.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for thai_column_classifier-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f2e5a6eba84cbf42041dde23dde09c1f6a24c289c74d74a54bc1899436a63aa0
MD5 007dd69365000d47e4ac8692476e6d61
BLAKE2b-256 50a9403b5aa29d922d501376ee3a3052798ec08c449a9992954539fc7cd3ab34

See more details on using hashes here.

File details

Details for the file thai_column_classifier-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for thai_column_classifier-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba6f8ac1da04c15b42286ec01b14e9f459edaad71403282d3aa0f22362ce5251
MD5 cf7f10333ebe91dd12a5c0d70a410eea
BLAKE2b-256 245c7e409d2954cb3bbbc2721ba5943cbcd495608786ac469a1d1fb16edfd364

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page