Pattern 1: Chain-of-Thought (CoT)
Add "Let's think step by step" to complex reasoning tasks. Improves accuracy by 20-40% on math and logic.
Pattern 2: Few-Shot with Negative Examples
Correct: "The product arrived damaged" → NEGATIVE
Correct: "Excellent quality, fast shipping" → POSITIVE
Incorrect: "It's okay I guess" → [CLASSIFY]
Pattern 3: JSON Mode
response = client.chat.completions.create(
model='gpt-4o',
response_format={'type': 'json_object'},
messages=[{'role': 'user', 'content': 'Extract entities from: ...' }]
)
Pattern 4: Persona + Constraint
"You are a senior ML engineer. Explain gradient descent in under 3 sentences. Use no math notation."
Pattern 5: Self-Consistency
Run the same prompt 5 times, take majority vote. Reduces error rate by ~30% on reasoning tasks.