Skip to content

AIExplore

Use ChatGPT Coding Help Without Blind Copying

Treat generated code as a draft. Run it, read it, and check edge cases before you merge it into anything real.

Copying ChatGPT code straight into a project works often enough to feel safe. That is the problem. When it fails, it fails quietly. A missing edge case here. A wrong assumption there. A helpful looking function that hides a real bug under a smooth surface. By the time you notice, the code is deep in a branch.

The habit that fixes this is small. You still ask ChatGPT for code. You still accept its help. You just add a short loop before the code goes in. Read it, run it, check the edges. That loop takes a few minutes and catches the mistakes that would eat hours later.

What a review loop actually looks like

The loop has three steps. Read the code once so you can describe it in your own words. Run it against a real input from your project. Test one or two edge cases that matter for your case. If all three pass, the code is ready. If any of them fail, ask for a small fix and repeat.

When to run this loop

  • Any code that will run in production, even a small helper
  • Anything that touches user input, money, dates, or files
  • Code you cannot fully explain out loud after reading it
  • Code that uses a library or pattern you have not used before
  • A quick fix under time pressure that feels too easy

Prompt that invites review, not a hand off

Task: write the function I described.
Also do these:
1. After the code, list the edge cases you considered.
2. Suggest three quick tests I should run before I merge this.
3. Point out any assumption in the code that I should verify against my project.
Keep the review short and specific.

Why this prompt works

It builds the review loop into the reply itself. You now have a checklist of edge cases and a set of tests without having to think them up yourself. If ChatGPT missed something, the checklist makes the gap easier to spot.

Prompt to check code you already have

Here is a function I plan to merge.
Task: review it as if you were a careful senior engineer on my team.
Call out:
- Edge cases that are not handled.
- Assumptions that could be wrong in production.
- Any line that would surprise a future reader.
Do not rewrite the function. Only comment for now.

Prompt to explore a suspicious edge case

In the function above, walk through what happens when the input is an empty array.
Also walk through null and undefined.
Describe each case in three lines: what the code does, what it should do, and any change needed.
Do not change the function yet.

What to include in a reviewable request

  • A clear task and the context the function will run in
  • A request for the edge cases ChatGPT considered
  • A request for quick tests you can run yourself
  • A prompt for assumptions you should verify
  • A rule against rewrites when you are in review mode

How to refine after the review

Turn each unhandled edge case into a small follow up. Fix one at a time and rerun the tests. Small named changes are easier to review than a full rewrite and they keep the parts that were already right untouched.

Common mistakes

  • Merging code before you can describe what it does in your own words
  • Skipping edge case checks because the sample input worked
  • Trusting a review from ChatGPT without running the code yourself
  • Ignoring the assumption list because it feels obvious
  • Bundling several fixes into one round so a regression is hard to spot

How to check the final version

Run the code with a real input from your project. Run it again with one edge case that matters, such as an empty value or a large size. If both pass and the diff looks reasonable, you are ready to merge. If either fails, the review loop has one more round to do.

Takeaway

Generated code is a draft. Read it, run it, check the edges, and only then let it into anything real.

Related articles