The invention provides a plug-and-play
security enhancement method and
system based on a
large model self-reflection mechanism, and the method comprises the steps: S1, receiving a
user input demand, generating a preliminary code, and extracting a
potential risk; s2, starting a security detection module to perform reflection
verification, identifying potential security issues, and marking the security issues through a self-generated security
knowledge base; s3, calling a correction module to perform code optimization, dynamically retrieving a security
knowledge base to perform security problem matching as reference content, performing automatic correction and code optimization, and returning to extract potential risks and perform reflection
verification; and S4, outputting a final code, generating a safety analysis report, summarizing the accumulated
safety knowledge, and updating and expanding a
safety knowledge base. According to the method, automatic correction, code optimization and reflection
verification can be performed through a self-reflection mechanism in each stage of the
code generation process, and it is ensured that each output result meets the safety requirement so as to meet the requirement for universality between different models.