[Paper Review] Using ChatGPT as a Static Application Security Testing Tool
This paper evaluates GPT-3.5 (via ChatGPT) as a static application security testing (SAST) tool for Python code, using prompt engineering to detect vulnerabilities. It demonstrates that ChatGPT reduces false positives and negatives compared to Bandit, Semgrep, and SonarQube, showing strong potential as a complementary SAST assistant with F1 scores up to 0.4101 in specific configurations.
In recent years, artificial intelligence has had a conspicuous growth in almost every aspect of life. One of the most applicable areas is security code review, in which a lot of AI-based tools and approaches have been proposed. Recently, ChatGPT has caught a huge amount of attention with its remarkable performance in following instructions and providing a detailed response. Regarding the similarities between natural language and code, in this paper, we study the feasibility of using ChatGPT for vulnerability detection in Python source code. Toward this goal, we feed an appropriate prompt along with vulnerable data to ChatGPT and compare its results on two datasets with the results of three widely used Static Application Security Testing tools (Bandit, Semgrep and SonarQube). We implement different kinds of experiments with ChatGPT and the results indicate that ChatGPT reduces the false positive and false negative rates and has the potential to be used for Python source code vulnerability detection.
Motivation & Objective
- To assess the feasibility of using large language models, specifically ChatGPT, for detecting software vulnerabilities in Python code.
- To compare ChatGPT’s performance against established SAST tools—Bandit, Semgrep, and SonarQube—on vulnerability detection accuracy.
- To investigate whether prompt engineering with ChatGPT can reduce false positive and false negative rates in static code analysis.
- To explore the potential of using GPT-3.5 as a supplementary assistant to improve results from traditional SAST tools.
Proposed method
- The study uses prompt engineering to instruct ChatGPT to analyze Python source code for security vulnerabilities based on Common Weakness Enumeration (CWE) categories.
- Four distinct experimental setups are designed: binary classification, vulnerability list selection, SAST assistant role, and free-text classification.
- ChatGPT is evaluated on three datasets containing known vulnerabilities, with results compared to Bandit, Semgrep, and SonarQube using precision, recall, and F1 metrics.
- The prompt design emphasizes naturalness and expressiveness to improve model performance, based on guidelines from prior LLM prompt evaluation studies.
- Evaluation metrics are computed using ground-truth labels from vulnerability datasets, with results analyzed across different prompt configurations.
- The experiments focus exclusively on Python code, leveraging the language’s popularity and prevalence in security-critical applications.

Experimental results
Research questions
- RQ1Can ChatGPT effectively detect security vulnerabilities in Python source code using prompt-based instruction?
- RQ2How does ChatGPT’s vulnerability detection performance compare to traditional SAST tools like Bandit, Semgrep, and SonarQube in terms of precision, recall, and F1 score?
- RQ3Does using ChatGPT as a SAST assistant improve the accuracy of existing SAST tools by reducing false positives and false negatives?
- RQ4How do different prompt configurations affect the reliability and consistency of ChatGPT’s vulnerability detection outcomes?
Key findings
- In the SAST assistant role, ChatGPT achieved an F1 score of 0.1808, outperforming SonarQube (F1: 0.0743), Bandit (F1: 0.1022), and Semgrep (F1: 0.1812) in the same setup.
- For the free-text classification task, ChatGPT achieved an F1 score of 0.1808, indicating moderate but competitive performance compared to rule-based SAST tools.
- In the binary classification experiment, ChatGPT achieved an F1 score of 0.4101, significantly outperforming Semgrep (F1: 0.1812), Bandit (F1: 0.1022), and SonarQube (F1: 0.0743).
- ChatGPT demonstrated lower false positive and false negative rates than all three baseline SAST tools across multiple experiments, especially in the binary classification setting.
- The model’s performance was sensitive to prompt design, with optimized prompts yielding significantly better results, suggesting prompt engineering is critical for reliable output.
- Despite promising results, the study acknowledges limitations, including reliance on GPT-3.5 (not GPT-4), dataset coverage gaps, and security concerns related to uploading source code to external servers.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.