An Empirical Study of Security Calibration in Large Language Models for Code
Mohammed Latif Siddiq, Md. Nafiu Rahman, Joanna C. S. Santos
Abstract
Large Language Models (LLMs) are rapidly transforming software development, yet their use in security-critical contexts raises a key question: do models know when their generated code is insecure? This property, known as calibration, measures whether a model's confidence aligns with the true correctness of its outputs. We present the first large-scale empirical study of security calibration in LLM-generated code. We evaluate GPT-4o-mini, Gemini-2.0-Flash, and Qwen3-Coder-Next across multiple temperature settings on two complementary benchmarks: self-contained security tasks and multi-language repository-level contexts. Our results suggest that overconfidence is prevalent across the evaluated LLMs. Functional calibration is consistently worse than security calibration, suggesting that models estimate security outcomes more reliably than functional correctness, potentially because functional correctness depends on complex execution behavior. We also examine whether calibration-guided automated repair can help remediate vulnerabilities in LLM-generated code, finding only limited improvements while frequently introducing functional regressions. Moreover, we study different mitigation strategies for reducing False Trust, where models assign high confidence to vulnerable code. The results show that although architectural gating improves calibration on controlled benchmarks, calibration deteriorates in realistic repository-level settings, increasing the risk of high-confidence vulnerable outputs.
Create a lesson
Metadata
- Categories
- cs.SE, cs.CR, cs.LG
- Comments
- Accepted at the 42nd International Conference on Software Maintenance and Evolution (ICSME 2026) Research Track
Related papers
Scientific Coding with Large Language Models: Evidence from Finite Element Analysis
Shared title terminologycs.SEErfan Hamdi, Joel Shor, Emma Lejeune
Beyond Benchmarks: Evaluating Large Language Models and Agentic Patterns for Static Code Analysis Warning Classification
Shared title terminologycs.SELakmal Deshapriya, Sherlock A. Licorish, Brendon J. Woodford et al.
Large Language Models for Multi-Lingual Equivalent Mutant Detection: An Extended Empirical Study
Shared title terminologycs.SEHonglin Shu, Zhao Tian, Dong Wang et al.
CodeChat-Eval: Evaluating Large Language Models in Multi-Turn Code Refinement Dialogues
Shared title terminologycs.SEGuoxiang Guo, Kla Tantithamthavorn, Neelofar Neelofar et al.
Bash-Commenter: Leveraging Syntax-Aware Preference Optimization to Reinforce Large Language Model for Bash Code Comment Generation
Shared title terminologycs.SELei Yu, Jingyuan Zhang, Xin Wang et al.
Large Language Models for Mobile GUI Text Input Generation: An Empirical Study
Shared title terminologycs.SEChenhui Cui, Tao Li, Junjie Wang et al.