How to Format a Prompt Before Using an AI Model
A well-formatted prompt isn't necessarily shorter. It's clearer about what you want, in what order, and under what constraints. The same request written as a wall of text versus written with labelled sections can produce meaningfully different output quality — especially for complex, multi-part tasks.
Use labelled sections
Labelled sections help the model identify what each part of your prompt is for. Common conventions:
## Context
You are reviewing pull requests for a Python codebase following PEP 8.
## Task
Review the following code diff and identify any bugs or style violations.
## Format
Return a bulleted list. Include line numbers where relevant.
If no issues found, say "Looks good."
## Code diff
[paste here]
The model can identify where the context ends and the task begins, rather than having to infer structure from a continuous block of text. You don't need to use Markdown headers — even labels like TASK: and FORMAT: in all-caps work. The key is unambiguous separation between different types of content.
Instructions first, examples after
If your prompt includes examples, put the instructions before them. Models generalise from examples — if the examples appear first without context, the model may treat them as definitions rather than illustrations. "Do X — here's what good X looks like" outperforms "here's what X looks like — do X."
Constraints work best stated near the end, just before the content being processed. "Do not include code examples — [user question]" is more reliably followed than "[user question] — and by the way, don't include code examples."
Handle variable parts explicitly
If you reuse a prompt template with different inputs, make the variable part obvious:
## Task
Classify the following customer review as Positive, Negative, or Neutral.
Return only the classification word, nothing else.
## Review
{{REVIEW_TEXT}}
Clear placeholder markers — {{REVIEW_TEXT}}, [USER_INPUT], <document> — make the template maintainable. When you come back to it in two weeks, you immediately know what changes per request and what stays fixed.
Cleaning before reuse
Prompts accumulate mess through iteration — extra blank lines, duplicated instructions, clarifications added after failed tests. Run a prompt through a formatter before saving it as a template. Clean whitespace and consistent structure make the template easier to read and modify. A messy template produces unpredictable results when the underlying model updates change how it handles ambiguous formatting.