Last Updated: May 1, 2025
Core Techniques
| Technique | How It Works | Best For |
|---|---|---|
| Role Assignment | 'You are an expert Python developer' — sets expertise | Consistent expertise, tone control |
| Chain-of-Thought | 'Let's think step by step' — forces reasoning | Math, logic, multi-step problems |
| Few-Shot | 2-5 examples of input→output pairs | Format control, style matching |
| Zero-Shot | Direct instruction, no examples | Simple, well-defined tasks |
| Structured Output | 'Return JSON with keys: name, age' | API responses, parsing |
| Self-Consistency | Ask 3-5 times → majority answer | Improving accuracy |
System Message Patterns
'You are a senior software engineer. Be concise. Prefer code.'Role + style + preference
'NEVER make up information. If unsure, say so.'Honesty guardrail
'Respond in JSON only: {"analysis":..., "confidence":0-100}'Structured output
Parameters Guide
| Item | Description |
|---|---|
Temperature (0-2) | 0=deterministic, 0.7=balanced, 1.5+=creative. Lower for facts, higher for brainstorming. |
Top-P (0-1) | Nucleus sampling — 0.1=only most likely tokens. Controls diversity differently from temperature. |
Max Tokens | Limits response length — 256 for short, 2048+ for essays/code. |
Frequency Penalty | Reduces word repetition. Higher = less repetition. |
Presence Penalty | Encourages new topics. Higher = less repetition of mentioned concepts. |
Advanced Patterns
| Item | Description |
|---|---|
Tree of Thoughts | Explore multiple reasoning paths → evaluate → commit. For complex planning. |
ReAct Pattern | Thought → Action → Observation loop. For tool-use and multi-step reasoning. |
Constitutional AI | 'Check your answer against these principles: 1. Accuracy 2. Helpfulness' |
Prompt Chaining | Break complex task: extract entities → classify → summarize → format |
Iterative Refinement | Start broad → refine based on output → add constraints → repeat |
Pro Tip: The system message sets persistent context — use it to define role, tone, and constraints. The user message delivers the task.