
Answer-first summary for fast verification
Answer: Provide recent secure-code examples and ask the LLM to generalize (few-shot)
## Explanation **Option A is correct** because providing recent secure-code examples and asking the LLM to generalize (few-shot learning) is the most effective approach for improving code security. This method: 1. **Provides concrete examples** of secure coding patterns 2. **Demonstrates real-world security practices** that the LLM can learn from 3. **Uses few-shot learning** which is effective for teaching LLMs specific patterns 4. **Generalizes from examples** to apply security principles to new code **Why other options are less effective:** - **Option B (Chain-of-thought)**: While asking the LLM to "think step-by-step" can improve reasoning, it doesn't specifically teach secure coding practices unless security considerations are explicitly included in the reasoning chain. - **Option C (Role-playing without examples)**: Simply role-playing as a security auditor without providing examples lacks concrete guidance on what constitutes secure code. - **Option D (High temperature for creativity)**: Using a higher sampling temperature (1.2) increases randomness and creativity, which could actually lead to less secure code as the LLM might generate unconventional or untested patterns. **Best Practice**: The most effective approach combines few-shot learning with security-focused examples, as this directly teaches the LLM secure coding patterns through demonstration rather than relying on abstract reasoning or role-playing alone.
Author: Ritesh Yadav
Ultimate access to all questions.
Which approach is most effective for improving the security of code generated by an LLM?
A
Provide recent secure-code examples and ask the LLM to generalize (few-shot)
B
Ask the LLM to "think step-by-step" using chain-of-thought
C
Role-play as a "Security Auditor" without examples
D
Use sampling temperature of 1.2 for creativity
No comments yet.