Large Language Models (LLMs) are increasingly used for software development tasks such as code generation, debugging, documentation and program repair. However, directly generated code may contain security weaknesses including hard-coded credentials, unsafe input handling, injection-prone logic and insecure API usage. This paper presents CodeGPT-X, a secure LLM-assisted framework for code generation, vulnerability detection and automated debugging. The proposed framework integrates secure prompt engineering, controlled LLM invocation, static vulnerability analysis, runtime-aware checking, CWE and OWASP mapping, risk scoring, patch suggestion, explainability, human-in-the-loop review and a DevSecOps deployment gate. A full-stack prototype was implemented with a FastAPI backend and a React dashboard. A local functional demonstration with sample vulnerable code illustrates that the framework can identify high-risk findings, present severity-based reports, suggest secure repair workflows and block critical artefacts before deployment. The demonstration illustrates how generation can be combined with validation, explainability and governance; it does not establish comparative security effectiveness. The work contributes a practical architecture for secure AI-assisted software engineering.
Introduction
The text introduces CodeGPT-X, an AI-powered framework designed to generate secure code, detect vulnerabilities, suggest automatic fixes, and improve software security using Large Language Models (LLMs).
1. Introduction
Large Language Models are increasingly used in software development for code generation, debugging, error explanation, and code improvement.
However, AI-generated code may contain security vulnerabilities even when it appears to work correctly. Common security problems include:
Hard-coded passwords and credentials.
SQL injection vulnerabilities.
Insecure input handling.
Unsafe use of eval() and exec().
Weak encryption and hashing.
Missing authentication and authorization.
Unsafe system commands.
To address these problems, the research proposes CodeGPT-X, which combines secure prompt engineering, AI-based code generation, vulnerability detection, automated debugging, and human review.
2. Related Work
The paper discusses four major research areas:
LLM-Based Code Generation: Using AI models to generate, complete, and improve source code.
Software Security and Vulnerability Detection: Identifying security weaknesses using static analysis and machine learning.
Automated Program Repair: Generating patches to correct software vulnerabilities.
Explainable and Trustworthy AI: Providing understandable explanations and human supervision for AI-generated decisions.
The research highlights that AI-generated code must be verified before deployment.
3. Proposed CodeGPT-X Framework
CodeGPT-X follows a security-focused workflow in which generated code is treated as untrusted until it passes security checks.
The main components include:
Secure Prompt Engineering: Adds security requirements to user instructions before sending them to the LLM.
LLM Code Generation: Generates source code based on the security-enhanced prompt.
Vulnerability Analysis: Examines generated or uploaded code for security weaknesses.
CWE and OWASP Mapping: Categorizes detected vulnerabilities using standard security classifications.
Risk Scoring: Assigns severity levels to identified vulnerabilities.
Automated Debugging: Suggests secure patches to fix detected problems.
Explainability: Explains vulnerabilities and recommended solutions.
Human-in-the-Loop Review: Allows developers or security experts to approve or reject important patches.
DevSecOps Deployment Gate: Prevents insecure code from being deployed.
4. Methodology
The system follows an iterative security-oriented process:
A. Secure Prompt Engineering
The system adds security instructions to user requirements.
For example, when generating a login API, it includes requirements for password hashing, input validation, rate limiting, secure error handling, and session management.
B. Vulnerability Analysis
The framework checks code for:
Hard-coded secrets.
SQL injection patterns.
Unsafe eval() and exec() usage.
Weak hashing algorithms.
Unsafe command execution.
Missing input validation.
Runtime-aware analysis is simulated unless a secure sandbox is configured.
C. Debugging and Governance
When vulnerabilities are detected, the system suggests defensive code patches and explains how they reduce security risks.
Suggested patches must be validated before acceptance. High-risk modifications require human approval.
D. Risk Classification
The system calculates a weighted risk score and classifies vulnerabilities into four levels:
Risk Level
Action
Low
Record and monitor
Medium
Repair or provide an explicit waiver
High
Require human approval
Critical
Block deployment
5. Implementation Technologies
The prototype is developed using the following technologies:
Technology
Purpose
Python
Backend programming
FastAPI
REST API and backend services
React
Frontend development
TypeScript
Frontend programming
SQLite
Database storage
Docker
Optional secure sandboxing
The application includes several modules:
Login and registration
Dashboard
Code generation
Vulnerability analysis
Automated debugging
Human review
Reports
Settings
6. Experimental Results
The prototype was tested in a local development environment.
A sample vulnerable Python program containing a hard-coded password and unsafe eval() usage was submitted for analysis.
The reported dashboard results were:
Total analyses: 2
Approved patches: 0
Pending reviews: 0
Blocked deployments: 2
Critical reports: 2
Reported risk scores: 8.32 and 8.82
The prototype successfully demonstrated code analysis, vulnerability reporting, patch suggestions, and deployment governance.
However, the paper does not establish comparative performance improvements through a large-scale experimental evaluation. Runtime analysis also remains simulated unless Docker sandboxing is configured.
Conclusion
This paper presented CodeGPT-X, a secure LLM-assisted framework for code generation, vulnerability detection and automated debugging. The framework integrates secure prompt engineering, controlled LLM invocation, static and runtime-aware vulnerability analysis, CWE and OWASP mapping, risk scoring, patch suggestion, explainability, human review and a DevSecOps deployment gate.
References
[1] Naveed, H., Khan, A.U., Qiu, S., et al.: ‘A comprehensive overview of large language models’, ACM Transactions on Intelligent Systems and Technology, 2025, 16, (5), pp. 1–72.
[2] Wang, L., Ma, C., Feng, X., et al.: ‘A survey on large language model based autonomous agents’, Frontiers of Computer Science, 2024, 18, (6).
[3] Bouzid, R., Khoury, R.: ‘Assessing the effectiveness of ChatGPT in secure code development: A systematic literature review’, ACM Computing Surveys, 2025, 57, (12), pp. 1–32.
[4] Krasniqi, R., Xu, D., Vieira, M.: ‘SE perspective on LLMs: Biases in code generation, code interpretability, and code security risks’, ACM Computing Surveys, 2025, 58, (5), pp. 1–16.
[5] Sheng, Z., Chen, Z.G., Gu, S., et al.: ‘LLMs in software security: A survey of vulnerability detection techniques and insights’, ACM Computing Surveys, 2025, 58, (5), pp. 1–35.
[6] Harzevili, N.S., Belle, A.B., Wang, J., et al.: ‘A systematic literature review on automated software vulnerability detection using machine learning’, ACM Computing Surveys, 2024, 57, (3), pp. 1–36.
[7] Le, T.H.M., Chen, H., Babar, M.A.: ‘A survey on data-driven software vulnerability assessment and prioritiza-tion’, ACM Computing Surveys, 2022, 55, (5), pp. 1–39.
[8] Casey, B., Santos, J.C.S., Perry, G.: ‘A survey of source code representations for machine learning-based cyberse-curity tasks’, ACM Computing Surveys, 2025, 57, (8), pp. 1–41.
[9] Renzullo, J., Reiter, P., Weimer, W., Forrest, S.: ‘Automated program repair: Emerging trends pose and expose problems for benchmarks’, ACM Computing Surveys, 2025, 57, (8), pp. 1–18.
[10] Cao, S., Sun, X., Widyasari, R., et al.: ‘A systematic literature review on explainability for ML/DL-based software engineering’, ACM Computing Surveys, 2025, 58, (4), pp. 1–34.
[11] Schneider, J.: ‘Explainable generative AI (GenXAI): A survey, conceptualization, and research agenda’, Artificial Intelligence Review, 2024, 57, (11).
[12] Ferdaus, M.M., Abdelguerfi, M., Ioup, E., et al.: ‘Towards trustworthy AI: A review of ethical and robust large language models’, ACM Computing Surveys, 2025, 58, (7), pp. 1–43.
[13] Huang, X., Ruan, W., Huang, W., et al.: ‘A survey of safety and trustworthiness of large language models through the lens of verification and validation’, Artificial Intelligence Review, 2024, 57, (7).
[14] Yao, Y., Duan, J., Xu, K., et al.: ‘A survey on large language model security and privacy: The good, the bad, and the ugly’, High-Confidence Computing, 2024, 4, (2), pp. 100211.
[15] Das, B.C., Amini, M.H., Wu, Y.: ‘Security and privacy challenges of large language models: A survey’, ACM Computing Surveys, 2025, 57, (6), pp. 1–39.
[16] Dong, Y., Mu, R., Zhang, Y., et al.: ‘Safeguarding large language models: A survey’, Artificial Intelligence Review, 2025, 58, (12), pp. 382.
[17] Kaur, R., Klobucar, T., Gabrijelcic, D.: ‘Harnessing the power of language models in cybersecurity: A comprehensive review’, International Journal of Information Management Data Insights, 2024, 5, (1), pp. 100315.
[18] Wang, S., Zhu, T., Liu, B., et al.: ‘Unique security and privacy threats of large language models: A comprehensive survey’, ACM Computing Surveys, 2025, 58, (4), pp. 1–36.