Kestrel Exams kestrel logo KESTREL EXAMSPRACTICE TO PASS
Using AIModule 08 of 1018 min of readingFree, no account

Coding with AI, even if you are not a programmer

You do not need to be a programmer to get a formula, a small script or an automation from an AI assistant. You do need to check it. This module shows how to describe the job, test the result on rows you can work out by hand, and keep your passwords out of it.

Course overview →Support Kestrel Exams

Start here: a formula is a set of instructions#

If you have ever left a note for someone covering your shift ("count the till, lock the back door, text me the total"), you have written a program. Code is a set of instructions written so precisely that a computer can follow them without asking what you meant.

A spreadsheet formula such as =SUM(C2:C20) is code. So is a script, a small program that does one job, such as renaming 200 photos. So is an automation, a rule that runs by itself, such as "every Monday, email me last week's total".

AI assistants are good at writing all three. Here is the one new part. When you wrote the shift note, you knew what you meant. When an AI writes the instructions, you have to find out whether they mean what you meant. That checking is what this module teaches, and you do not need to be a programmer to do it.

Our running example. Gloria runs a small home bakery that sells to five local cafes. Every Monday she updates a sales sheet: which cafe ordered, the invoice amount, when it went out and when it was paid. She wants AI help with two jobs: a column that works out late fees, and later a small script that emails payment reminders. Everything in her sheet is made up, and a pencil is all you need to follow along.

Describe the job: inputs, output, an example, edge cases#

Try it first

Gloria's first prompt is Write me a late fee formula. Before you read on, list three things the AI will have to guess.

Show the answer

Which columns hold the dates and amounts. How many days counts as late. How big the fee is, and whether there is a minimum. What happens to invoices not paid yet. Which spreadsheet app she uses. The AI will guess all of these, usually without saying so.

An AI fills every gap in your request with a guess. A wrong guess produces a formula that works perfectly on a rule you never had. Four parts describe almost any formula or script:

PartWhat it meansGloria's version
InputsWhat it reads, and exactly whereColumn B: invoice date. C: amount in dollars. D: date paid. Data starts in row 2.
OutputWhat you want back, in what formThe fee in dollars in column E, or 0
The rule, with an exampleThe rule in plain words, plus one worked caseDue within 14 days. If late, 2% of the amount, never less than $5. Example: $400 paid after 24 days: $8.
Edge casesThe unusual rows at the limits of the rulePaid exactly on day 14 is on time.

An edge case is an unusual input at the limit of a rule: a blank cell, a zero, a value exactly on a boundary. Most mistakes in code live there, and it is the part people forget to describe. Gloria's second prompt:

I use Google Sheets. Write a formula for cell E2 that I can copy down the column.
Inputs: B2 is the invoice date, C2 is the amount in dollars, D2 is the date it was paid.
Output: the late fee in dollars, or 0 if there is no fee.
Rule: payment is due within 14 days of the invoice date. If it is paid later than that,
the fee is 2% of the amount, but never less than $5.
Example: an invoice for $400 paid 24 days after the invoice date has a fee of $8.
Edge case: paid exactly 14 days after the invoice date is on time, so no fee.
Give me the formula, then explain each part in plain words.

It names the app, because formulas differ a little between apps, and it asks for an explanation, which you will need soon. It still has a gap Gloria does not see; the next section's test finds it.

Try it with any AI assistant: one vague prompt, one precise prompt

Open two new chats in any free assistant, such as ChatGPT, Claude, Gemini or Copilot. Paste Write me a late fee formula. into the first and Gloria's full prompt into the second.

What to look for: Did the vague reply ask you questions, or quietly pick columns, days and a fee? Did either say what happens to an invoice that has not been paid at all?

Run it, do not trust it: a worked example#

Here is the formula Gloria got back:

=IF(D2-B2>14, MAX(C2*0.02, 5), 0)

IF chooses between two answers: if the test is true, the first; otherwise the second. Spreadsheets store each date as a count of days, so D2-B2 is the number of days it took to pay. MAX gives the larger of its inputs, so MAX(C2*0.02, 5) is "2% of the amount or $5, whichever is bigger". In words: if it took more than 14 days, charge that; otherwise charge 0.

It looks right, and that is exactly the code that needs testing: nothing about it looks wrong.

A test row is a row whose right answer you already worked out by hand. You choose them on purpose: a few ordinary rows plus the edge cases. Gloria made five:

