Prompts producing Python programs.
7votes
1answers
1.1kviews

What's the best prompt structure for getting Python scripts with proper error handling?

Every generated Python script I get is happy-path only: no retries, bare excepts, crashes on the first weird input. I've been experimenting with a checklist-style prompt suffix that forces defensive c
20votes
1answers
5.2kviews

Bounding concurrency in an asyncio scraper so I stop opening 5000 sockets at once

I asked for an async version of a fetcher and the model gleefully did await asyncio.gather([fetch(u) for u in urls]) over 5000 URLs. It opened every connection simultaneously, the event loop thrashed,
28votes
0answers
4.2kviews

One prompt for a polite, resumable web scraper that won't get me IP-banned

I needed to pull a few thousand product pages for a price-history side project. My first scraper hammered the site with 50 concurrent requests, got a 429, then kept retrying instantly and made it wors
23votes
2answers
2.9kviews

Prompt for a log-tailing CLI that parses, filters, and summarizes without loading the whole file

I wanted a small tool to slice gigabyte-sized JSON-lines logs by level and time range and print a summary, but the first version the model gave me did open(f).read() and json.loads on the whole thing,
18votes
2answers
3.1kviews

Prompt for a production-grade Python CLI with argparse, exit codes, and a self-check

Every weekend project starts with me asking a model for "a Python script that does X" and getting back a 20-line toy: no argument parsing, prints stack traces at users, returns 0 even when it failed.
22votes
1answers
2.2kviews

Debugging an intermittent asyncio race the model kept papering over

Had a flaky test that failed maybe 1 in 30 runs. Every model I tried "fixed" it by adding an await asyncio.sleep(0.1) somewhere, which is not a fix, it is a bribe. The real bug was two coroutines muta
17votes
1answers
2.4kviews

Safely refactoring a 600-line god-function CLI without changing its behavior

Inherited a single def run() that was 600 lines: arg parsing, file IO, business logic, and printing all tangled together. Management wanted features added but touching it was Russian roulette. Asking
26votes
1answers
2.2kviews

Prompt for a pandas cleaning script that validates the schema before it trusts the CSV

I get monthly CSV exports from a vendor and the columns silently drift: a header gets renamed, a numeric column arrives with stray $ and commas, dates flip between MM/DD and DD/MM. My old script assum
18votes
1answers
2.2kviews

Prompt for docstrings that document the WHY and the gotchas, not just the params

Auto-generated docstrings are useless: they restate the function signature in English. def add(a, b): """Adds a and b.""". Thanks. I wrote a prompt that reads the function body and forces it to docume
16votes
1answers
1.7kviews

Prompt for a CSV-to-chart tool that picks the chart type instead of me

I wanted an internal tool where an analyst pastes any CSV and gets a defensible chart without choosing a type. My first attempt just always drew a bar chart, which is nonsense for two numeric columns.
9votes
2answers
1.8kviews

Prompt to convert a messy research notebook into a reproducible, parameterized script

My analysis lived in a 400-cell notebook with out-of-order execution, hardcoded paths from my laptop, and df reused for six different frames. It ran on my machine and nowhere else. I needed a clean CL
8votes
1answers
1.5kviews

Getting the model to propose property-based tests, not three happy-path cases

Ask any model for tests and you get three example-based cases: a normal input, an empty input, maybe a null. Fine, but they miss the weird stuff. I wanted property-based tests that assert invariants a
9votes
1answers
1.7kviews

Forcing the model to write the failing test first instead of the impl

I do strict TDD and I wanted the model to do it with me, not for me. Default behavior with GPT is: ask for a feature, get the implementation plus some tests it wrote to match the code it just wrote. T
24votes
2answers
3.0kviews

Prompt that writes the migration AND a reversible down-migration, not just the ALTER

Models are great at spitting out ALTER TABLE statements and terrible at remembering that migrations run on live data with existing rows. I got burned adding a NOT NULL column with no default to a tabl
12votes
0answers
1.3kviews

Measure-before-optimize prompt so the model stops tuning cold code

I asked a local Llama-3 70B to "make this data pipeline faster" and it micro-optimized a list comprehension that runs once at startup while ignoring the O(n^2) join in the hot loop. Textbook: it optim