Code prompts that actually work (debug, refactor, tests)

How to stop getting generic answers: force diffs, constraints, and test checklists.

Last updated: · Markdown version

Make it concrete

  • Provide minimal reproducible snippet + expected vs actual.
  • Demand an output structure (steps, diff, checklist).
  • Include environment/version constraints.
  • Ask for edge cases + tests.

Before → after: a debugging request

  • Before: "My function doesn't work, fix it." The model has to guess the language, the symptom and what 'works' means, so it rewrites the function in general terms.
  • After: "Bug: the total is off by one when the list has one item. Environment: Node 20, TypeScript 5. Expected: 10. Actual: 9. Minimal reproduction below. Return the cause, the fix as a diff, and a test that fails before and passes after."
  • What changed: symptom, environment, expected versus actual, a minimal reproduction and the exact deliverable are all stated.

Check the answer before you trust it

  • Run the code and the tests it proposes. A confident explanation is not proof that the fix works.
  • Ask for a diff or only the changed parts, so you can review a small change instead of a rewritten file.
  • Change one thing per request. If you ask for a refactor, a new feature and a bug fix together, you cannot tell which change broke what.
  • Ask what it is unsure about ('list assumptions you made'): the assumptions are where wrong fixes come from.

Templates

Refactor with invariants

Refactor this code while keeping behavior identical.

Constraints:
- Do not change public API.
- Keep runtime complexity <= current.
- Prefer small functions + clearer names.

Code:
"""[paste]"""

Return:
1) brief rationale
2) diff/snippet (only changed parts)
3) test checklist (what to cover)
Opens the analyzer with the prompt prefilled.
Open in Promptea

Debug with expected vs actual

Bug: [one-line description]
Environment: [language, runtime, framework versions]
Expected: [what should happen]
Actual: [what happens; paste the error or stack trace]

Minimal reproduction:
"""[code]"""

Return:
1) the most likely cause, in two sentences
2) the minimal fix as a diff (changed lines only)
3) one test that fails before the fix and passes after
4) the assumptions you made, so I can check them
Opens the analyzer with the prompt prefilled.
Open in Promptea

FAQ

How do I get a real diff?
Ask for 'only changed parts' and specify the file context. If possible, include filenames.
Should I paste the whole file?
Paste the smallest snippet that reproduces the problem plus the signatures it depends on. A whole file adds noise and can push the relevant lines out of focus.
How do I stop it from rewriting everything?
State the invariants ('do not change the public API') and ask for the minimal diff. Telling it what must stay the same works better than asking it to 'be careful'.