CafeInvoice dateAmountPaid dateDays taken
Corner CafeSep 1, 2026$400Sep 10, 20269
Bean ThereSep 1, 2026$400Sep 25, 202624
Daily GrindSep 1, 2026$150Sep 20, 202619
HilltopSep 1, 2026$600(blank: not paid yet)still waiting, weeks later
Mill StreetSep 1, 2026$300Sep 15, 202614
Try it first

Work out the right fee for each row by hand: due within 14 days; if late, 2% of the amount, never less than $5. Then read the formula again and predict: will it get every row right? Look hard at the row with the blank.

Show the answer

Corner Cafe, 9 days: on time, $0. Bean There, 24 days: 2% of $400 is $8. Daily Grind, 19 days: 2% of $150 is only $3, so the minimum, $5. Hilltop, unpaid and long overdue: 2% of $600 is $12. Mill Street, exactly 14 days: on time, $0. And no, the formula will not get them all right. If you suspected Hilltop, you found the bug before the spreadsheet did.

Here is what the formula gave when we ran it in a real spreadsheet:

CafeRight fee (by hand)Formula saysMatch?
Corner Cafe$00Yes
Bean There$88Yes
Daily Grind$55Yes
Hilltop$120No
Mill Street$00Yes
Try it first

You may already have a guess. Why does the formula charge Hilltop nothing?

Show the answer

Hilltop's paid-date cell is blank, and in arithmetic a spreadsheet treats a blank cell as 0. In the date system most spreadsheets use, September 1, 2026 is day 46,266, so "blank minus September 1" is about minus 46,266 days. That is not more than 14, so the formula calls it on time. The one cafe that has not paid is the one cafe never charged. That was the gap in Gloria's prompt, and the AI never asked about it.

Trap: a blank cell counts as zero

In spreadsheet arithmetic an empty cell behaves like 0, with no warning. Any formula that subtracts, multiplies or divides using a cell that might be empty needs a test row with that cell left empty.

Gloria described the missing edge case in the same chat. Unpaid invoices have a blank paid date, and they must get the fee once they are more than 14 days old. The new version:

=IF(IF(D2="", TODAY(), D2)-B2>14, MAX(C2*0.02, 5), 0)

Only one piece changed. IF(D2="", TODAY(), D2) means: if the paid date is blank, use today's date instead. She then re-ran all five rows, not just Hilltop: 0, 8, 5, 12, 0. Every row matched. Re-run every test after a fix, because a change that repairs one row can quietly break another.

Try it first

Suppose the AI had written >= (more than or equal to) instead of >. Which test row catches it?

Show the answer

Mill Street, paid on exactly day 14. With >=, 14 days passes the test, so the formula charges 2% of $300, which is $6, though the rule says day 14 is on time. Without a row sitting right on the boundary, nobody would notice.

Where this formula works

We ran both formulas on this page in LibreOffice Calc, a free spreadsheet app. They use only IF, MAX and TODAY, standard functions documented for Microsoft Excel and Google Sheets (see Sources). If your spreadsheet uses a comma as the decimal mark, it may want semicolons between the parts instead of commas, and 0,02 instead of 0.02.

Notice that the right answers came from Gloria's pencil. Answers from the AI would carry the same misunderstanding as its formula, and every row would "pass".

From our own work: the bundle that was four files short

Kestrel Exams is a small study site built by one person working with an AI assistant. Before each site update, a script packs the site's files into a bundle and checks them. One bundle had 47 files when the folder had 51. The script reported "47/47 verified", and it was right about the 47 it had been given. It checked the bundle against itself, not against the folder. We caught it only because the count looked wrong. Rule: a check that compares something to itself proves nothing. Count the real source.

Read every line you can, and ask about the rest#

Try it first

Gloria cannot read code. Name one thing in her fixed formula she can still check.

Show the answer

The numbers and letters: 14 for the days, 0.02 for 2%, 5 for the minimum, and columns B, C and D. If any were wrong, she would spot it with no knowledge of formulas at all.

Testing covers the rows you tried. Reading covers the rows you did not, and it does not need fluency.

  • Read every part you can: numbers, column letters, words you recognize.
  • Ask about every part you cannot. "What does D2="" do?" is a good question. If a part cannot be explained in plain words, treat that as a warning.
  • Explain it back. Say what you think it does in your own words, then ask whether you are right.
  • Get a second opinion from something that did not write it. A fresh chat does not remember writing the code, so it has nothing to defend.
