✨ I’ve been playing with large language models a lot lately, and one simple lesson keeps showing up: how you ask matters as much as what you ask. A few small habits in prompt-writing get much better answers — and faster. Here’s a friendly, copy-ready guide you can use. 👇
🔑 Practical habits I use every day
🧑🏫 Start with role — Tell the model who it should be.
Example: “You are a senior developer and clear teacher.” This sets tone and assumptions.
🎯 State the goal & format — Be explicit about output shape.
Example: “Explain X in 3 bullets” or “Return JSON with keys: name, summary.”
🧩 Give one example (few-shot) — Show an input→output pair so the model copies the structure.
🎛️ Control creativity — Temperature 0–0.2 for precise answers; 0.6–0.9 for creative brainstorming.
✅ Validate — Ask the model to check its output against rules.
Example: “Confirm JSON has keys id and name; if missing, fix it.”
🔁 Refactor example — before & after (copyable)
⚠️ Bad prompt (vague):
“Refactor this function: function calc(a,b){return (a?+a:0)+(b?+b:0)}”
Problem: model might change behavior or return explanations when you just wanted code.
✅ Good prompt (role + constraints + format):
System: You are an expert TypeScript refactorer.
User: Refactor the function below to improve readability and types, keeping behavior identical.
Constraints: TypeScript, ≤ 20 lines, no external libs.
Output: Return only a fenced TypeScript code block and a one-line summary comment.
Function:
function calc(a,b){return (a?+a:0)+(b?+b:0)}
Example of an expected refactor:
// Refactored: explicit types and clear naming
function calc(a?: string | number, b?: string | number): number {
const toNumber = (v?: string | number) => (v ? Number(v) : 0);
return toNumber(a) + toNumber(b);
}
📝 Executive summary example (useful template)
Prompt:
System: You are a concise summarizer for managers.
User: Summarize the text below into: (1) TL;DR ≤2 lines, (2) three business impacts, (3) one recommended action.
Text:
Example output:
TL;DR: Migration reduces page load by 40% and hosting costs by 25%.
Business impacts:
Faster pages → ~5% conversion uplift.
Lower hosting cost → monthly savings.
Fewer performance bugs → less engineering time lost.
Recommended action: Pilot migration on one high-traffic service.
⚙️ Quick prompt templates you can copy
Code review
System: You are a senior dev.
User: Review this PR diff and list 5 risks, 3 quick fixes, and 1 performance suggestion. Return bullets only.
Bug triage
System: You are a pragmatic engineer.
User: Given this error stack and snippet, list 3 likely causes and a one-line reproduction step for each.
Idea generation
System: You are a product designer.
User: Generate 12 landing-page ideas for [domain]; at least 4 must be low-cost MVPs. Return a numbered list, one line each.
🧰 Settings cheat sheet
Temperature: 0–0.2 (precise/technical) | 0.3–0.6 (balanced) | 0.7–0.9 (creative)
Max tokens: set just above expected length
Use stop sequences to avoid extra boilerplate
🛠️ Troubleshooting (if output is wrong)
Add a clear role and goal.
Specify exact output format (JSON, code block, bullets).
Provide 1 example.
Reduce temperature for deterministic results.
Ask the model to validate its output and fix rule violations.
Top comments (0)