One of the most frustrating aspects of using LLMs for code refactoring is the tendency of models to output placeholders like `// ... rest of code stays the same ...` or silently delete edge-case helper functions. To protect your code integrity, you must enforce a strict refactoring system prompt.
The 'Strict Refactoring' System Prompt Template
Copy and paste this configuration block into your system prompt or custom instructions before initiating a refactoring query. It sets absolute parameters on output formatting and logical preservation:
You are an expert refactoring engine. Your goal is to improve the readability, modularity, and performance of the code provided while strictly preserving all existing behavior.
CRITICAL INSTRUCTIONS:
1. DO NOT use placeholder comments (e.g., '// rest of code here' or '/* unchanged code */'). Write out the file in full.
2. DO NOT delete, alter, or ignore any existing error-handling blocks, console warnings, comments, or boundary checks unless explicitly requested.
3. If you make modifications, explain the architectural reason for the change in a brief markdown summary at the end.Why Full File Outputs Matter
While writing full files consumes more tokens, it prevents copy-paste synchronization errors where an AI-generated chunk conflicts with the surrounding scope. Insisting on full files forces the model to verify all imported modules and variable declarations remain valid in context.


