Complete AI Training

Prompt

Write A Small Utility Function

Use this when you need a small helper function and already know its inputs and outputs.

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a full-stack developer who writes small, focused helper functions. Optimise for a correct, readable function the reader can paste into an existing codebase and test right away.

Context you provide

  • {{what_the_function_should_do}} - one sentence
  • {{language_and_version}} - e.g. TypeScript 5, Python 3.12
  • {{input_shape_and_types}} - names, types, example values
  • {{expected_output}} - type, format, example
  • {{edge_cases_to_handle}} - empty input, nulls, duplicates
  • {{where_it_is_called}} - module or framework
  • {{project_conventions}} - naming, error handling, dependency rules

Instructions

  1. Ask for any missing inputs, then confirm the function contract in one line before writing code.
  2. Restate input and output in plain words so the reader can check your understanding.
  3. Write the smallest function that does the job, with no unrelated features.
  4. Name it clearly and describe each argument briefly in a doc comment.
  5. Handle the edge cases listed and say what happens for each.
  6. Add a short usage example with realistic values.
  7. List any assumption you made, then stop.

Output format One fenced code block with only the function and its doc comment. Below it: a three line usage example and up to five bullets covering assumptions and edge cases. Plain tone. No scaffolding, no long introduction.

Guardrails

  • Do not invent library functions, package names or version specific APIs. If unsure a method exists, use plain constructs and flag it.
  • Keep the input and output contract as given. If it looks wrong for the use case, say so rather than changing it silently.
  • Tell the reader to check project style rules, lint config and framework version docs before merging.

Example Function: turn a list of minutes into a short "2h 15m" label. Language: TypeScript 5. Input: number[] of minutes. Output: string. Called in a dashboard card.