REFACTORING / A WORKED STARTING POINT
Refactor without changing the contract
Request a small rewrite with explicit behaviour-preservation checks, including awkward inputs already allowed by the code.
Template reviewed
WHEN TO USE IT
You want a readability change with a deliberately narrow scope.
Bring these inputs
- {{contract}}
- The behaviours that must remain stable.
- {{code}}
- The function to refactor.
01 / THE PROMPT
A template you can inspect.
Refactor only the supplied function for readability. Preserve its current externally visible behaviour, including whitespace, truthiness and existing error behaviour unless the contract explicitly permits a change.
Return the revised function and a short before/after check table. Do not add validation, trim text, rename public fields or introduce dependencies. Distinguish checks you ran from checks you propose. If a cleaner rewrite requires a behaviour change, explain it instead of making that change silently.
Contract:
{{contract}}
Code:
{{code}}
Copying does not run the prompt. Workbench opens an editable draft with the example inputs. It does not save or send it.
02 / THE EXAMPLE TARGET
What a useful result should contain.
This is a target for the worked example, not a recorded model response. Equivalent wording can be valid where the task allows it.
export const label = record => record.active ? record.name.toUpperCase() : 'Inactive';
{ active: true, name: ' Juniper ' } => ' JUNIPER '
{ active: false, name: null } => 'Inactive'
{ active: 1, name: 'hello' } => 'HELLO'
{ active: 0, name: 'unused' } => 'Inactive'
03 / JUDGE THE RESULT
Check the answer, not the confidence.
- The surrounding spaces remain in the active name.
- A falsy active value does not read or convert name.
- Truthy values such as 1 retain their existing behaviour.
The worked example is a target to inspect, not a saved response from a model. Use the checks to judge an actual result.
This template was revised during the September prompt review. The earlier text remains in Git history.
Read the prompt collection review ↗