What prompt engineering techniques should every LLM practitioner know?
The core toolkit is: system prompts (role and constraints), few-shot examples (format and tone anchoring), chain-of-thought (step-by-step reasoning), and output constraints (JSON schema, stop sequences). Combining these predictably closes the gap between a capable base model and a production-ready feature.
How to think about it
Prompt engineering is the practice of shaping model behavior through input text rather than weight updates. It is the fastest iteration loop in LLM development.
System prompts
The system turn sets persistent instructions: persona, response format, tone, and hard refusals. Because it is prepended to every turn in a conversation, it is the primary lever for consistent behavior.
You are a concise technical writer for a developer audience.
- Answer in plain English, no jargon without definition.
- Never fabricate citations.
- If unsure, say so explicitly.
Few-shot examples
Provide 2–8 input/output pairs that demonstrate the exact format and reasoning style you want. Few-shot examples are especially powerful for structured extraction tasks where the output schema is non-obvious.
messages = [
{"role": "system", "content": "Extract entities as JSON."},
{"role": "user", "content": "Apple acquired Beats for $3B in 2014."},
{"role": "assistant", "content": '{"acquirer":"Apple","target":"Beats","amount":"$3B","year":2014}'},
{"role": "user", "content": "Microsoft bought Activision Blizzard for $68.7B in 2023."},
]
Append “Think step by step before answering.” or provide traced examples. Improves multi-step reasoning. See the dedicated CoT question for detail.
Output constraints
- Use
response_format={"type": "json_object"}or a JSON schema (OpenAI Structured Outputs) to guarantee parseable output. - Use
stopsequences to prevent runaway generation. - Set
temperature=0for deterministic tasks (extraction, classification); higher for creative tasks.
Prompt ordering matters
Later content in a long context receives more attention (recency bias). Put the most important instruction last in the user turn, not buried in a long system prompt.
Role prompting
“You are a senior security auditor reviewing this code for vulnerabilities” outperforms “Review this code” because the role primes domain-specific vocabulary and reasoning patterns.