Refactoring Plan for an Existing Module
Decomposes a refactor into small independently deployable and revertible steps, instead of a large rewrite that cannot be reviewed or reverted.
Prompt
Plan a refactor. Binding constraint: every step deploys separately, reviews separately, and reverts separately. No big rewrite.
Current code: <code> [Paste the module or describe its structure] </code>
The actual problem: [what is hard to do today, not "the code is ugly"] Existing test coverage: [describe]
Produce:
- Whether to refactor at all — if the code works and does not touch upcoming work, say so and stop. A refactor without a need is risk without return.
- Safety net — which tests must exist before touching anything. With no coverage, step one is characterisation tests documenting current behaviour, including behaviour that looks wrong.
- Step sequence — each step with: what changes, estimated diff size, what proves nothing broke, and how to revert. Aim for steps under 200 lines.
- Order — start with the step having the best value-to-risk ratio. Never change behaviour and structure in the same commit.
- Compatibility — how existing callers keep working through the transition. A shim if needed, and when it gets deleted.
- Stop condition — what signals the refactor has become too expensive and should stop with what has been achieved.
Explicitly state what not to touch in this pass, and why.
Why this converts well
- Ready to copy and use immediately
- Tailored for legal and public-sector work
- Easy to adapt to internal workflows
Tags
Related Prompts
Tool Specification for a Legal AI Agent
Produces a complete agent tool definition — schema, description, errors, permissions — with emphasis on tools that perform irreversible actions.
Designing a Structured Output Schema for Legal Data
Designs a JSON schema for legal data extraction with explicit representation of uncertainty and missing values instead of silent defaults.
Regression Test Suite for a Production Prompt
Builds a test suite for a prompt before changing it, catching silent regressions introduced by an innocent-looking improvement or a model swap.