<< Home | Work
Prevented broken code and unintended changes in scripts
| Area | Work |
| AI used | Any |
| Source | r/PromptEngineering |
| Posted | 2026-03-12 |
The move
Request only the specific modified function instead of a full file rewrite.Steps
- Identify the specific function or block of code that needs modification.
- Instruct the AI to output only the code for that specific function.
- Copy the AI's output into your existing file manually.
- Reject any response that attempts to rewrite the entire file.
Prompt for your AI
I have the following code: [Paste your code]. Please modify only the [specific function or logic] to [describe the change]. Output ONLY the code for this specific function. Do not rewrite the entire file.
What happened
Users often ask AI to modify code while keeping the rest unchanged, but LLMs regenerate the entire script from scratch, leading to errors and variable changes. By requesting only the specific function that needs changing, you avoid the model's tendency to hallucinate or alter unrelated parts of the code. This approach ensures the rest of your script remains untouched.Watch out
The AI may still make errors within the specific function requested; always verify the logic after pasting.Give it to your agent
Read https://howtheyuse.ai/p/prevented-broken-code-and-unintended-changes-in-scripts.md and help me do this.