When GPT returns invalid code: how to fix it

Long-time member of the list and script fanatic Alberto Esteves Correia (name shared with permission) asked:

“Some people think GPT will do everything for them, even if they know nothing about programming or scripting.

When GPT returns invalid code, how to get out of it?”

It’s true: most LLMs still hallucinate a lot when it comes to Google Ads Scripts and often return code that is broken.

Here’s how to fix that and learn some things along the way (works for any LLM):

1. Assign ChatGPT the role of a Google Ads Script developer tasked with debugging the code.
2. Copy-paste the code. Then, ask ChatGPT to explain the code that shows the issue.
3. Copy-paste the error. Then, ask ChatGPT to explain the error message.
4. Ask ChatGPT to fix the code and explain the fix.
5. If a new error message pops up: rinse and repeat steps 2, 3, and 4.
6. If the same error message pops up: 
  6.1: Ask ChatGPT to find supporting documentation on the Google Ads Scripts Developer documentation site.
  6.2: Copy-paste the documentation into ChatGPT.
  6.3: Repeat steps 2, 3, and 4.

If all that doesn’t work, post your issue on the Google Ads Scripts Developer Forum: https://groups.google.com/g/adwords-scripts

Want to learn the exact prompts I use to get the most out of ChatGPT script development?

Sign up for my next 5-Day ChatGPT and Google Ads Scripts Challenge.

Link: https://nilsrooijmans.com/5-day-chatgpt-and-google-ads-scripts-challenge-2025/

– Nils

Author: Nils Rooijmans

Google Ads Performance Architect with a passion for PPC Automation & AI, in particular via Google Ads Scripts.