Lesson 15 of 16 · Level 4: Expert
Coding with AI for Non-Programmers: Method, Testing and Security
- ⏱ 13 min read
- ❓ 4 review questions
- ✍️ Exercise with solution
In this lesson
- Know which tools you can build with AI's help even if you're not a programmer.
- Apply a six-step method to go from an idea to a program that works.
- Test and fix AI-generated code with edge cases.
- Avoid the security and data risks of running generated code.
- Calculate how much time a tool saves you and know when to hand it to a developer.
AI assistants write code surprisingly well. That opened a new door for every professional: building small tools tailored to their own work (a complex formula, a macro, a script that organizes files, an automatic report) without waiting on IT. But "asking AI for code" and "having a reliable tool" aren't the same thing. The difference is the method, and that's what you'll learn today.
What you can build
Advanced formulas
A formula that tiers customers based on three conditions.
Where: Excel or Google Sheets.VBA macros
Formatting a report, splitting one workbook into several files.
Where: desktop Excel.Apps Script
Sending an email when a row's status changes, generating documents from a sheet.
Where: Google Sheets, Docs and Gmail.Python scripts
Renaming hundreds of files, merging reports, flagging overdue invoices.
Where: your computer.Simple web pages
A quote calculator, an internal form.
Where: the browser.You can use any assistant's chat, coding assistants built into code editors (such as GitHub Copilot or Cursor) or agents that work directly on a project's files (such as Claude Code or Codex; lesson 9). To start, the chat is enough.
Big tech teams have already embraced it. In October 2024, Google CEO Sundar Pichai said that more than a quarter of all new code at Google was being generated by AI, then reviewed and accepted by engineers. Notice the second half of that sentence: reviewed and accepted. For you, at a smaller scale, the promise is the same: less time writing code, as long as you spend time testing it.
The six-step method
1. Describe the problem with sample data
Nothing improves generated code more than showing the exact input and the output you expect. A complete prompt:
I need a Python script to flag overdue invoices.
INPUT: a CSV like this (the columns are always the same):
number,client,issue_date,credit_days,amount,paid
INV-102,Lakeview Offices,2026-08-20,30,850.50,no
INV-103,Hotel Marisol,2026-09-05,15,640.00,no
RULES: an invoice is due on issue_date + credit_days. It's overdue
if it isn't paid and that date has passed.
OUTPUT: a list of overdue invoices sorted by days late (number,
client, due date, days late and amount) and, at the end, the total
overdue per client.
CONTEXT: I'm not a programmer. I use Windows and Python 3.12. I can
only use the standard library. I want to run it like this:
python overdue.py invoices.csv, with an optional date for testing.
2. Ask for the plan before the code
"Before writing any code, explain in 5 steps how you'll solve this and what assumptions you're making." That way you catch misunderstandings while they're cheap to fix: for example, if the AI assumes credit days are business days rather than calendar days.
3. Ask for readable code and instructions to run it
Ask for clear names, short comments, small functions and exact steps to run it. A typical result, already tested:
"""List overdue invoices and the total owed by each client.
Usage: python overdue.py invoices.csv [YYYY-MM-DD]
If you don't pass a date, today's date is used.
"""
import csv
import sys
from collections import defaultdict
from datetime import date, datetime, timedelta
def read_invoices(path):
with open(path, encoding="utf-8") as f:
return list(csv.DictReader(f))
def overdue_invoices(invoices, today):
overdue = []
for inv in invoices:
if inv["paid"].strip().lower() == "yes":
continue
issued = datetime.strptime(inv["issue_date"], "%Y-%m-%d").date()
due = issued + timedelta(days=int(inv["credit_days"]))
if due < today:
overdue.append({**inv, "due": due, "days_late": (today - due).days})
return sorted(overdue, key=lambda x: x["days_late"], reverse=True)
def main():
if len(sys.argv) < 2:
print(__doc__)
sys.exit(1)
today = (datetime.strptime(sys.argv[2], "%Y-%m-%d").date()
if len(sys.argv) > 2 else date.today())
overdue = overdue_invoices(read_invoices(sys.argv[1]), today)
by_client = defaultdict(float)
for inv in overdue:
print(f"{inv['number']} {inv['client']:<18} due {inv['due']} "
f"{inv['days_late']:>3} days {float(inv['amount']):>9,.2f}")
by_client[inv["client"]] += float(inv["amount"])
print("\nTotal overdue by client:")
for client, total in sorted(by_client.items(), key=lambda x: -x[1]):
print(f" {client:<18}{total:>10,.2f}")
if __name__ == "__main__":
main()
4. Test with data you know
Prepare a small file where you know the right answer. With five invoices, of which you know only INV-102 and INV-103 are overdue as of October 31, 2026:
python overdue.py invoices.csv 2026-10-31
INV-102 Lakeview Offices due 2026-09-19 42 days 850.50
INV-103 Hotel Marisol due 2026-09-20 41 days 640.00
Total overdue by client:
Lakeview Offices 850.50
Hotel Marisol 640.00
It matches. Now the edge cases: what if someone typed "Y" instead of "yes" in the paid column? The script compares against "yes," so it would treat that invoice as unpaid and report it as overdue. That's the kind of error the AI can't guess, because it doesn't know your real data. Always test with: blank cells, "Y," "Yes" and "Paid" variants, dates in U.S. format (09/15/2026), amounts written as "$1,250.00" and a file with no rows.
1. What's the best way to confirm that an AI-generated script works?
AI can say its code is correct when it isn't. Only a test with known results proves it.
2. With the original script, an invoice issued 2026-08-01, with 30 credit days and "Y" in the paid column, is checked on October 31, 2026. What does the script do?
The script lowercases the value and compares it with "yes": "y" doesn't match, so the invoice is treated as unpaid. It was due August 31 and gets reported 61 days late. That's a silent error: no error message, just a wrong result.
5. Fix it with the exact error
When something fails, paste the complete error message into the chat along with what you were doing. "It doesn't work" doesn't help; this does:
Running it on the real file, I get this error:
ValueError: time data '09/15/2026' does not match format '%Y-%m-%d'
In the real file, some dates look like 09/15/2026 and others like
2026-09-15. Also, the paid column contains "yes", "Y" and "Paid", and
some amounts are written as "$1,250.00". Fix all three and tell me
what you changed.
6. Ask for an explanation and a review
Before you rely on it: "Explain what each function does as if I didn't know how to code" and "Review this code like an experienced developer: what could break with real data? Is there any security risk?" Understanding the essentials of your tool lets you maintain it when your needs change.
3. Your script fails. Which message to the AI will get the best result?
The exact error and the data behind it give the AI what it needs to find the cause. Starting over usually repeats the problem.
Security: what never to do (and what to do instead)
Running code on your only copy of the data: a script that moves or deletes files can target the wrong folder.
Always work on a copy, or have a backup before you run it.
Pasting keys and passwords into the code or the chat.
Use environment variables (as in lesson 10) and never share credentials with any assistant.
Pasting confidential data so "the AI can see the problem."
Use made-up sample data with the same structure (lesson 12).
Installing packages you don't know: AI sometimes invents library names, and attackers publish malicious packages under those names.
Check that the package exists, is widely used and is the official one, or ask for a standard-library alternative.
Giving an agent broad permissions without supervision.
Review the changes it proposes before accepting them, especially if it deletes files or sends messages.
Is it worth it? Calculate the savings
Before you invest an afternoon in a tool, do the math: minutes per week × 52 ÷ 60 = hours per year. Three examples:
If building and testing the tool takes you 4 hours, each of these pays for itself within a few months. But count maintenance too: when the report format or the date column changes, you'll have to adjust it.
When to call a developer
Coding with AI is ideal for personal tools or tools for a small team. Get professional help when the tool handles money or customers' personal data, when many people depend on it, when it has to connect to critical company systems or when it must meet security or compliance standards. A prototype you built with AI is also the best way to show a developer exactly what you need.
4. The AI suggests installing a Python package with a name you've never seen. What do you do?
Package names invented by AI can match malicious packages that were published on purpose. Verifying before installing is basic security hygiene.
Practice exercise: your first tool
- Pick a repetitive task from your work that takes at least 30 minutes a week.
- Write the prompt with sample input, rules, expected output and context.
- Ask for the plan, then the code, and test it on a sample file whose answer you know.
- Write 3 edge cases, test them and ask for the fixes you need.
- Calculate how many hours a year it will save you.
See solution
def is_paid(value):
return value.strip().lower() in ("yes", "y", "paid", "true")
def parse_date(text):
for fmt in ("%Y-%m-%d", "%m/%d/%Y"):
try:
return datetime.strptime(text.strip(), fmt).date()
except ValueError:
pass
raise ValueError(f"Unknown date format: {text!r}")
def parse_amount(text):
return float(text.replace("$", "").replace(",", "").strip())
# In overdue_invoices:
# if is_paid(inv["paid"]): continue
# issued = parse_date(inv["issue_date"])
# And in main(), use parse_amount(inv["amount"]) instead of float(...)
With these fixes, "Y" counts as paid, "09/15/2026" is read as September 15 and "$1,250.00" becomes 1250.0. Notice that the date function raises a clear error ("Unknown date format: '15.09.2026'") when it meets a new format, instead of guessing. A script that stops is better than one that quietly delivers a wrong result. Estimated savings: if checking invoices by hand took 45 minutes a week, that's 45 × 52 ÷ 60 = 39 hours a year.
Summary
- With AI you can build formulas, macros, Apps Script, Python scripts and simple web pages without being a programmer.
- The method: sample data, plan first, readable code, tests with known answers, exact errors and a review.
- Edge cases (variants like "Y," blanks, U.S. date and dollar formats) are where generated code breaks.
- Back up your data, keep keys and confidential data out of the chat and verify packages before installing.
- For critical tools, your prototype is the starting point for a developer.
Next lesson: How to Make Money with AI: Services, Pricing and Your First Clients. In the course's final lesson you'll turn everything you've learned into income: services businesses pay for, how to price them and how to land your first clients.
Create your account in 30 seconds, mark your lessons and download your certificate at the end.