This content originally appeared on Level Up Coding – Medium and was authored by Maria Ali
How changing the way I wrote prompts completely transformed my results.
A beginner-friendly Python guide made for non-programmers. Start learning Python the easy way!
I was sitting in front of my laptop, half-empty coffee mug to my right, frustrated because my “AI assistant” had just generated the most painfully irrelevant response for the third time in a row. I had blamed the tool for weeks, thinking maybe it wasn’t smart enough, maybe it needed the “pro” version, or maybe AI just wasn’t as magical as everyone claimed.
Non-members can read for free from here.
But the truth was more uncomfortable: the problem wasn’t the AI, it was me. Specifically, the way I was writing my prompts.
That night, instead of giving up, I decided to debug my prompts the same way I debug Python code. And the difference was night and day.
Why Prompts Are Like Functions
Think about it, writing a prompt is like defining a Python function. If your function accepts vague arguments, don’t expect precise results. I had been feeding the AI instructions that looked more like random thoughts than structured queries.
Here’s one of my early “prompts”:
Write something about data automation
And here’s what I started writing instead, once I treated prompts like code:
You are a Python automation assistant.
I want you to write a script that scans a folder,
detects all CSV files, and merges them into a single Excel file.
Explain your steps clearly and add comments in the code.
The first one is like calling my_function() with no arguments. The second one is a proper function call with typed parameters. Suddenly, the AI had context, constraints, and a target output.
Debugging Prompts with Python Mindset
After that realization, I started experimenting. I wrote prompts as if I were writing test cases. Each one had to be clear, reproducible, and give me the result I expected.
For example, I wanted the AI to generate automation scripts for file handling. Instead of saying:
Give me a Python script to handle files
I learned to frame it like this:
You are a file management expert.
Write a Python script that moves all `.log` files older than 7 days
from the `/logs` directory into `/archive`.
Use pathlib and shutil libraries. Add error handling.
And just like that, the AI produced something useful:
from pathlib import Path
import shutil
import time
logs = Path("logs")
archive = Path("archive")
archive.mkdir(exist_ok=True)
for file in logs.glob("*.log"):
if time.time() - file.stat().st_mtime > 7 * 86400:
shutil.move(str(file), archive / file.name)
The more specific my prompt, the fewer edits I had to make.
Building a Prompt Testing Loop
Like any good developer, I wanted a way to iterate fast. So I hacked together a tiny script that would test my prompts in batches. It wasn’t fancy, but it gave me insight into which phrasing worked best.
import json
from itertools import product
prompts = [
"Summarize this text in bullet points:",
"Give me a structured summary with key insights:"
]
texts = [
"Python is widely used in automation, data science, and web development.",
"Automation reduces manual work and increases efficiency."
]
for p, t in product(prompts, texts):
print("Prompt:", p)
print("Text:", t)
# imagine sending (p+t) to AI API
print("---")
It was almost like A/B testing for prompts. I could instantly see which structures led to the clearest results.
Automating Prompt Refinement
Here’s where it got interesting. I realized I could even use Python to automate the way I refine prompts. By storing my best-performing prompts in a JSON file, I created a reusable “prompt library” for different tasks, summarization, code generation, debugging, and documentation.
{
"summarization": "Summarize this text in bullet points with clarity and conciseness:",
"debugging": "Analyze this Python code, find logical errors, and suggest corrections:",
"automation": "Write a Python script to automate this process, explain step by step:"
}
Then I could load them dynamically in scripts instead of retyping them every time.
import json
with open("prompts.json") as f:
prompts = json.load(f)
print(prompts["automation"])
This might sound trivial, but it saved me hours. No more rewriting prompts from scratch.
When Prompts Became My Superpower
Once I cracked the “prompt problem,” AI stopped feeling like a toy and started feeling like a teammate. I could spin up automation scripts faster than ever before. For instance, I built a script that renames files based on regex patterns:
import re
from pathlib import Path
folder = Path("downloads")
for file in folder.iterdir():
new_name = re.sub(r"\s+", "_", file.name).lower()
file.rename(folder / new_name)
This was exactly the kind of thing I used to waste time doing manually. With AI and the right prompts, I didn’t just automate the task, I automated the thinking process behind building the task.
Takeaway
The day I stopped blaming AI and started fixing my prompts was the day automation really clicked for me.
If you’ve ever felt like AI “just doesn’t get it,” step back and look at the way you’re writing prompts. Are you giving the tool vague guesses, or are you handing it a well-structured function call?
Like debugging code, the secret isn’t in yelling at the compiler, it’s in fixing your arguments.
“A bad prompt can waste hours. A good prompt can save weeks.”
Read my other articles:
- 7 Data Science Projects That Made Me Say “Why Didn’t I Learn This Sooner?”
- ChatGPT Isn’t Magic — But These 7 Techniques Make It Feel Like It Is
- 9 Python Libraries That Will Make You Code Like the Top 1%
- I Used Python to Clean My Messy Digital Life — Here’s What Happened
Want a pack of prompts that work for you and save hours? click here
Ready to go from Java beginner to confident developer? Start here.
Want more posts like this? Drop a “YES” in the comment, and I’ll share more coding tricks like this one.
Want to support me? Give 50 claps on this post and follow me.
Thanks for reading!
The Day I Realized My Prompts Were the Reason AI Was Failing Me was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on Level Up Coding – Medium and was authored by Maria Ali