Create intermediate Works with: Any AI

Code Generation Prompt With Tests

Structured brief Has example

Ask for code, tests, and assumptions together.

The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.

Rate this prompt

Loading ratings…

Write a code generation prompt. Language and version: [LANGUAGE_AND_VERSION]. Framework or libraries allowed: [LIBRARIES]. What the code must do (inputs, outputs, edge cases): [REQUIREMENTS]. Existing code context: [PASTE_CONTEXT]. Style and constraints (performance, security, readability): [CONSTRAINTS].

Produce a prompt that asks for: a short restatement of the requirements and assumptions; a design in a few lines; the code with comments only where logic is not obvious; input validation and error handling; unit tests that cover normal cases, edge cases, and failure cases, with expected values; a list of security or performance considerations; and instructions for running the tests. Specify: no unnecessary dependencies, no hardcoded secrets, use of existing project conventions, and a statement of what it could not verify.

Add: a checklist for reviewing the generated code (does it run, do the tests pass, are there hidden assumptions, any insecure patterns, does it handle empty inputs); a follow-up prompt for fixing failing tests with the error output pasted; a prompt for explaining the code line by line to a beginner; and a warning that generated code must be reviewed and tested, and that license and security responsibilities remain with me. Provide an example for a small function (parsing dates) showing the expected tests.

Fill in before use

Optional: type your details and the prompt above updates. Nothing is saved or sent.

Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.

See an example result (fictional data)
Requirements restated: parse dates in formats DD/MM/YYYY and YYYY-MM-DD; return ISO strings; raise ValueError for invalid dates.
Assumptions: two-digit years are not supported.
Code: function parse_date(text) with validation.
Tests: "15/10/2026" -> "2026-10-15"; "2026-02-30" -> error; "" -> error; "1/1/2026" -> "2026-01-01"; whitespace trimmed.
Security/performance notes: input length cap, no eval. Run: pytest -q.
Review checklist: edge cases, leap years, invalid month, whitespace, very long input, and no hidden dependencies. Generated code must be reviewed and tested, and license and security responsibilities stay with you. Follow-up prompt for failures: paste the error output and ask for a fix with an explanation. Beginner version: ask for a line-by-line explanation of the function.

Illustrative only, made-up data. Your results will differ and must be reviewed.

Related prompts