Five Small Things to Do Before Asking AI to Write Code for You

小蕾 · AI Coding & Tools · 2026-11-30

Many friends' first attempt at using AI to write code goes like this: they open a chat, type a single line like "help me write a program that organizes files," get a big block of code they can't understand, run it, get an error, paste the error back, get another error... and in the end everything is a bigger mess. The problem is often not the AI, but that nothing was prepared "before starting." Today, Lily shares five small things to do before you begin. Ten minutes of preparation can save you an hour or two.

First: say in one sentence what you actually want

Don't rush to ask. First, write one sentence on paper: what goes in, and what comes out.

For example: "I have a folder with several hundred phone photos, and I want to sort them into subfolders by the month they were taken."

This sentence has an input (a folder of photos) and an output (subfolders sorted by month). Sending this exact sentence to the AI works far better than a vague "organize my photos." If you can't clearly say it yourself, the AI can only guess for you, and the odds of guessing wrong are high.

Second: tell the AI your environment and your level

The same request can be written in many ways. It's best to tell it:

  • Are you using Windows, a Mac, or a phone?
  • Which language do you want to use? If you're not sure, just ask, "What's the simplest language for a beginner to do this?"
  • Your level: for example, "I've never written code before, so please explain every step."

This way, what it gives you is a version you can actually run and understand.

Third: break big tasks into small steps

Don't ask the AI to write "a complete software program" in one go. A better approach is to split it up and do one small step at a time:

  1. First, have it write code that "reads the names of all the photos in the folder." Run it and confirm it works.
  2. Then add "reading the date each photo was taken."
  3. Then add "creating folders by month."
  4. Finally, add "moving the files."

Each step runs and shows you a result, so if something breaks, you know which step went wrong. This is the most important habit when writing code with AI: move fast in small steps, and verify at every step.

Fourth: test on a copy, not the originals

Automation scripts often move, rename, or delete files. Before the first run:

  • Copy the files you're going to process into a test folder, and try the script on the copies.
  • Ask the AI to add a "print only, don't actually execute" dry-run mode, so you can see what it plans to do first.
  • For anything involving deletion, ask it to "confirm with me first."

That way, even if the code has a bug, you won't lose anything important.

Fifth: guard your keys and your privacy

This one is the easiest to overlook, and also one of the most important.

  • Don't paste keys, passwords, or tokens directly into the chat, and don't hard-code them into your code. When you need them, ask the AI to show you how to store them in "environment variables" or a config file, and have your code refer only to the variable name.
  • Before sharing code with others or posting it in a forum for help, check it first: look for account names, passwords, API keys, phone numbers, and internal company addresses.
  • When you ask the AI to look at error messages or data samples, replace real names, phone numbers, and customer information with fake ones before pasting.
  • If you're not sure what a command does, ask the AI first, "What does this command do, and what are the risks?" before deciding whether to run it. Be especially careful with commands that include words like "delete," "format," or "administrator privileges."

A opening template you can copy directly

I want to do one thing: [one sentence describing the input and output].
My computer is [operating system]. I've barely written any code, so please use the simplest method and explain each step.
Please first give me a small version that only does step one. I'll continue once I've run it successfully.
Note: if the task involves changing or deleting files, print out what it will do first so I can confirm.

Replace the bracketed parts with your own details, and you're ready to start.

Let's Talk

What small script have you written with AI recently, or where did you get stuck? Share your experience in the comments, or @Lily directly with your questions. Before asking for help with code, remember to strip out keys and private information first!