TL;DR
INDICT introduces a dual-critic framework that significantly improves Large Language Model (LLM) code generation by balancing the often-conflicting goals of safety and helpfulness. By orchestrating an autonomous internal dialogue between a safety-driven critic and a helpfulness-driven critic—both empowered with external search and execution tools—the framework achieves over a 10% absolute improvement in code quality across various model sizes without requiring expensive fine-tuning.
What Problem Does This Paper Address?
While LLMs have become remarkably proficient at generating code, they struggle to navigate the intricate boundary between helpfulness and security. Code itself is rarely inherently malicious; for instance, an encryption script can be used to build a secure personal file system (helpful) or to launch a ransomware attack (malicious).
Standard alignment techniques like fine-tuning (RLHF) are expensive, require scarce expert cybersecurity data, and often fail against sophisticated, optimized "jailbreak" attacks. Furthermore, forcing a single model to optimize for both functional correctness and safety at inference time often leads to biased or diluted critiques. INDICT addresses this gap by creating a scalable, inference-time multi-agent framework that simultaneously optimizes both security and helpfulness.
Methods
The core innovation of INDICT (Internal Dialogues of Critiques) is its dual cooperative critic system. Instead of relying on a single critic, the framework splits the responsibility into two distinct agents with orthogonal objectives:
- Safety-Driven Critic ($\sigma$): Focuses entirely on identifying security risks, vulnerabilities, and malicious intents.
- Helpfulness-Driven Critic ($\omega$): Focuses on whether the code fully satisfies the user's prompt requirements and corner cases.
These critics engage in an autonomous internal dialogue. To prevent context bloat for the main "actor" LLM, their conversation is dynamically summarized by an LLM-based summarizer.
Crucially, the critics are knowledge-grounded using external tools through two primary actions:
- Code Search: Queries the web, Wikipedia, or OpenAI using text and code snippets to find secure alternatives or best practices.
- Code Review: Executes code snippets within a secure code interpreter to observe runtime behavior and errors.
INDICT deploys these critics in two distinct phases: preemptive feedback (during the initial code generation stage to prevent dangerous code from ever being executed) and post-hoc feedback (after the code runs in an execution environment).
Datasets
The authors evaluated INDICT across 8 programming languages using 5 rigorous benchmarks:
- CyberSecEval-1: Used to test insecure coding practices (Autocomplete and Instruction splits) and cyberattack helpfulness.
- CyberSecEval-2: Used to evaluate advanced threats like interpreter abuse and prompt injection.
- CVS (Code Vulnerability and Security): A dataset providing pairs of ground-truth secure and insecure code for specific problems.
- HarmBench: An open-ended generation benchmark used to test the framework against automated red-teaming optimization methods.
- CAMEL: A dataset containing complex, open-ended problems across diverse conversational domains.
Key Insights and Ideas
- Decoupling Objectives Prevents Bias: Trying to prompt a single model to be both perfectly safe and perfectly helpful usually results in a compromise. Separating these roles into two adversarial yet collaborative agents allows each to advocate fully for its objective.
- Preemptive Protection is Mandatory for Security: Relying solely on post-hoc execution feedback (testing if code works after running it) is highly risky in cybersecurity. If an LLM generates code that deletes a directory, running it to get an error message is too late. Preemptive critique acts as a vital firewall.
- External Grounding Cures Hallucinations: LLMs frequently hallucinate security vulnerabilities or miss obscure ones. Giving critics access to web searches and code interpreters drastically improves the accuracy and reliability of their feedback.
Key Results
The framework was validated using models ranging from 7B to 70B parameters (including CommandR, Llama, and CodeLlama families).
- Universal Improvement: INDICT delivered a consistent +10% absolute improvement in overall code quality across all tested models.
- State-of-the-Art Safety: When paired with CommandR and Llama3, INDICT achieved state-of-the-art safety scores, rendering over 80% of outputs safe on CyberSecEval-1 and over 90% safe on CVS.
- No Loss in Helpfulness: Unlike traditional safety guards that make models overly conservative, up to 70% of INDICT's outputs were rated as more helpful than baseline or ground-truth models.
Limitations and Future Work
- Dependency on Instruction-Following: INDICT relies heavily on the base LLM’s capacity to roleplay effectively. If a model struggles to maintain the persona of a strict safety critic, the quality of the dialogue degrades.
- Computational Overhead: Running multiple critic loops and external tool queries increases inference latency and API costs, making INDICT roughly 3-4x more time-consuming than direct single-model generation.
- Narrow Definition of Safety: The paper focuses heavily on technical vulnerabilities (CWEs) and malicious exploits. It does not currently address broader safety concerns such as social biases or offensive language within code comments.
Summary updated