atlas

Research map / Large language models / Language, safety and interpretability

PurpCode: Reasoning for Safer Code Generation

NeurIPS 2025 · Large language models › Language, safety and interpretability · approach: Safety alignment of LLMs · 0 citations (OpenAlex)

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Introduces PurpCode, a two-stage post-training recipe (rule learning via SFT on rule-referencing reasoning traces, then GRPO-based RL with security and utility oracles) plus internal red-teaming, yielding PurpCode-32B with state-of-the-art cybersafety among frontier models.

Problem

Code LLMs can be abused to assist malicious cyberactivities or to generate functionally correct code containing security vulnerabilities, while over-refusing benign security-related requests; existing SFT/RLHF alignment does not generalize well for cybersafety.

Approach

Explicitly teach a code model to reason over known cybersafety rules (CWE-specific coding hints, behavioral and safety guidelines) through rejection-sampled SFT, then run outcome-driven RL with multi-objective binary oracles (CodeGuru security, LLM safety judge, test execution, over-refusal judge), using a single-step dynamic sampling variant and batched code-analyzer reward computation.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Add Rule Learning (ablation)Qwen2.5-32B · CyberSecEval SCG% secure code: 64.8 -> 68.5Helped
Add RL after Rule Learning (ablation)PurpCode-32B · CyberSecEval SCG% secure code: 68.5 -> 80.8Helped
Add Rule Learning (ablation)Qwen2.5-32B · CodeLMSec% secure code: 29.2 -> 71.4Helped
Add RL after Rule Learning (ablation)PurpCode-32B · CodeLMSec% secure code: 71.4 -> 94.8Helped
Add Rule Learning (ablation)Qwen2.5-32B · CyberSecEval MITRE% safe response: 98.0 -> 99.9Helped
Add RL after Rule Learning (ablation)PurpCode-32B · CyberSecEval MITRE% safe response: 99.9 -> 99.2Hurt
Use single-step dynamic sampling instead of DAPO's dynamic sampler (ablation)Qwen2.5-14B-Instruct-1M RL · CyberSecEval SCG% secure code: 74.5 -> 76.6Helped
Use single-step dynamic sampling instead of DAPO's dynamic sampler (ablation)Qwen2.5-14B-Instruct-1M RL · CyberSecEval MITRE% safe response: 99.2 -> 96.2Hurt
Use single-step dynamic sampling instead of DAPO's dynamic sampler (ablation)Qwen2.5-14B-Instruct-1M RL · HumanEval+pass@1: 78.7 -> 82.4Helped
Use single-step dynamic sampling instead of DAPO's dynamic sampler (ablation)Qwen2.5-14B-Instruct-1M RL · RL training time per policy updateseconds per policy update step: 694 seconds -> 611 secondsHelped

Surprising findings

Limitations

Experimental setup

Datasets: OSV KodCode-V1-SFT-R1 CyberMetric CyberSecEval CodeLMSec CWEval SecCodePLT HarmBench

Benchmarks: CyberSecEval SCG CodeLMSec CWEval (Python) CyberSecEval MITRE CyberSecEval FRR XSCode XSTest PHTest HumanEval+ MBPP+ Security QA

Metrics: % secure code % safe response % answered defense success rate pass@1

Baselines: Qwen3-32B Qwen3-235B DeepSeek-R1-0528 o4-mini Claude Sonnet 4 SafeCoder ProSec DAPO

Builds on: deliberative alignment GRPO DAPO veRL ProSec

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy