Few-Shot Code-Change Prompts for LLM Vulnerability Repair

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing methods struggle to efficiently detect and remediate software vulnerabilities in source code due to their subtle nature and the lack of clear fail-stop symptoms, which complicates resource management and security in complex software systems.

Innovation Solution

A system that generates a prompt for a large language model using few-shot examples of code changes to correct specific software vulnerabilities, clustering similar changes and selecting representative examples for the prompt to guide the model in generating accurate repair code.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Measurement precision

If traditional vulnerability detection methods are used, then detection capability is limited, but computational resources and time consumption increase

Engineering Contradiction:
Improvevulnerability detection capabilityVSAvoidtime consumption
Core Design Contradiction:
Measurement precisionVSLoss of time

Solution Approach 1:

The system performs preliminary actions by pre-processing vulnerability data and organizing it into structured formats before the actual detection process. Code changes related to vulnerabilities are collected, cleaned, and prepared in advance, allowing the large language model to work with pre-organized information during real-time detection, thus reducing operational time consumption.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The system creates simplified copies of vulnerability information by generating structured representations of code changes and vulnerability relationships. Instead of analyzing raw, complex codebases directly, the system uses copied and structured vulnerability data that preserves essential information while reducing computational complexity, enabling faster detection without sacrificing accuracy.

Inventive Principle:
Principle #26Copying

2Reliability

If fine-tuning the large language model is performed, then model accuracy improves, but computational resources and training time increase

Engineering Contradiction:
Improvemodel accuracyVSAvoidcomputational resources
Core Design Contradiction:
ReliabilityVSUse of energy by moving object

Solution Approach 1:

The system introduces an intermediary layer between the large language model and the vulnerability detection task. Instead of fine-tuning the model directly on vulnerability data (which consumes大量 computational resources), the system uses structured vulnerability information and code change representations as intermediaries that guide the model's detection process, achieving high accuracy without extensive fine-tuning.

Inventive Principle:
Principle #24Intermediary (Mediator)

Solution Approach 2:

The system changes the parameters of the detection approach by using structured vulnerability data formats and organized code change representations instead of raw data. This parameter change allows the large language model to achieve high detection accuracy by working with pre-processed, well-structured information rather than requiring extensive fine-tuning on raw vulnerability datasets.

Inventive Principle:
Principle #35Parameter changes

3Measurement precision

If comprehensive code analysis is performed, then vulnerability detection accuracy improves, but system complexity and processing time increase

Engineering Contradiction:
Improvedetection accuracyVSAvoidsystem complexity
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The system segments the vulnerability detection process into distinct components: code change collection, data cleaning, structured representation generation, and model inference. By dividing the comprehensive code analysis into these manageable segments, the system maintains high detection accuracy while reducing overall system complexity and making each component easier to manage and optimize independently.

Inventive Principle:
Principle #1Segmentation

Data Source

PatentUS12406072B2Code-change based prompt for code repair
Publication Date: 2025.09.02 MICROSOFT TECHNOLOGY LICENSING LLC
  • US12406072B2 patent drawing
  • US12406072B2 patent drawing
  • US12406072B2 patent drawing

AI summary

A source code repair system generates a prompt including a few-shot examples of code changes made previously to correct a particular source code vulnerability. The prompt is given to a large language model to generate repair code for a source code snippet having the same vulnerability. Code changes made for a particular source code vulnerability, in the form of code diffs, are clustered into groups of closely related code change embeddings. A select few of the code diffs in each group having a closest mean of the cluster are used as the few-shot examples for the corresponding source code vulnerability.