PrivCode++: Latent-Conditioned Differentially Private Code Generation for Comprehensive Guarantees
Abstract
Large language models fine-tuned on instruction–code pairs may memorize and subsequently leak sensitive training data. Existing differentially private (DP) code generation methods primarily protect code snippets while assuming prompts are public, which fails in realistic scenarios where prompts may also contain sensitive information. When prompts cannot be explicitly learned or used during generation, code synthesis suffers from severe utility degradation as well as reduced diversity and fidelity. To address these challenges, we propose PrivCode++, the first work to explore DP code generation where both prompts and code snippets are considered sensitive in LLM fine-tuning. PrivCode++ introduces a two-stage DP framework with a Privacy-Free Latent Conditioning module, enabling effective DP fine-tuning and data synthesis without direct access to sensitive prompts or code. Extensive experiments show that PrivCode++ achieves substantially higher utility than baselines, remains competitive with the method with relaxing privacy assumptions, and provides stronger privacy guarantees.
Lay Summary
Large language models can now generate code very well, but they sometimes memorize parts of their training data and accidentally reveal them later. Existing privacy-protection methods mainly try to protect the code itself, while assuming the text instructions given to the model are safe. In practice, however, these instructions can also contain sensitive information, such as private user requests, internal company details, or confidential project descriptions. Once these prompts can no longer be directly used, code generation quality usually drops a lot. In this work, we propose PrivCode++, the first method that protects both prompts and code during code model training. Instead of directly relying on sensitive prompts, our method teaches the model to learn hidden patterns about programming tasks, such as code structure and task intent, without memorizing the original data. The model can then use these hidden patterns to generate new code while keeping the training data private. Experiments show that PrivCode++ generates much better code than existing privacy-preserving methods and still provides strong privacy protection. It also performs competitively compared to methods that make weaker privacy assumptions. Our results suggest that it is possible to build useful AI coding systems without exposing sensitive user or code data.