A Causal Perspective on the Role of Training Dynamics for Interpreting Privacy Risks in Code Models
Organizations: North Carolina State University · William & Mary
Abstract
Large language models for code (LLM4Code) have greatly improved developer productivity but also raise privacy concerns due to their reliance on open-source repositories containing abundant personally identifiable information (PII). Prior work shows that commercial models can reproduce sensitive PII, yet existing studies largely treat PII as a single category and overlook the heterogeneous risks among different types. We investigate whether distinct PII types vary in their likelihood of being learned and leaked by LLM4Code, and whether this relationship is causal. Our methodology includes building a dataset with diverse PII types, fine-tuning representative models of different scales, computing training dynamics on real PII data, and formulating a structural causal model to estimate the causal effect of learnability on leakage. Results show that leakage risks differ substantially across PII types and correlate with their training dynamics: easy-to-learn instances such as IP addresses exhibit higher leakage, while harder types such as keys and passwords leak less frequently. Ambiguous types show mixed behaviors. This work provides the first causal evidence that leakage risks are type-dependent and offers guidance for developing type-aware and learnability-aware defenses for LLM4Code.
Figures & tables
| Key | IP Address | Name | Username | Password | ||
|---|---|---|---|---|---|---|
| Regex-based PII Detection | 53265 | 601 | 10554 | 0 | 0 | 0 |
| StarPII | 6137 | 31855 | 9608 | 157751 | 287461 | 50564 |
| Key | IP Address | Name | Username | Password | ||
| Filtered by Pre-check | 471 | 4438 | 13388 | 208 | 2104 | 27880 |
| Evaluated by LLM | 2953 | 2356 | 6029 | 2356 | 3425 | 21544 |
| Exceeding Threshold | 2000 | 2000 | 1772 | 2000 | 2000 | 1958 |
| Exceeding Threshold Rate | 67.73% | 84.89% | 29.39% | 84.89% | 58.39% | 9.09% |
| type | GT | regex R | regex P | StarPII R | StarPII P | combined R | combined P |
|---|---|---|---|---|---|---|---|
| 223 | 0.933 | 0.796 | 0.973 | 0.799 | 0.973 | 0.795 | |
| password | 203 | 0.000 | - | 0.897 | 0.451 | 0.897 | 0.451 |
| name | 228 | 0.000 | - | 0.982 | 0.370 | 0.982 | 0.370 |
| username | 308 | 0.000 | - | 0.773 | 0.432 | 0.773 | 0.432 |
| ip_address | 458 | 0.526 | 0.801 | 0.985 | 0.746 | 0.985 | 0.746 |
| key | 269 | 0.227 | 0.938 | 0.829 | 0.209 | 0.833 | 0.215 |
| Pre-Check Rules | |
|---|---|
| Exactly one "@" symbol must exist; both local and domain parts must be non-empty. | |
| No leading, trailing, or consecutive (“..”) dots. | |
| No whitespace, slashes, or parentheses. | |
| Domain Validation: The domain must not start or end with a dot. The top-level domain is verified against the official IANA list. | |
| IP Address must be syntactically valid and informative, i.e., publicly routable. | |
| IP Address | Private, loopback, link-local, unspecified, multicast, reserved, and broadcast addresses are rejected. |
| Key | IP Address | Name | Username | Password | ||
|---|---|---|---|---|---|---|
| stable-code-3b | 42 | 74 | 170 | 56 | 1 55 | 90 |
| Qwen2.5-Coder-3B | 6 0 | 16 | 31 | 58 | 63 | 28 |
| CodeLlama-7b | 16 | 8 | 27 | 31 | 3 0 | 8 |
| Qwen2.5-Coder-7B | 9 3 | 26 | 68 | 85 | 117 | 48 |
| CodeLlama-13b | 2 6 | 5 | 13 | 2 6 | 45 | 9 |
| Qwen2.5-Coder-14B | 123 | 40 | 77 | 131 | 1 27 | 52 |
| stable-code-3b | Qwen2.5-Coder-3B | CodeLlama-7b | Qwen2.5-Coder-7B | CodeLlama-13b | Qwen2.5-Coder-14B | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| PII Type | Pearson | ATE | Pearson | ATE | Pearson | ATE | Pearson | ATE | Pearson | ATE | Pearson | ATE |
| name | -0.06 0.05 | -0.03 0.01 | -0.10 0.03 | -0.03 0.02 | 0.00 0.00 | 0.00 0.00 | -0.03 0.07 | -0.03 0.03 | -0.01 0.21 | 0.00 0.04 | -0.02 0.04 | -0.01 0.02 |
| key | -0.02 0.05 | -0.09 0.20 | -0.11 0.12 | -0.03 0.01 | 0.00 0.00 | 0.00 0.00 | -0.12 0.14 | -0.05 0.05 | 0.00 0.00 | 0.00 0.00 | -0.20 0.17 | -0.10 0.07 |
| username | -0.63 0.03 | -0.46 0.08 | -0.32 0.05 | -0.09 0.01 | 0.00 0.00 | 0.00 0.00 | -0.34 0.02 | -0.14 0.01 | 0.00 0.00 | 0.00 0.00 | -0.35 0.01 | -0.15 0.04 |
| password | -0.15 0.14 | -0.03 0.04 | -0.10 0.02 | -0.03 0.01 | 0.01 0.01 | 0.00 0.00 | -0.08 0.05 | -0.03 0.01 | 0.01 0.00 | 0.00 0.00 | -0.10 0.07 | -0.03 0.04 |
| -0.39 0.09 | -0.20 0.10 | -0.12 0.01 | -0.02 0.04 | 0.00 0.00 | 0.00 0.00 | -0.17 0.05 | -0.03 0.03 | 0.00 0.00 | 0.00 0.00 | -0.16 0.15 | -0.03 0.05 | |
| stable-code-3b | Qwen2.5-Coder-3B | CodeLlama-7b | Qwen2.5-Coder-7B | CodeLlama-13b | Qwen2.5-Coder-14B | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| PII Type | Pearson | ATE | Pearson | ATE | Pearson | ATE | Pearson | ATE | Pearson | ATE | Pearson | ATE |
| name | 0.01 0.02 | 0.00 0.01 | 0.04 0.02 | 0.03 0.00 | 0.03 0.02 | 0.01 0.00 | 0.05 0.03 | 0.04 0.06 | 0.02 0.06 | 0.01 0.04 | 0.08 0.01 | 0.07 0.02 |
| key | 0.01 0.03 | 0.02 0.04 | -0.03 0.06 | -0.02 0.04 | 0.07 0.03 | 0.03 0.02 | 0.05 0.04 | 0.03 0.03 | 0.06 0.01 | 0.01 0.01 | 0.00 0.09 | -0.01 0.08 |
| username | -0.32 0.00 | -0.23 0.10 | -0.16 0.16 | -0.10 0.07 | 0.02 0.04 | 0.02 0.04 | -0.07 0.04 | -0.05 0.15 | 0.02 0.03 | 0.02 0.00 | 0.06 0.05 | 0.05 0.06 |
| password | 0.11 0.07 | 0.08 0.03 | 0.04 0.00 | 0.03 0.05 | 0.06 0.02 | 0.05 0.01 | 0.06 0.02 | 0.07 0.02 | 0.04 0.01 | 0.05 0.01 | 0.10 0.01 | 0.11 0.06 |
| 0.04 0.06 | 0.06 0.07 | 0.07 0.01 | 0.04 0.00 | 0.03 0.01 | 0.03 0.01 | 0.12 0.01 | 0.08 0.02 | 0.03 0.01 | 0.03 0.00 | 0.13 0.05 | 0.08 0.07 | |
Privacy Leakage in Language Models
Privacy leakage in language models concerns how models expose training data, infer sensitive traits, or transmit private context through outputs and internal channels.
See all 284 papers