From our own work: the independent reviewer

We had an AI write six new study guides about the Java programming language. Then we gave each one to a separate AI reviewer that had not written it, with instructions to re-run every code example and check every claim. All six came back "ship after fixes". One guide said mixing up = (set a value) and == (compare two values) in an if-test always stops the program before it runs. In fact, with a true-or-false variable (a named value the program stores) it runs without complaint and does the wrong thing: the classic exam trap. Another said "every declaration (a line that creates a variable) has five parts"; int x; has three. Every code listing on those pages is compiled and run by a script, so the output shown is real, not typed. Rule: the writer is the worst checker of its own work.

Try it with any AI assistant: ask a fresh chat what would break it

Open a new chat and paste this:

Here is a spreadsheet formula and the rule it should follow.
Formula for E2: =IF(IF(D2="", TODAY(), D2)-B2>14, MAX(C2*0.02, 5), 0)
B2 is the invoice date, C2 the amount in dollars, D2 the date paid (blank if unpaid).
Rule: due within 14 days; if late, the fee is 2% of the amount, never less than $5.
Do not rewrite it yet. List inputs that would make it give a wrong or confusing answer,
and for each one give me a test row I can check by hand.

What to look for: We ran the likely suggestions ourselves. A paid-date cell holding a space, or the word "unpaid", gives the error #VALUE!, which at least is visible. An amount of $333.33 gives a fee of 6.6666, because nothing rounds to cents. Anything else it suggests, build that row and run it: a suggestion is not a result until you have tested it.

Four ways AI code goes wrong#

Try it first

Gloria's formula passed four of five rows and failed at an edge. Before you read on, guess one way AI code can go wrong that no test row would show.

Show the answer

A password written into the code. An instruction to install a package that does not exist. Code written for a different version of the app. Test rows check what the code calculates; they do not check what it installs, where it sends your data or which version it expects.

Gloria's formula failed in a classic way. Three others are worth knowing by name.

FailureWhat it looks likeHow to catch it
Right-looking, wrong at the edgesWorks on ordinary rows, fails on a blank, a zero or a boundaryTest rows chosen on purpose: blank, zero, exactly on the line, something odd
Invented namesA function or setting that does not exist, or a package (a bundle of ready-made code you install) that nobody publishedLook the name up in the official documentation or package list before you use it
Out-of-date waysCode written for an older or newer version of your app or languageName your app and version. If it errors, paste the exact error message back
Security holesA password typed into the code; code that trusts whatever a user typesAsk "What are the security risks in this code?" and keep secrets out

Researchers have measured two of these: security holes and invented names. In one study, an AI coding tool completed 89 small tasks chosen because they are easy to get wrong in ways an attacker could use. About 40% of the 1,689 programs it produced had such a weakness. A second study gave 47 people security-related coding tasks, some with an AI assistant and some without. Those with the assistant wrote less secure code overall and were more likely to believe it was secure. On one task, 3% of people with the assistant wrote a secure answer, against 21% without. These were small groups: 33 people with the assistant and 14 without. The danger is not only the code; it is the confidence.

A third study generated 576,000 code samples from 16 AI models and checked every package name the models suggested. On average, at least 5.2% of package names from commercial models did not exist. For open-source models, which anyone can download and run, it was at least 21.7%. Anyone can publish a package under a name AIs tend to invent. Whoever installs it after that is running a stranger's code on their own computer.

Try it first

An AI script tells Gloria to install a package called easy-invoice-mailer. She has never heard of it. What should she check first?

Show the answer

That it exists in the official package list for her language, with exactly that spelling, and that real people use and maintain it. If not, she can ask for a version with no extra package.

These studies are a few years old

They tested AI tools from 2021 to 2024. Newer tools may do better on some measures. Testing works whichever tool you use.

Keep passwords and keys out of prompts and code#

Gloria's second job is a script that emails each cafe a polite reminder when an invoice is overdue. The AI's draft looks complete, and near the top is a line like this:

password = "type-your-email-password-here"
Try it first

Gloria types her real password between the quotes. The script fails, so she pastes it back into the chat to ask why. What went wrong before the script even ran?

Show the answer

Her password is now in the chat history, and in every copy of that script she saves or shares. The AI never needed it to find the bug.

