Every workday of mine starts the same way: open the IDE, look at the task in the tracker, and realize that 80% of the time is spent not on writing code, but on routine—coming up with test cases, recalling syntax, debugging a mysterious error. About a year ago, I started actively using neural networks to generate and debug Python code, and during that time I've developed a set of prompts that really work. Below are 12 scenarios that I use almost daily. They've saved me dozens of hours, and I'm sure they'll be useful to you too.
1. Generating a Function from a Specification
When to use: When you need to quickly write a function with specific behavior without getting distracted by syntax.
Prompt:
Write a Python function {name} that takes {input data} and returns {output data}. Consider the following requirements: {list of requirements}. Add a docstring and type annotations.
Example:
Write a Python function parse_log_line that takes a log string in the format "2026-09-08 14:22:11 ERROR Connection error" and returns a dictionary with keys timestamp, level, message. Note that the message may contain spaces. Add a docstring and type annotations.
Why it works: A clear specification plus the requirement for docstring and annotations gives you code that is ready to use and easy to integrate into a project.
2. Writing Unit Tests
When to use: When you need to quickly cover an existing or new function with tests.
Prompt:
Write unit tests for the function {name} from module {path}. Use pytest. Cover the main scenarios: {list scenarios}. Include tests for edge cases and exceptions.
Example:
Write unit tests for the function parse_log_line from file utils.py. Use pytest. Cover scenarios: correct string, string with error, empty string, string with additional fields. Include tests for edge cases and exceptions.
Why it works: The neural network generates tests that often cover cases you might not have thought of—especially if you specify "edge cases."
3. Explaining Someone Else's Code
When to use: When you need to quickly understand unfamiliar code, especially legacy code.
Prompt:
Explain what this Python code does: {code}. Break down the explanation step by step, indicate the purpose of each function and possible side effects.
Example:
Explain what this Python code does: def f(x): return x * 2. Break down the explanation step by step, indicate the purpose of each function and possible side effects.
Why it works: You get a structured explanation that can be used as documentation or for review.
4. Finding and Fixing Errors (Debugging)
When to use: When the code doesn't work and you can't figure out why.
Prompt:
Here is Python code and the error traceback: {code} {traceback}. Find the cause of the error and suggest a fix. Explain why the error occurred.
Example:
Here is Python code and the error traceback:
def divide(a, b):
return a / b
print(divide(10, 0))
Traceback (most recent call last):
File "main.py", line 3, in <module>
print(divide(10, 0))
File "main.py", line 2, in divide
return a / b
ZeroDivisionError: division by zero
Find the cause of the error and suggest a fix. Explain why the error occurred.
Why it works: The neural network analyzes the traceback and code, often finding non-obvious causes—such as race conditions or improper exception handling.
5. Refactoring Legacy Code
When to use: When you need to improve the structure of old code without changing its behavior.
Prompt:
Refactor this Python code: {code}. Goal: improve readability, split into functions, remove duplication. Do not change the logic. Provide the final code and briefly describe the changes.
Example:
Refactor this Python code:
def process(data):
result = []
for item in data:
if item > 10:
result.append(item * 2)
else:
result.append(item + 1)
return result
Goal: improve readability, split into functions, remove duplication. Do not change the logic. Provide the final code and briefly describe the changes.
Why it works: The result usually contains a cleaner version with explanations, simplifying code review.
6. Performance Optimization
When to use: When the code runs too slowly and you need to find bottlenecks.
Prompt:
Profile this Python code and suggest optimizations to speed it up: {code}. Indicate which parts of the code are likely bottlenecks, and suggest specific changes (e.g., replacing loops with list comprehensions, using generators, caching).
Example:
Profile this Python code and suggest optimizations to speed it up:
import time
def slow_function(n):
result = []
for i in range(n):
result.append(i * 2)
return result
Indicate which parts of the code are likely bottlenecks, and suggest specific changes (e.g., replacing loops with list comprehensions, using generators, caching).
Why it works: The neural network often suggests standard optimizations like list comprehensions or using sets for lookups—these speed up code significantly.
7. Generating Regular Expressions
When to use: When you need to quickly create a regex for parsing strings.
Prompt:
Write a regular expression to find {what to find} in text. Consider {features}. Provide an example of usage in Python with the re module.
Example:
Write a regular expression to find email addresses in text. Consider that the address may contain dots, hyphens, and digits. Provide an example of usage in Python with the re module.
Why it works: You get a ready-made regex and example code, saving time on pattern crafting.
8. Creating SQL Queries
When to use: When you need to quickly write a complex SQL query for data extraction.
Prompt:
Write an SQL query to {task}. Tables: {schema description}. Consider {conditions}. Return only SQL.
Example:
Write an SQL query to get the top 10 customers by total order amount in the last month. Tables: customers(id, name), orders(id, customer_id, amount, order_date). Consider that you also need to output the number of orders. Return only SQL.
Why it works: You get a ready-made query that can be immediately tested in the database.
9. Writing Documentation and Comments
When to use: When you need to quickly document code.
Prompt:
Add docstrings and comments to this Python code: {code}. The docstring should be in Google style, explaining parameters, return value, and possible exceptions.
Example:
Add docstrings and comments to this Python code:
def add(a, b):
return a + b
The docstring should be in Google style, explaining parameters, return value, and possible exceptions.
Why it works: The neural network generates detailed docstrings that can be inserted directly into the code.
10. Explaining Errors and Tracebacks
When to use: When you get an unclear error and want to understand its cause.
Prompt:
Explain what this Python error means: {error text}. Tell what typical causes trigger it and how to fix it. Provide an example of code that causes this error and a corrected version.
Example:
Explain what this Python error means: IndexError: list index out of range. Tell what typical causes trigger it and how to fix it. Provide an example of code that causes this error and a corrected version.
Why it works: You get not only an explanation but also a ready-made example for reproduction and fixing.
11. Generating Automation Scripts
When to use: When you need to quickly write a script for a routine task (e.g., renaming files, parsing logs).
Prompt:
Write a Python script to {task}. The script should accept arguments via argparse. Add error handling and console output. Example run.
Example:
Write a Python script to rename all files in a folder according to the pattern "prefix_20260101.ext". The script should accept arguments via argparse. Add error handling and console output. Example run.
Why it works: You get a full-fledged script with a CLI interface that can be run immediately.
12. Help Choosing a Library or Approach
When to use: When you need to decide which library to use or which algorithm to apply.
Prompt:
Compare libraries {library1} and {library2} for {task}. Indicate their pros and cons, performance, ease of use. Give a recommendation.
Example:
Compare libraries requests and httpx for making HTTP requests in Python. Indicate their pros and cons, performance, ease of use. Give a recommendation.
Why it works: The neural network has access to up-to-date information (at the time of training) and can give a balanced comparison, helping you make a decision.
In Summary?
These 12 prompts are my basic set that covers 90% of routine tasks. Of course, I often combine them: for example, first generate a function (Prompt #1), then immediately tests (#2), and if something fails—run debugging (#4). The main thing is to be specific in your request: the more precisely you describe the task, the better the answer will be. Try applying at least a couple of them today—and you'll notice how your work speeds up. And if you have your own favorite prompts—share them in the comments, I'm always open to new ideas!
Comments