Blog / Build with AI /

AI-written code: five mistakes to check before you trust it

AI-written code has a particular trap. It looks tidy. It has comments. It comes with a confident explanation. And that polish makes you trust it more than you should.

If you run websites and are starting to paste code from a chatbot into a theme file, a snippet plugin or a script, a few checks will save you from the worst surprises. Here are the five I would run every time. They are the same checks I would apply to code from a stranger on a forum, because that is effectively what it is.

Mistake 1: functions and options that do not exist

Language models predict plausible code. Sometimes the most plausible function name is one that does not exist, or one that existed in an older version and has since been removed or renamed. The knowledge of ChatGPT stops in 2021, so recent changes are invisible to it.

What to check:

  • Search for each unfamiliar function or hook in the official documentation. For WordPress, the developer reference. For other tools, their docs.
  • If the code mentions a plugin or library, check that it really exists and is maintained.
  • Look at the version. A snippet written for an old release may behave differently now.

What it looks like when it goes wrong: an error such as “call to undefined function”, or code that runs and quietly does nothing.

Mistake 2: skipping security

Beginner-level code, whether from a human or a bot, often forgets security. In WordPress, that means not cleaning input that comes from users and not escaping output that goes to the page. Both can open the door to attacks.

A small example. This prints a value without escaping:

echo '<p>' . $title . '</p>';

The safer version escapes it first:

echo '<p>' . esc_html( $title ) . '</p>';

If $title came from a form or a URL, the first version could let someone inject their own code into your page.

What to check:

  • Anywhere the code accepts user input, does it sanitise it?
  • Anywhere it prints data, does it escape it?
  • Does it use nonces or capability checks before doing admin actions?
  • Does it include passwords, API keys or secrets in plain text? It should not.

You can ask the chatbot: “Review this code for security problems”, and then verify what it says. It helps, though it does not replace your own judgement.

Mistake 3: doing more than you asked

Code can have side effects you did not request. It might delete files, overwrite data, change a setting site-wide or send information somewhere. Often this is not malicious. The model simply solved the problem in a heavy-handed way.

What to check:

  • Read for words like delete, unlink, DROP, UPDATE, rename, remove and overwrite.
  • Look for any network calls to addresses you do not recognise.
  • Check whether the code changes things globally when you only needed a local change.
  • In scripts, add a dry-run mode that only prints what would happen.

If you do not understand a line that touches files or the database, stop and ask the chatbot to explain it. If the explanation does not satisfy you, do not run it.

Mistake 4: it works for the example and nowhere else

AI code often handles the simple case you described and falls apart on the others. Empty values, strange characters, huge files, missing fields, a second user. Because the code looks complete, you do not notice what it does not handle.

What to check:

  • What happens with empty input?
  • What happens when a value is missing or unexpected?
  • What if the list has one item? Or ten thousand?
  • Does it handle errors, or does it crash with no message?

Try to break it on purpose. Feed it the awkward cases before your visitors do.

Mistake 5: testing on the live site

This one is about you, not the code. The biggest damage from AI code happens when someone pastes it straight into a live site. One missing bracket in a PHP file can take the whole site down with a white screen.

What to do instead:

  1. Take a backup before you touch anything.
  2. Use a staging copy or a local test site.
  3. Use a snippets plugin rather than editing your theme’s functions file. Most of them catch fatal errors and switch the snippet off before the site crashes.
  4. Add one change at a time.
  5. Know how to undo it, including how to get into the site if the dashboard is unreachable (through your host’s file manager or SFTP).

I made a similar point in using ChatGPT to write your first automation script: test on copies, then run it for real.

A quick review routine

Before running any AI-written code:

  1. Read it once from top to bottom.
  2. Ask the chatbot to explain it line by line.
  3. Look up any function or setting you do not know.
  4. Scan for anything that deletes, overwrites or sends data.
  5. Check security: sanitise input, escape output.
  6. Test on a copy, with awkward input.
  7. Keep a record of what you added and when.

That last step helps later. When something breaks, “what changed?” is the first question, and a note answers it.

A fair point about human code

Human-written code has these problems too. Forum answers can be out of date, tutorials can skip security and developers make mistakes. The difference is that AI output arrives fast, with high confidence and in volume. That makes it easy to accept things without checking. The review habits are the same ones you would apply to anyone, just applied more consciously.

When not to use AI code

I would be cautious, or ask someone experienced, when the code:

  • Handles payments or personal data.
  • Touches login or user roles.
  • Changes the database in bulk.
  • Runs on a schedule and affects many sites.

These are places where a mistake is expensive.

Key takeaways

  • Check that functions and libraries exist and match your version.
  • Make sure input is sanitised and output is escaped.
  • Look for deletions, overwrites and unexpected network calls.
  • Test awkward cases, not only the happy path.
  • Never test on a live site without a backup and a way to undo.

What is the first thing you check when someone hands you code you did not write?