A secret is anything that lets someone act as you, such as a password or an API key. An API key is a long code that lets a program use an online service on your account. Inside the code, a secret travels wherever the code goes: chat history, a shared file, a screenshot, a public code site.

  • Never paste a real password or key into a chat. Replace it with a placeholder such as PASSWORD_HERE first. The AI does not need the real one to help.
  • Keep secrets out of the code. Ask: "Change this so the password is read from an environment variable." An environment variable is a named value stored on your computer, outside the file. In the Python language the line becomes:
import os
password = os.environ["BAKERY_MAIL_PASSWORD"]
  • If a secret was pasted or shared, change it now. Deleting the message does not undo copies that may already exist.
  • Use made-up data. Gloria tests with invented cafes and her own email address, not her customer list. Rows with the same shape test the code just as well.
Trap: the screenshot and the shared link

People who would never paste a password will share a screenshot of their code, or a link to the whole chat. A secret visible in either one has been shared.

Anything you paste into a chat leaves your computer and may be stored. Check the service's privacy policy, and at work, your employer's policy on what you may share.

If you are learning to code: write it first#

Gloria does not want to become a programmer, so letting the AI write her formula was the right call. If your goal is to learn to code, the trade is different: when the AI writes the code, it also does the part that teaches you.

Try it first

Which teaches you more: reading the finished code carefully, or writing a rough attempt, getting it wrong, then asking for a hint?

Show the answer

The rough attempt. Reading a finished answer feels like understanding. You find out whether you understood only when you try to write it, and the spot where you get stuck is the thing you needed to learn.

  1. Write your own attempt first, even if it is wrong or unfinished.
  2. Run it and read the error message.
  3. Ask for a hint, not the answer: Here is my code and the error I get. Do not give me corrected code. Ask me one question that points me toward the bug.
  4. Ask for a review once it works: "What would a careful reviewer change, and why?"

Module 5 covers learning with AI in full. Before you use AI on graded coding work, check your school's or course's policy; the rules differ from class to class.

When the AI can edit files or run commands#

Some AI tools can open your files, change them, or run commands. A command is an instruction typed to the computer itself, such as "delete this folder". A tool that acts for you like this is often called an agent. Module 4 covers agents in full. For coding work, four rules do most of the protecting.

RuleWhat it means for Gloria
Back up firstBefore any tool edits her sales sheet, she saves a copy with the date in its name.
Least permissionAccess to only what the job needs: one sheet, not her whole drive; permission to look, not change, when it only needs to look.
Try it on a copyThe tool works on the copy first. She checks the result, then repeats it on the real sheet.
Review before you approveShe reads what the tool says it will do, and clicks on a few real cells herself, before saying yes.
Try it first

An AI tool tells Gloria: "I found no formulas in your sheet, so I will replace the totals with typed numbers." Should she say yes?

Show the answer

Not yet. "Found none" describes the search, not the sheet. She should click a few total cells herself and see what is really in them.

From our own work: zero results

Our AI assistant searched a spreadsheet for formulas and found zero. So it nearly overwrote the sheet's live formulas with typed totals. The sheet was full of formulas; the search pattern had been too narrow to match them. Rule: "none found" is a claim about the search, not about the file. Look at a raw sample of the real thing before acting on it.

Module 4 tells our worst moment with an agent: a helper our AI named for "read" that the computer took as "delete", and four record files gone.

What was new in this module#

  1. Formulas, scripts and automations are all code.
  2. Describe the job: inputs, output, the rule with an example, edge cases.
  3. Test on rows whose answers you worked out yourself: a blank, a boundary, something odd.
  4. A blank cell counts as zero in spreadsheet arithmetic.
  5. After any fix, re-run every test.
  6. Read what you can, ask about the rest, and ask a fresh chat what would break it.
  7. Four failures: wrong at the edges, invented names, out-of-date ways, security holes.
  8. Secrets never go into prompts, shared code or screenshots. If one leaks, change it.
  9. Learning to code: run your own attempt and read the error before you ask for a hint.
  10. When a tool reports "none found", check the real file before you let it act.
One sentence to carry with you

Run it on rows you can check by hand before you trust it. Code from an AI is a confident first draft. Test rows whose answers you worked out yourself, including the blank and the boundary, turn it into something you can rely on.

Key terms#

