Loading...
Loading...
Prompt engineering is the practice of crafting inputs to AI models to get reliable, high-quality outputs. It's less about tricks and more about communication — you're telling the model exactly what you need.
| Vague | Specific |
|---|---|
| "Write a blog post" | "Write a 600-word blog post for developers about Docker basics. Use code examples and a friendly, direct tone." |
| "Summarize this" | "Summarize the following article in 3 bullet points, each under 20 words, targeting a non-technical audience." |
System: You are a senior TypeScript developer reviewing code for production readiness.
Focus on: type safety, error handling, performance, and security.
Be direct and give specific fix suggestions.
User: Review this API handler: [code]
Show the model the exact output format you want:
Convert these to slugs:
Input: "Getting Started with Next.js" → Output: getting-started-with-nextjs
Input: "10 TypeScript Tips" → Output: 10-typescript-tips
Input: "React vs Vue in 2024" → Output: ?
Force JSON output for programmatic use:
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{
role: 'user',
content: `Extract blog post metadata from this text and return JSON:
{ "title": string, "tags": string[], "readingTime": number }
Text: ${articleText}`
}],
response_format: { type: 'json_object' },
})
const metadata = JSON.parse(response.choices[0].message.content!)For complex reasoning, ask the model to think step-by-step:
Analyze this user's code for bugs.
Think through it step by step:
1. First identify what the code is trying to do
2. Then trace through the logic
3. Then identify any bugs or edge cases
4. Finally, suggest fixes
Code: [...]
Control creativity vs. consistency:
// Factual tasks (low temperature)
await openai.chat.completions.create({
model: 'gpt-4o',
temperature: 0.1, // deterministic, consistent
messages: [{ role: 'user', content: 'What is the capital of Morocco?' }],
})
// Creative tasks (higher temperature)
await openai.chat.completions.create({
model: 'gpt-4o',
temperature: 0.8, // more creative, varied
messages: [{ role: 'user', content: 'Write a catchy blog post intro about AI' }],
})const SYSTEM_PROMPT = `You are a helpful assistant for CodeWithSabir, a tech blog.
Rules:
- Only answer questions about programming and technology
- Always provide code examples when relevant
- Be concise — developers value their time
- If unsure, say so rather than making things up
- Format code with proper markdown code blocks`Good prompts are clear, specific, and give the model the context it needs to succeed. Treat prompting like writing a precise specification — the more clarity you provide, the better your results.