HomeRoadmapsSynthetic Day 2
Synthetic Test Data Track Β· Day 2 Β· 20 min

PII Detection & Format-Preserving Tokenization
Synthetic Test Data Sprint β€” Day 2

Detect sensitive personal identifiers in JSON payloads, generate valid Luhn check credit cards, and execute deterministic HMAC pseudonymization.

πŸ” Security: Salted HMAC + Luhn ValidπŸ›‘οΈ Synthetic Data & Privacy Quality Architect
PII MaskingLuhn AlgorithmHMAC-SHA256PseudonymizationHIPAA / GDPR
About this lab

Copying real customer data into test databases violates GDPR, HIPAA, and PCI-DSS. However, naive masking (like replacing emails with dummy@dummy.com) breaks relational foreign keys and API validations. Today you build format-preserving tokens and deterministic HMAC pseudonymization.

πŸ“¦Sample Codebase & Working Solution (Day 2)Available Now
View on GitHub

The official reference codebase for Day 2 is hosted in the repository. Clone the repository and navigate to day-2-pii-tokenization to run the working solution.

Git Clone β€” Working Solution
git clone https://github.com/777abhi/synthetic-test-data-roadmap.git
cd synthetic-test-data-roadmap/day-2-pii-tokenization
🏭Production Context & Enterprise Implementation
πŸ’‘ Why We Are Doing This: Downstream services require valid formatting (e.g. valid credit card Luhn check digits and domain formatting) and referential equality across tables without exposing raw personal data.
🏒 Real-World Production Usecase: Sanitizing database snapshots into non-production staging environments while retaining join consistency across customer, order, and billing tables.
βš™οΈ How Implemented in Production: Salted HMAC-SHA256 tokenization and Luhn algorithm generators in synthlab/pii_tokenizer.py.
Phase 1

Inspect PII Tokenization

Review regex pattern scanning, Luhn checksum verification, and salted HMAC surrogate tokens.

Step 2.1: Inspect PII Tokenizer Engine
Terminal β€” View Tokenizer Code
cat synthlab/pii_tokenizer.py | head -50
Step 2.2: PII Masking Unit Tests
test_day2.py
import unittest
from synthlab.pii_tokenizer import PIIScanner, PIITokenizer, LuhnValidator

class TestDay2PIITokenization(unittest.TestCase):
    def setUp(self):
        self.tokenizer = PIITokenizer(salt="qe-test-salt-2026")

    def test_luhn_credit_card_generation_and_validation(self):
        card = LuhnValidator.generate_valid_card(prefix="4111", length=16)
        self.assertTrue(LuhnValidator.is_valid(card))

    def test_deterministic_pseudonymization_preserves_referential_equality(self):
        token_1 = self.tokenizer.tokenize_email("alice@example.com")
        token_2 = self.tokenizer.tokenize_email("alice@example.com")
        self.assertEqual(token_1, token_2)
Phase 2

Execute Day 2 Tests

Run the PII and Luhn verification tests.

Step 2.3: Run Test Suite
Terminal β€” Run Day 2 Tests
npm run test:day2
Day 2 Key Learnings
  • Implemented the Luhn algorithm (Mod 10) to generate mathematically valid test credit cards.
  • Used salted HMAC-SHA256 for deterministic pseudonymization: same customer produces identical surrogate tokens.
  • Deep masked nested dictionary payloads while preserving RFC-compliant email and SSN formats.

🧠 Knowledge Check

Why is deterministic pseudonymization preferred over random string replacement for test fixtures?