Skip to content

huajielong/SensFinder

Repository files navigation

v1.0 MIT Python 3.8+ Stars LLM Support

๐Ÿ” SensFinder

LLM-Powered Sensitive Information Detection & Classification System

๐Ÿ›ก๏ธ Pre-masking Inspection ยท ๐Ÿ“‹ Data Leak Risk Assessment ยท โœ… Compliance Checking

๐Ÿš€ Quick Start โ€ข

๐Ÿ—๏ธ Architecture โ€ข

โšก Features โ€ข

๐Ÿ“Š Classification โ€ข

โš™๏ธ Config โ€ข

โ“ FAQ

ไธญๆ–‡่ฏดๆ˜Ž


๐Ÿค” Do You Really Know What Sensitive Data Is Hidden in Your Text?

Data masking and compliance checks are essential for every organization, but manually reviewing thousands of text fields is nearly impossible:

| Pain Points | SensFinder Solutions |

|:------------|:--------------------|

| โ“ Thousands of records โ€” manual review is impractical | โœ… Automated Detection โ€” LLM-powered batch processing, done in minutes |

| โ“ Names, places, companies mixed together, hard to classify | โœ… Smart Classification โ€” 6 precise categories with custom extension support |

| โ“ Switching between LLM providers is a hassle | โœ… Multi-Engine โ€” OpenAI / DeepSeek / Local models, one-click switch |

| โ“ Results need manual verification | โœ… Confidence Scoring โ€” Low-confidence fields auto-flagged for focused review |

| โ“ Batch processing can miss anomalies | โœ… Multi-Level Validation โ€” Rule conflict detection + low confidence filtering |

๐Ÿ”ฅ Use Cases

Pre-masking Data Inspection โ†’ Privacy Compliance Audit โ†’ Data Leak Risk Assessment โ†’ PII Discovery & Classification


๐Ÿš€ Quick Start

Prerequisites

| Dependency | Version |

|:-----------|:-------:|

| Python | 3.8+ |

| pandas | โ€” |

| openai | โ€” |

One-Click Install

# 1. Clone the repo

git clone https://github.com/huajielong/SensFinder.git

cd SensFinder



# 2. Create virtual environment & install deps

python -m venv venv

# Windows

venv\Scripts\activate

# macOS / Linux

# source venv/bin/activate



pip install -r requirements.txt

Configure LLM Service

Create a .env file (or modify config/config.py directly):

# Service selection: OPENAI / DEEPSEEK / LOCAL

LLM_SERVICE=DEEPSEEK



# DeepSeek Config

DEEPSEEK_API_KEY=sk-your-key

DEEPSEEK_BASE_URL=https://api.deepseek.com



# OpenAI Config

OPENAI_API_KEY=sk-your-key

OPENAI_BASE_URL=https://api.openai.com/v1



# Local LLM Config

LOCAL_LLM_URL=http://localhost:8000/v1/chat/completions

Run

python script/sens_finder.py

That's it. The program automatically runs: data preprocessing โ†’ LLM classification โ†’ result verification โ†’ report generation.


๐Ÿ—๏ธ System Architecture


โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

โ”‚                     โ”‚    โ”‚                     โ”‚    โ”‚                     โ”‚

โ”‚   Data Preprocess   โ”‚โ”€โ”€โ”€>โ”‚   LLM Classification โ”‚โ”€โ”€โ”€>โ”‚   Result Verify     โ”‚

โ”‚   data_preprocess   โ”‚    โ”‚   llm_classify      โ”‚    โ”‚   result_verify     โ”‚

โ”‚                     โ”‚    โ”‚                     โ”‚    โ”‚                     โ”‚

โ”‚  โ€ข Clean invalid    โ”‚    โ”‚  โ€ข Call LLM API     โ”‚    โ”‚  โ€ข Confidence score  โ”‚

โ”‚  โ€ข Batch sharding   โ”‚    โ”‚  โ€ข Smart tagging    โ”‚    โ”‚  โ€ข Conflict detect   โ”‚

โ”‚  โ€ข Dedup optimize   โ”‚    โ”‚  โ€ข Multi-thread     โ”‚    โ”‚  โ€ข Problem summary   โ”‚

โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

         โ”‚                          โ”‚                          โ”‚

         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

                                    โ–ผ

                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

                         โ”‚                     โ”‚

                         โ”‚      Output         โ”‚

                         โ”‚  โ€ข Results CSV      โ”‚

                         โ”‚  โ€ข Problem Report   โ”‚

                         โ”‚  โ€ข Detailed Log     โ”‚

                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Module Responsibilities

| Module | File | Core Responsibility |

|:-------|:-----|:--------------------|

| Main Control | script/sens_finder.py | Orchestrate full pipeline (preprocess โ†’ classify โ†’ verify) |

| Data Preprocess | script/data_preprocess.py | Clean, deduplicate, batch shard |

| LLM Classify | script/llm_classify.py | Call LLM to classify each field |

| Local LLM Client | script/local_llm_client.py | Support private/local model access |

| Result Verify | script/result_verify.py | Confidence scoring + conflict detection |

| Configuration | config/config.py | Centralized system and LLM config |


โšก Key Features

| Feature | Description |

|:--------|:------------|

| ๐Ÿค– Multi-LLM | OpenAI GPT, DeepSeek, local/private models, one-click switch |

| ๐Ÿ“ฆ Batch Processing | Auto-sharding for large text corpora (1000-2000 rows per batch) |

| ๐ŸŽฏ Smart Classification | Accurately identifies names, places, companies, organizations, products |

