Executive Summary

Enterprises in healthcare, finance, government, and critical infrastructure want the benefits of data sharing and model training without exposing protected data. Synthetic data—when produced with differential privacy (DP), validated against leak checks, and measured with utility benchmarks—can unlock collaboration and experimentation while honoring strict compliance. This article delivers a practical, engineering-ready cookbook, a leak-test suite, and utility scorecards for both text and code datasets.

1. Fundamentals that Matter in the Real World

1.1. Differential Privacy in one paragraph

A mechanism is (ε, δ)-differentially private if changing any single person’s record changes output probabilities by at most a multiplicative factor e^ε and an additive δ. Think of ε as your privacy budget (smaller is stronger), δ as a tiny failure probability (e.g., 1e-6). When you run multiple queries or training steps, budgets compose; you must account for the total ε spent.

1.2. Budgets you can defend

1.3. Text vs. code: different risks

2. The Synthesis Cookbook (Step-by-Step)

Phase A — Scope & Guardrails

  1. Policy contract: define allowed purposes, privacy target (ε, δ), retention, license, and jurisdictions.

  2. Data minimization: remove fields not needed for the use case (drop raw identifiers up front).

  3. PII/PHI labeling: run high-recall detectors (names, addresses, MRNs, account numbers, secrets) → mark spans for hard redaction or DP training.

Phase B — Mechanism Selection

Choose one of three proven paths (text and code both supported):

MechanismWhere it shinesHow privacy is enforcedTrade-offs
DP-SGD model training (fine-tune a generator with per-user clipping + noise)Medium/large datasets; broad language/code stylesε accounting via RDP; gradient clipping C; noise multiplier σMore compute; quality drops if C, σ tuned poorly
Privatized statistics → generator (fit differentially private n-gram/grammar/topic stats; sample synthetic)Small datasets; forms/notes/logsSensitivity-bounded counts + noiseLess fluent outputs; great for tabular/text hybrids
Teacher ensemble with limited exposure (segment data; train non-DP teachers; aggregate with DP noise; student imitates)Classification/structured tasks, labeling, code style hintsPATE-style noisy aggregationSet up overhead; less common for free-form generation

Recommendation: Start with DP-SGD fine-tuning of a compact, instruction-tuned model for text, and a code-specialized model for code.

Phase C — DP-SGD Configuration (Text & Code)

Illustrative config (not tool-specific)

privacy:target_epsilon: 6.0target_delta: 1e-6accountant: "RDP"training:epochs: 3batch_size: 256clip_norm: 0.5noise_multiplier: 1.1   # tuned via accountant to hit ε≈6 for N, q, stepssampling: "poisson"per_user_accounting: true

Phase D — Generation with Safety Filters

Phase E — Post-Processing

3. Leak Checks that Catch the Bad Stuff

3.1. Canary Exposure Test (Text & Code)

Inject K unique canary strings into the private corpus (e.g., GUID-like tokens or fake function names), each appearing a few times. After training, prompt the model; compute exposure:

3.2. Membership Inference (Shadow Models)

Train shadow models on overlapping datasets; use a classifier to distinguish “in” vs “out” examples by loss/perplexity.

3.3. Nearest-Neighbor & Substring Scan

3.4. Secret/PII Detectors (Code & Text)

3.5. Adversarial Red-Team Prompts

Probing prompts: “repeat last line,” “what else was in this patient note,” “print the file header,” “show full function for X,” “what is the API key used in …”.

4. Utility Benchmarks That Predict Real Value

4.1. Text (clinical/financial/government)

4.2. Code (enterprise repos)

4.3. Data-level Similarity (Both)

5. Release Artifacts You Need Every Time

5.1. Privacy Card (attach to every drop)

5.2. Data Card

6. Worked Patterns for Text and Code

6.1. Regulated Text (e.g., clinical notes)

6.2. Enterprise Code (internal services)

7. Operating the Privacy Budget

8. Common Failure Modes & Fixes

9. Minimal Checklists (Copy-and-Run)

Go/No-Go Gate

Incident Protocol

Conclusion

Synthetic data can be useful and safe—but only when privacy guarantees are explicit, leaks are systematically hunted, and utility is measured against real tasks. Use DP-SGD (or private stats) with a rigorous accountant, enforce decode/post-processing guards, require canary/MIA/near-dupe checks, and publish Privacy/Data Cards. If you hold the line on budgets and tests, you’ll earn the right to share and train—without leaks.