Code generation prompt wizard
The quality of LLM-generated code is determined almost entirely by the prompt. A vague request (“write a function to parse dates”) forces the model to guess your language, your edge cases, and your definition of done — and guessing is where hallucinations come from. This wizard collects the handful of details that actually matter and assembles them into a tight, unambiguous prompt you can paste into any model.
How it works
The tool builds a prompt in the order models reason best: the task first, then hard constraints (language, framework, signature), then edge cases as explicit requirements, and finally the output format so you get just the code or code plus tests. Each section maps to a real failure mode — wrong language, wrong types, missing boundary handling, or prose padding around the answer — and closes it off before the model starts writing.
An example: the difference a structured prompt makes
Vague request: “Write a function to parse dates.”
The model might return a Python 2 function, assume US date format, skip null handling, and add no tests. You get something that compiles but fails in production.
Structured prompt (what this wizard generates):
- Language: Python 3.12, no external libraries
- Function signature:
parse_date(raw: str) -> datetime | None - Must match: ISO 8601,
DD/MM/YYYY,Month DD YYYY; must returnNonefor invalid input (not raise) - Edge cases: empty string, future dates, Feb 29 on non-leap years
- Include: three pytest unit tests
The model now has a closed specification. The output is directly runnable, handles the specified formats, and comes with tests you can execute immediately. The gap between these two outcomes is entirely in the prompt.
How to choose what to include in edge cases
The most useful edge cases to specify are those that:
- Your domain actually produces — if users paste dates from spreadsheets, they will contain slashes and inconsistent spacing.
- Are silently wrong, not obviously broken — division by zero raises an error; returning an incorrect date for Feb 30 does not.
- Cross language boundaries — Unicode in string inputs, locale-specific number separators, null-byte injection.
You do not need to list every imaginable case. Three to five focused edge cases turn a happy-path function into one that holds up in production.
Tips for reliable results
- Pin the version. “Python 3.12” or “React 19” stops the model reaching for deprecated or not-yet-released APIs.
- Give real types.
(items: number[], target: number) => number[]is worth a paragraph of description. - Name the edge cases you care about — empty input, nulls, overflow, concurrent access. The model handles what you ask for.
- Ask for tests when stakes are high. Runnable tests are faster to trust than a wall of code you have to read line by line.
- One function per prompt. Asking for a full module in one shot invites the model to gloss over details. Smaller targets yield better results.