| โœ… Confidence Scoring | Each result scored; low confidence auto-flagged |

| ๐Ÿ” Result Validation | Rule conflict detection + low confidence filtering |

| โšก Parallel Processing | Multi-threaded for high throughput |

| ๐Ÿ“Š Structured Output | CSV format for easy review and integration |


๐Ÿ“Š Classification Standard

| Category | Examples |

|:---------|:---------|

| ๐Ÿ‘ค Person Name | John Smith, Zhang San, Li Si |

| ๐ŸŒ Place Name | London, California State, Beijing |

| ๐Ÿข Company Name | Apple Inc, Alibaba, Tencent |

| ๐Ÿ›๏ธ Organization | UN, WHO, World Health Organization |

| ๐Ÿ”ง Product/Tech | iPhone 15, GPT-4, TensorFlow |

| ๐Ÿ“ง Other PII | Email, phone number, date/time |


โš™๏ธ Configuration

Config file: config/config.py

LLM Config

CURRENT_LLM_SERVICE = "DEEPSEEK"  # OPENAI | DEEPSEEK | LOCAL

LLM_TEMPERATURE = 0.1             # Lower = more stable (0.1-0.3)

Preprocessing

BATCH_SIZE = 1000           # Rows per batch

MIN_FIELD_LENGTH = 2        # Minimum field length filter

Validation

LOW_CONFIDENCE_THRESHOLD = 80    # Below this โ†’ manual review

๐Ÿ“ Project Structure


SensFinder/

โ”œโ”€โ”€ config/                  # Configuration

โ”‚   โ”œโ”€โ”€ config.py            # Main config

โ”‚   โ””โ”€โ”€ prompt_template.txt  # LLM prompt template

โ”œโ”€โ”€ data/                    # Data directory

โ”‚   โ”œโ”€โ”€ input_raw/           # Raw input

โ”‚   โ”œโ”€โ”€ preprocessed_batches/ # Preprocessed batches

โ”‚   โ”œโ”€โ”€ classify_results/    # Classification results

โ”‚   โ””โ”€โ”€ verify_problems/     # Verification issues

โ”œโ”€โ”€ script/                  # Core scripts

โ”‚   โ”œโ”€โ”€ sens_finder.py       # Main entry point

โ”‚   โ”œโ”€โ”€ data_preprocess.py   # Data preprocessing

โ”‚   โ”œโ”€โ”€ llm_classify.py      # LLM classification

โ”‚   โ”œโ”€โ”€ local_llm_client.py  # Local LLM client

โ”‚   โ””โ”€โ”€ result_verify.py     # Result verification

โ”œโ”€โ”€ test/                    # Tests

โ”œโ”€โ”€ ไบงๅ“่ฎพ่ฎกPRD.md           # Product PRD (Chinese)

โ”œโ”€โ”€ ๆŠ€ๆœฏๅฎž็Žฐๆ–นๆกˆ.md          # Tech design doc (Chinese)

โ”œโ”€โ”€ requirements.txt         # Python dependencies

โ””โ”€โ”€ README.md                # ๐Ÿ’ก You are here

---



## โ“ FAQ



<details>

<summary><b>Which LLM providers are supported?</b></summary>

OpenAI (GPT-4o-mini/GPT-4o), DeepSeek (deepseek-chat), and any OpenAI-compatible local model (via Ollama/vLLM, etc.).

</details>



<details>

<summary><b>Processing is slow โ€” what can I do?</b></summary>

1. Increase `BATCH_SIZE` (watch context limits)<br>

2. Check LLM API response speed<br>

3. Use a faster model (e.g., GPT-4o-mini)<br>

4. Check network stability

</details>



<details>

<summary><b>How to improve classification accuracy?</b></summary>

1. Lower `LLM_TEMPERATURE` to ~0.1<br>

2. Use a more capable LLM<br>

3. Add more examples to `prompt_template.txt`<br>

4. Lower `LOW_CONFIDENCE_THRESHOLD` for wider review scope

</details>



<details>

<summary><b>How to use the results?</b></summary>

Output is CSV with field content, classification, confidence score, and reasoning. Use for: pre-masking field marking, compliance audit evidence, data leak risk assessment reports.

</details>



<details>

<summary><b>Is my API key safe?</b></summary>

API keys are configured via `.env` or `config.py`. The project includes `.gitignore` to prevent accidental key commits.

</details>



---



## ๐Ÿงช Development & Extension



### Add New Classification Types

1. Edit `config/prompt_template.txt` โ€” add definition and examples

2. Add corresponding validation rules in `result_verify.py`



### Add New LLM Service

1. Add config item in `config/config.py`

2. Add API call logic in `llm_classify.py`



### Testing

```bash

python test/test_sens_finder.py


๐Ÿค Contributing

Contributions of all forms are welcome โ€” issues, PRs, documentation improvements.

Contributions Welcome

๐Ÿ“„ License

MIT ยฉ huajielong


โญ Star SensFinder if it helps you protect your data!

About

๐Ÿ” ๅŸบไบŽLLM็š„ๆ™บ่ƒฝๆ•ๆ„Ÿไฟกๆฏ่ฏ†ๅˆซไธŽๅˆ†็ฑป็ณป็ปŸ โ€” ่‡ชๅŠจๆฃ€ๆต‹ไบบๅ/ๅœฐๅ/ๅ…ฌๅธๅ/็ป„็ป‡ๅ๏ผŒๆ”ฏๆŒOpenAI/DeepSeek/ๆœฌๅœฐๆจกๅž‹

Topics

Resources

License

Contributing

Security policy

Stars

5 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages