LLM Code Generation With Multi-Critic Feedback Loops
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Large language models (LLMs) used for code generation often produce hallucinations and security risks, leading to incorrect code execution and vulnerabilities despite providing accurate results.
Innovation Solution
Implementing an LLM-based generative framework with an internal dialogue critique loop, utilizing multiple neural network-based critics for preemptive and post-hoc critiques to refine generated code, including safety and helpfulness-focused critics, and incorporating external tool feedback to enhance code quality.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Productivity
If LLM is used for code generation, then code can be generated automatically, but hallucinations and security risks occur causing incorrect code execution
Solution Approach 1:
The patent implements a critique loop where multiple critic LLMs provide feedback on generated code through internal dialogues. The critic LLMs evaluate the code for security risks, hallucinations, and correctness issues, then the actor LLM uses this feedback to refine and regenerate code until it meets quality standards, resolving the contradiction between automated generation and code reliability
Solution Approach 2:
The patent introduces critic LLMs as intermediary components between the code generation process and the final output. These critic LLMs act as mediators that analyze generated code, identify security vulnerabilities and hallucinations, and provide structured feedback to improve code correctness without preventing automated generation
2Reliability
If multiple critic LLMs are used for code critique, then code quality improves, but computing resources increase
Solution Approach 1:
The patent segments the code critique function into multiple specialized critic LLMs, each focusing on specific aspects such as security, correctness, and best practices. This segmentation allows parallel evaluation of different code dimensions, improving comprehensive code quality assessment while enabling efficient resource utilization through specialized rather than general-purpose critique models
3Object-affected harmful factors
If internal dialogue critique loop is implemented, then dangerous code execution is avoided, but system complexity increases
Solution Approach 1:
The patent merges the code generation and code critique functions into a unified system where actor LLMs and critic LLMs work together in an integrated dialogue loop. This merging allows the system to simultaneously generate and evaluate code, preventing dangerous execution through built-in validation while managing complexity through coordinated interaction rather than separate independent systems
Data Source
AI summary
Embodiments described herein provide a method of jointly generating a code output. A first language model (LM) generates a code output in response to a task description. Second and third LMs generate critiques based on the task description and the generated code. The second LM may critique the accuracy of the generated code, and the third LM may critique the safety of the generated code (e.g., susceptibility to hacks). The first LM may revise the generated code based on the critiques. The revised code may be executed, and based on the results of the execution, the first LM may revise the code again. The process of critiques, revisions, and execution may be repeated. The final generated code is output to a user (e.g., in a programming environment).