Code
Instructions precise enough for a computer to follow. A spreadsheet formula counts.
Edge case
An unusual input at the limit of a rule: a blank cell, a zero, a value exactly on a boundary.
Test row
An input whose right answer you worked out yourself.
Package
A bundle of ready-made code that someone publishes for others to install.
Secret
Anything that lets someone act as you, such as a password or an API key.
API key
A long code that lets a program use an online service on your account.
Environment variable
A named value stored on your computer, outside your code, so a secret is not written in the file.
Agent
An AI tool that takes actions for you, such as editing files or running commands.
Least permission
Giving a tool access to only what its job needs.

Check yourself#

Answer each one out loud before you open it. Reading the answer without trying first feels like learning and is not.

1. A coworker says: "I asked the AI to check its own formula, and it said it is correct." What is missing?

An independent check. The AI judged the formula by its own understanding, so the same mistake passes. Work out a few answers by hand, including a blank and a boundary.

2. Gloria's formula is right on all twenty rows of last month's real data. Is it tested?

Not necessarily. If last month had no unpaid invoice and nothing paid on exactly day 14, the two cases that matter most were never tried.

3. An AI tells you to install a package you have never heard of. What do you do first?

Look it up in the official package list for your language, check the exact spelling, and see whether real people use it. AIs sometimes invent package names.

4. You pasted a script holding a real API key into a chat yesterday, then deleted the chat. Are you safe?

Treat the key as exposed and change it now. Deleting a message does not undo copies that may exist.

5. An AI tool offers to "clean up every formula in your shared drive". What do you set up before saying yes?

A backup; access to one file, not the whole drive; a trial run on a copy; and a look at the proposed changes. If it reports "nothing found", check the file yourself.

I can#

Tick each one only when you could do it tomorrow without this page open.

  • I can describe a formula or script job in four parts.
  • I can build test rows, including a blank and a boundary, and work out their answers by hand.
  • I can find which row a formula gets wrong and explain why in plain words.
  • I can name four common ways AI code goes wrong and how to catch each one.
  • I can keep passwords and API keys out of prompts, shared code and screenshots.
  • I can set up a backup and least permission before an AI tool edits my files.

Frequently asked questions#

Can AI write spreadsheet formulas for Excel or Google Sheets?

Yes, often well. Tell it your app, your columns, the rule with one worked example, and unusual cases such as blank cells. Then test it on rows where you know the right answer.

Is code written by AI safe to use?

Not automatically. Studies have found security weaknesses in a large share of AI-generated code. Test it, ask what the security risks are, and keep passwords out of it.

Do I need to know how to code to use AI for coding?

No, but you need to check the result. Describe the job precisely, test it on inputs whose answers you know, and ask the AI to explain any part you do not understand.

Is it safe to paste a password or API key into an AI chatbot?

No. Anything you paste leaves your computer and may be stored. Use a placeholder instead, keep secrets outside the code, and if you already pasted one, change it right away.

Should I use AI when I am learning to code?

Yes, as a tutor rather than a ghostwriter. Write your own attempt first, then ask for a hint or a review. Check your course policy for graded work.

This course is free, with no ads and no account. If it helped you, you can help keep it that way.

Support Kestrel Exams →

Sources#

Pearce, H., Ahmad, B., Tan, B., Dolan-Gavitt, B. and Karri, R. (2022). Asleep at the Keyboard? Assessing the Security of GitHub Copilot’s Code Contributions. IEEE Symposium on Security and Privacy 2022 (preprint arXiv:2108.09293). 89 scenarios, 1,689 programs, about 40% vulnerable.

Perry, N., Srivastava, M., Kumar, D. and Boneh, D. (2023). Do Users Write More Insecure Code with AI Assistants? ACM Conference on Computer and Communications Security (CCS 2023), doi:10.1145/3576915.3623157. 47 participants; message-signing task: 3% secure with an AI assistant, 21% without.

Spracklen, J., Wijewickrama, R., Sakib, A. H. M. N., Maiti, A., Viswanath, B. and Jadliwala, M. (2025). We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs. USENIX Security Symposium 2025 (preprint arXiv:2406.10279). 576,000 samples, 16 models; at least 5.2% (commercial) and 21.7% (open-source) of suggested packages did not exist.

Microsoft Support. IF function (Excel). Checked October 2026.

Microsoft Support. TODAY function and MAX function (Excel). Checked October 2026.

Google. IF function, MAX function and TODAY function, Google Docs Editors Help (Google Sheets). Checked October 2026.