TL;DR
Large Language Models (LLMs) trained on public code repositories often inadvertently memorize sensitive personally identifiable information (PII) like API keys and emails. This paper introduces a novel, test-driven evaluation pipeline that bypasses LLM safety filters by prompting models to generate unit tests for realistic development scenarios. Supported by an automated privacy feature library, this approach uncovers up to 2.56 times more confirmed privacy leaks than existing state-of-the-art baselines.
What Problem Does This Paper Address?
When LLMs are trained on massive scrapes of public code repositories (like GitHub), they don't just learn syntax—they also memorize hardcoded secrets, personal emails, names, and medical records accidentally uploaded by developers. When these LLMs are later used for code generation, they can unintentionally reproduce this sensitive data.
Existing methods to detect these privacy leaks rely on manual or ad-hoc prompt engineering (e.g., directly asking the model for a secret key). However, these methods face two major hurdles:
- Safety Filters: Modern commercial LLMs are aligned to refuse direct requests for private data.
- Artificial Contexts: Simple prompts don't match the complex, real-world code structures where PII originally appeared, meaning the model's memorized associations aren't triggered, leading to generic placeholders (like
[email protected]or "John Doe") rather than actual leaks.
This paper addresses the challenge of realistically eliciting and verifying true memorized PII from black-box commercial LLMs without triggering their refusal mechanisms.
Methods
The authors propose a semi-automated, test-driven privacy auditing pipeline consisting of three main stages:
- Privacy-Related Question Construction: Instead of abstract queries, the pipeline maps specific privacy attributes to realistic software domains (e.g., enterprise apps, mobile services, blockchains). An LLM generates diverse, context-aware programming tasks that naturally require handling sensitive data fields.
- Indirect Probing via Test Generation: To bypass safety filters, the pipeline uses a two-turn interaction pattern. First, the target LLM generates a functional code snippet for the task. Second, it is prompted to write unit tests for that function. Because unit tests require concrete input arguments, the LLM is forced to materialize realistic data values, effectively bypassing standard safety guardrails.
- Privacy Feature Library (FL): To guide the model away from trivial placeholders, the authors introduce an automatically updated library containing structural templates ($\Lambda_{tmp}$) and realistic fragments ($\Lambda_{frag}$). They use a pretrained code model (CodeBERT) to compute token-wise pseudo-log-likelihood scores; tokens with low likelihood represent common code structures (templates), while high-dispersion tokens represent specific values (fragments). These are clustered using DBSCAN to filter out noise and provide realistic prompt augmentations.
Finally, candidate strings are passed through a Judge LLM to filter out obvious junk, verified against public GitHub repositories via API searches, and manually reviewed by humans to ensure authenticity.
Datasets
The pipeline was evaluated against five major commercial LLMs:
- OpenAI Series: GPT-4o, GPT-4.1, GPT-OSS
- DeepSeek Series: DeepSeek-V3, DeepSeek-R1
Because the exact training corpora of these commercial models are closed, the authors utilized public GitHub repositories as a proxy proxy to verify whether the extracted strings were genuine historical data or merely model hallucinations.
The privacy attributes targeted were divided into three distinct categories based on a refined taxonomy:
- Identifiable: Name, Address, Email, Phone Number, Date of Birth
- Private: Identity, Medical Record, Bank Statement, Political alignment
- Secret: Password, Authentication PIN/Token, Secret Key, Credit Card, Account/User Name, Biometric Data
Key Insights and Ideas
- The "Unit Test" Loophole: Safety alignment mechanisms are highly attuned to direct text requests ("What is the API key for X?") but struggle to recognize privacy risks when embedded in standard developer workflows like unit test generation.
- Context Triggers Memorization: LLM memorization is highly context-dependent. By mimicking the exact structural environments of real-world code bases, the pipeline successfully triggers the model's internal weights to complete the code using real data it observed during pretraining.
- Template vs. Fragment Separation: Using token-wise pseudo-log-likelihood from an independent model (CodeBERT) proves to be an effective, unbiased way to separate generic syntax boilerplate from high-risk, out-of-distribution privacy fragments.
Key Results
- Higher Detection Rates: The proposed pipeline consistently outperformed existing baselines (CodexLeaks and Codebreaker), achieving up to a 2.56x increase in confirmed privacy leak detection.
- Pervasive Leakage: Across all 5 commercial models, the pipeline uncovered an average of 92.6 fully confirmed privacy leakage instances. The GPT series demonstrated a leakage rate of 17.6‰, while the DeepSeek series sat at 13.3‰.
- Category Vulnerability: "Identifiable" data (like emails and names) was leaked at a significantly higher rate (24.64‰) than "Secret" data (11.78‰), reflecting the high density of these fields in open-source code repositories.
Limitations and Future Work
- Conservative Lower Bound: Because GitHub repositories are constantly modified or deleted, searching current GitHub code only provides a conservative lower bound of what the model actually encountered during its historical training phase.
- Scalability Bottleneck: While the Judge LLM filters out clear negatives, final verification still requires manual human review to rule out synthetic examples or documentation text, limiting fully automated, large-scale auditing.
- Scope: The evaluation was restricted to 5 model families and 8 specific code-task scenarios; future work is needed to explore how these vulnerabilities shift across different languages and deployment settings.
Summary updated