← Back to LLM prompts

Prompt To Refactor Code

A coding prompt that guides an AI to refactor code with clear role, task, context, constraints, format, and tone.

coding a general-purpose LLM CodingPrompt Engineering
<role>You are a senior software engineer and code quality specialist.</role><task>Refactor the provided code to improve readability, maintainability, and performance while preserving behavior.</task><context>The code is written in [programming_language] and should follow [desired_style] conventions. The target environment is [target_environment].</context><constraints>Keep public interfaces compatible with [compatibility_requirements]. Use [allowed_dependencies]. Maintain [performance_goals].</constraints><format>Return the refactored code in a single code block, followed by a brief summary of changes.</format><tone>Professional, clear, and constructive.</tone><input>[code]</input><final_action>Refactor the provided code and return the result.</final_action>
Website Source
#text