Skip to content
ChatGPT Wrote My Google Apps Script; Here's Why It Broke in Production

ChatGPT Wrote My Google Apps Script; Here's Why It Broke in Production

20 October 2025
#Automation#AI#Google Apps Script#ChatGPT

The Experiment

I wanted to test something. A client needed a common automation: scan Gmail for invoices, extract the attachments, save them to the correct Google Drive folder based on the sender, and log everything in a Google Sheet.

Standard stuff. I’ve built versions of this dozens of times.

So I asked ChatGPT to write it. The prompt was clear, the requirements were specific, and the code came back fast. Clean. Well-commented. It even had error handling.

I deployed it. It ran perfectly; for about 3 days.

Then Monday morning happened.


Problem 1: The Quota Wall

Google Apps Script has daily quotas. Every Google Workspace account has limits on how many emails you can read, how many files you can create, and how many script executions you can run per day.

ChatGPT’s code called GmailApp.getInboxThreads() on every run with no pagination, no batching, and no state tracking. On a quiet Friday, that was fine; 30 emails, no drama. On Monday morning, with 200+ emails after the weekend? The script hit the daily quota before 10am and stopped dead.

What production code needs: Batch processing with a state marker (tracking the last processed email ID), pagination to handle volume spikes, and graceful degradation when approaching quota limits. This isn’t complex, but it requires knowing the quotas exist, and knowing the real-world email patterns that trigger them.


Problem 2: The Shared Drive Blind Spot

The AI used DriveApp.createFile() to save attachments to Drive. This works perfectly for personal Google Drive.

The client’s team uses a Shared Drive.

Shared Drives have a completely different permissions model and require a different API approach. DriveApp doesn’t fully support Shared Drives; you need the Advanced Drive Service with supportsAllDrives: true parameters.

The script didn’t throw an error. It just… didn’t save the files. No crash, no warning, no log entry. Files silently disappeared into the void.

The client didn’t notice for two days. Invoices went missing.

What production code needs: Detection of the Drive type (personal vs. shared), the correct API calls for each, and; critically; verification that the file actually saved successfully before logging it as complete.


Problem 3: The Silent Trigger Death

Google Apps Script’s time-based triggers have a little-known behaviour: they can stop firing without warning. Triggers can be invalidated by permission changes, script updates, or Google’s own maintenance. There’s no notification when this happens.

ChatGPT set up the trigger correctly. But it didn’t build any monitoring. After 6 days, the trigger stopped. The script sat there, doing nothing, while the client assumed their invoices were being sorted.

What production code needs: A self-monitoring system. This could be as simple as a daily “heartbeat” check; a separate trigger that verifies the main automation ran successfully in the last 24 hours and sends an alert if it didn’t. It could also be a dashboard in a Google Sheet that shows the last successful run time.


Problem 4: The Encoding Trap

Some of the client’s invoices came from European suppliers with special characters in filenames; accents, umlauts, non-ASCII characters. ChatGPT’s code passed filenames directly to DriveApp.createFile() without sanitising them.

Most of the time, Google handles this fine. But occasionally, a filename with certain character combinations would cause a silent failure or create a file with a garbled name that couldn’t be found later.

What production code needs: Filename sanitisation that strips or replaces problematic characters, plus a logging system that records both the original filename and the sanitised version so nothing gets lost.


Why This Happens

None of these problems are ChatGPT’s fault. They’re not bugs in the AI. They’re gaps in the AI’s experience.

ChatGPT can write syntactically correct Google Apps Script. It knows the API methods, it understands JavaScript, and it can structure code logically.

What it can’t do:

  • Know your volume. It doesn’t know your client gets 200 emails on Monday morning.
  • Know the edge cases. Shared Drives, trigger expiry, encoding issues; these come from years of deployment experience, not documentation.
  • Build for failure. Production automation needs to assume things will break and handle it gracefully. AI writes for the happy path.
  • Monitor itself. A script that works today needs to be watched to make sure it’s still working next month. AI doesn’t think about ongoing operations.

The code AI writes is the first 80%. It looks right, it runs in testing, and it handles the obvious cases.

The last 20%; quota management, edge case handling, monitoring, self-healing, and operational resilience; is where the value actually lives. That 20% is the difference between a demo and a system.


What I Actually Delivered

The final automation I built for this client:

  • Batch processes emails with state tracking, handling up to 500 emails per run without hitting quotas
  • Detects Drive type automatically and uses the correct API for personal and shared drives
  • Verifies every file save before logging it as complete
  • Sanitises filenames and maintains an audit trail
  • Self-monitors with a daily heartbeat check and email alert if anything stops
  • Handles errors gracefully; if one email fails, it skips it, logs the error, and continues with the rest
  • Has been running reliably for over a year with zero manual intervention

The core logic? Maybe 40 lines. The production hardening? Another 150 lines.

That’s the job.


The Takeaway

If you’ve asked ChatGPT to write you a Google Apps Script and it “mostly works,” you’re not imagining the problems. AI-generated automation is a brilliant starting point. But deploying it in a business without the production hardening is like buying a car engine and expecting it to drive itself.

The engine matters. But so do the brakes, the dashboard warning lights, and the mechanic who knows what that weird noise means.


Got a Script That “Mostly Works”?

At Empower Automation, we specialise in taking automations from “it runs in testing” to “it runs the business.” Whether you need to fix an AI-generated script, replace a flaky Zapier workflow, or build something from scratch, we build Google Apps Script solutions that work reliably, not just today, but next year.

Book a free 15-minute automation audit →

Send us your script, tell us what it’s supposed to do, and we’ll tell you what’s likely to break, and what it would take to make it bulletproof.


Nicola Berry is the founder of Empower Automation, based in Falkirk, Scotland. Over 80,000 hours of manual work saved for clients through bespoke Google Apps Script development.

Google Workspace

Professional Email & Tools for Your Business

Get you@yourcompany.com, plus video meetings, secure cloud storage, and the powerful admin controls you need to scale. Same tools I use to build your automations.

Custom business email
Secure file sharing & collaboration
Security and management controls