Overview
Prompt engineering for developers is about consistently getting high-quality code output from LLMs. Small changes in how you phrase requests can dramatically improve the quality, correctness, and relevance of generated code.
Key Principles
- •Be specific — name the language, framework, and version
- •Provide context — show related code, types, and imports
- •Set constraints — no dependencies, must handle errors, max line count
- •Give examples — show input/output pairs for the expected behavior
- •Specify format — "Return a named export", "Use async/await", etc.
Common Techniques
| Technique | How It Works | Best For |
|---|---|---|
| Few-shot | Show 2-3 input/output examples | Consistent formatting, patterns |
| Role prompting | "You are a senior TypeScript dev" | Quality and convention adherence |
| Chain-of-thought | "Think step by step" | Complex logic, algorithms |
| Structured output | "Return JSON with these fields" | API responses, data transforms |
| Constraint listing | List what NOT to do | Preventing common LLM mistakes |
Testing Prompts
Good prompts are repeatable. Test the same prompt multiple times with the LLM. If results vary wildly, the prompt is too vague. Add constraints until outputs converge on the quality you need.