Describing programming tasks, errors and context
Write a coding prompt that states the environment, inputs, expected behaviour, constraints and the exact error.
You do not need to be a programmer
Many people use AI to write small scripts, spreadsheet formulas or automation steps. The same prompting principles apply — but code has an extra property: it either runs correctly or it does not, so you can (and must) test it.
What a good coding prompt contains
- Goal in plain language — what the code should achieve and for whom.
- Environment — language and version, tools, libraries, operating system, spreadsheet app. "Python 3.12, standard library only" or "Google Sheets formula".
- Inputs — what the data looks like, ideally with a small fake sample.
- Expected output — exactly what should happen or be produced, with an example.
- Constraints — performance, no external services, style rules, must not modify the original file.
- What you have tried — and what happened.
Example:
Goal: Combine monthly CSV exports into one file for a yearly report.
Environment: Python 3.12, standard library only, Windows.
Input: 12 files named sales-01.csv … sales-12.csv in one folder.
Each has the header: date,product,quantity,price
Expected output: one file all-sales.csv with the same header once,
then every row from all 12 files, in month order.
Constraints: do not modify the original files; skip blank lines.
Please explain each part of the code in a short comment.
Debugging prompts
When something fails, give the model what it needs to diagnose the problem:
- the exact error message (copied, not paraphrased) and where it appeared;
- the relevant code — the smallest piece that reproduces the problem;
- what you expected versus what happened;
- what you already tried.
"It doesn't work, fix it" forces guessing. "Running line 14 raises KeyError: 'price'; the CSV header is shown below; I expected the total price per product" points straight at the cause.
Asking for explanations
Code you do not understand is code you cannot maintain or trust. Ask:
- "Explain this function line by line for someone who knows basic Python."
- "What assumptions does this code make about the input? What happens if a file is empty?"
- "What are the risks of running this script?"
Share safely
Never paste passwords, API keys, access tokens, private customer data or proprietary code you are not authorised to share. Replace secrets with placeholders (API_KEY = "YOUR_KEY_HERE") and use fake sample data. Check your organisation's rules on using AI with its code.
Caution with generated code
Generated code can look correct and still: use functions that do not exist, rely on outdated library versions, mishandle edge cases, or do something destructive (overwrite files, delete data). Tomorrow's lesson covers checking it before you rely on it.
Practice exercise
Write a coding or formula prompt for a small real task (a spreadsheet formula, a script that renames files, a simple calculation).
Submit:
- The full prompt with goal, environment, input sample (fake data), expected output and constraints.
- A debugging prompt for a realistic error (real or invented), containing the exact error text and expected vs actual behaviour.
- One question you would ask to have the code explained before you run it.