AI Application Engineer: Building PII-Scrubbed Synthetic Datasets & Domain-Specific LLM Fine-Tuning Pipelines
Fine-tuning a domain-specific language model or building a golden evaluation benchmark from raw production support tickets, clinical notes, or financial transcripts carries a major compliance risk: if raw customer names, credit card numbers, SSNs, or API tokens remain in the training corpus, the fine-tuned model can memorize and regurgitate that PII to other users. As an AI Application Engineer and Backend Engineer, I build deterministic + NER PII redaction and synthetic data generation pipelines for supervised fine-tuning (SFT) and Direct Preference Optimization (DPO) on Google Cloud Vertex AI.
1. Format-Preserving PII Pseudonymization Before SFT / Evaluation Export
Replacing every entity with a generic [REDACTED] token destroys coreference resolution in multi-turn conversations (because the model can no longer tell whether two turns refer to the same customer or two different people). Instead, we use HMAC-keyed deterministic pseudonymization (`
import hashlib
import hmac
import re
EMAIL_RE = re.compile(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}")
PHONE_RE = re.compile(r"(?:\+?\d{1,3}[\s-]?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}")
class DeterministicPseudonymizer:
def __init__(self, secret_salt: bytes) -> None:
self._salt = secret_salt
self._seen: dict[str, str] = {}
def _token_for(self, category: str, raw_val: str) -> str:
digest = hmac.new(self._salt, f"{category}:{raw_val.lower()}".encode("utf-8"), hashlib.sha256).hexdigest()[:8]
key = f"{category}:{digest}"
if key not in self._seen:
idx = sum(1 for k in self._seen if k.startswith(f"{category}:")) + 1
self._seen[key] = f"<{category}_{idx}>"
return self._seen[key]
def scrub_transcript(self, text: str) -> str:
text = EMAIL_RE.sub(lambda m: self._token_for("EMAIL", m.group(0)), text)
text = PHONE_RE.sub(lambda m: self._token_for("PHONE", m.group(0)), text)
return text
2. Teacher-Student Synthetic Data Distillation & Judge Filtering
Once historical edge cases are pseudonymized, we use a frontier teacher model (`gemini-2.5-pro`) to synthesize diverse hard-negative and schema-constrained JSON training examples, filter out low-quality generations via an automated LLM-as-a-Judge rubric (Ragas & DeepEval Quality Gates), and fine-tune fast, low-cost student models on Google Cloud Vertex AI.
Need an AI Application Engineer to build PII-safe synthetic data and LLM fine-tuning pipelines? Book a 1-Day Engineering Sprint.