LLM Code Refactoring for Library Compliance
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing software development ecosystems face challenges in updating code that uses non-compliant or deprecated third-party library APIs, due to API breaking changes, licensing issues, and vulnerabilities, which can lead to non-compliance with governing policies.
Innovation Solution
A method is introduced that uses a large language model (LLM) to refactor code snippets identified as potentially using out-of-compliance libraries. This involves accessing the code snippet, generating context, building an LLM prompt to instruct the model to rewrite the code to use compliant libraries, and displaying the proposed rewritten code.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Ease of operation
If existing code uses older library versions with more tutorials and example code, then ease of operation is improved, but compliance with governing policy deteriorates
Solution Approach 1:
The patent introduces an intermediary system that acts as a mediator between the codebase and compliance requirements. This system automatically detects non-compliant library usage and generates refactored code that meets compliance standards while preserving functionality, thus resolving the conflict between ease of operation and compliance without requiring manual intervention.
Solution Approach 2:
The patent replaces manual code review and refactoring processes with an automated AI-based system. This substitution transforms the mechanical process of compliance checking into an automated computational task, enabling the system to identify and correct non-compliant code patterns efficiently while maintaining both ease of operation and compliance.
2Reliability
If code is updated to use latest compliant library versions, then compliance is improved, but ease of operation deteriorates due to fewer tutorials and example code
Solution Approach 1:
The patent introduces an intermediary system that acts as a mediator between the codebase and compliance requirements. This system automatically detects non-compliant library usage and generates refactored code that meets compliance standards while preserving functionality, thus resolving the conflict between ease of operation and compliance without requiring manual intervention.
Solution Approach 2:
The patent replaces manual code review and refactoring processes with an automated AI-based system. This substitution transforms the mechanical process of compliance checking into an automated computational task, enabling the system to identify and correct non-compliant code patterns efficiently while maintaining both ease of operation and compliance.
3Ease of operation
If language model tools are trained on older library versions, then ease of operation is improved through better code suggestions, but compliance deteriorates as tools suggest outdated and non-compliant code
Solution Approach 1:
The patent implements a dynamic training approach where the language model is continuously updated with data from compliant library versions. This dynamic adaptation allows the model to evolve its code suggestions over time, balancing the benefits of learning from extensive historical data with the necessity of recommending compliant, up-to-date coding practices.
Solution Approach 2:
The patent applies preliminary filtering and guidance in the prompt engineering process to steer the language model toward compliant code suggestions. By pre-configuring the model with compliance constraints and guidelines before code generation, the system ensures that even when trained on older data, the model produces suggestions that meet current compliance standards.
Data Source
AI summary
Techniques for intelligently prompting an LLM to refactor code are disclosed. A code snippet is accessed. This code is identified as potentially comprising a reference to an out-of-compliance library. Context for the code snippet is generated. An LLM prompt is then built. This prompt will be fed to the LLM, and the prompt instructs the LLM to refactor the code snippet into modified code, which calls a compliant library. Output of the LLM is displayed. This output is based on the LLM operating in response to the LLM prompt. The output includes a proposed rewritten version of the code snippet.


