{"slug":"prompting","id":"prompting","type":"guide","title":"Prompt Engineering Guide — How to Write Better AI Prompts","description":"Master prompt engineering from beginner to advanced. Learn zero-shot, few-shot, chain-of-thought, and other techniques to get better results from ChatGPT, Claude, and Gemini.","last_updated":"2026-04-10","last_verified":null,"verification_status":"unverified","markdown_url":"/content/guides/prompting.md","html_url":"/guides/prompting","api_url":"/api/v1/guides/prompting.json","content_hash":"02d1076a6bda05c2a68105ef860799364edcbad14e56aae3feec74800a503395","sha256":"02d1076a6bda05c2a68105ef860799364edcbad14e56aae3feec74800a503395","tags":["prompt-engineering","prompting","techniques"],"relationships":{"links":[{"text":"What Is AI? beginner guide","href":"getting-started.md","html_path":"/guides/getting-started","markdown_url":"/content/guides/getting-started.md","target_id":"getting-started","target_type":"guide","target_title":"What Is AI? A Complete Beginner's Guide to Artificial Intelligence"},{"text":"AI Model Comparison","href":"/models","html_path":"/models","target_id":"models","target_type":"index","target_title":"AI Model Comparison"},{"text":"Prompt Patterns","href":"/prompt-patterns","html_path":"/prompt-patterns","target_id":"prompt-patterns","target_type":"index","target_title":"Prompt Patterns by Model"},{"text":"Compare AI Models","href":"/models","html_path":"/models","target_id":"models","target_type":"index","target_title":"AI Model Comparison"},{"text":"What Is AI?","href":"getting-started.md","html_path":"/guides/getting-started","markdown_url":"/content/guides/getting-started.md","target_id":"getting-started","target_type":"guide","target_title":"What Is AI? A Complete Beginner's Guide to Artificial Intelligence"},{"text":"AI Glossary","href":"/glossary","html_path":"/glossary","target_id":"glossary","target_type":"glossary","target_title":"AI Glossary"}],"related":[{"id":"agent-tooling-compatibility","title":"Agent Tooling Compatibility","type":"guide","html_url":"/guides/agent-tooling-compatibility","markdown_url":"/content/guides/agent-tooling-compatibility.md","shared_tags":[],"score":2},{"id":"agent-usage-guide","title":"Agent Usage Guide","type":"guide","html_url":"/guides/agent-usage","markdown_url":"/content/guides/agent-usage.md","shared_tags":[],"score":2},{"id":"ai-failure-modes","title":"AI Failure Modes","type":"guide","html_url":"/guides/failure-modes","markdown_url":"/content/guides/failure-modes.md","shared_tags":[],"score":2},{"id":"benchmark-methodology","title":"Benchmark Methodology","type":"guide","html_url":"/guides/benchmark-methodology","markdown_url":"/content/guides/benchmark-methodology.md","shared_tags":[],"score":2},{"id":"best-for-task-matrix","title":"Best-For Task Matrix","type":"guide","html_url":"/guides/best-for-task-matrix","markdown_url":"/content/guides/best-for-task-matrix.md","shared_tags":[],"score":2},{"id":"build-a-coding-agent-stack","title":"Build a Coding Agent Stack","type":"guide","html_url":"/guides/build-a-coding-agent-stack","markdown_url":"/content/guides/build-a-coding-agent-stack.md","shared_tags":[],"score":2}],"explicit":{}},"metadata":{"title":"Prompt Engineering Guide — How to Write Better AI Prompts","type":"guide","id":"prompting","description":"Master prompt engineering from beginner to advanced. Learn zero-shot, few-shot, chain-of-thought, and other techniques to get better results from ChatGPT, Claude, and Gemini.","last_updated":"2026-04-10","tags":["prompt-engineering","prompting","techniques"]},"content_text":"# Prompt Engineering Guide\n\nHow to write prompts that get you exactly what you need from AI. From basic principles to advanced techniques, with real examples you can copy and adapt.\n\n---\n\n## What Is Prompt Engineering?\n\nA \"prompt\" is the text you type into an AI tool like ChatGPT, Claude, or Gemini. **Prompt engineering** is the skill of writing prompts that consistently produce useful, accurate, and relevant results.\n\nThink of it this way: an AI model is like an incredibly knowledgeable colleague who is eager to help but takes instructions very literally. The more precisely you communicate what you want, the better the result you get back.\n\nPrompt engineering is not about memorizing magic phrases. It is about understanding how AI models interpret your instructions and developing a repeatable approach to communicating effectively with them. Whether you are writing a quick email or building a complex AI workflow, these principles apply.\n\nIf you are new to AI entirely, read our [What Is AI? beginner guide](getting-started.md) first, then come back here.\n\n---\n\n## Basic Prompting Principles\n\nBefore diving into specific techniques, here are the fundamental principles that apply to every prompt you will ever write:\n\n### 1. Be Specific, Not Vague\n\nThe single biggest improvement you can make is being more specific. Vague prompts produce generic output. Specific prompts produce useful output.\n\n```\nBad: Write about dogs.\n```\n\n```\nGood: Write a 300-word blog post about the top 3 benefits of adopting a\nsenior dog from a shelter. Target audience: families with young children.\nTone: warm and encouraging.\n```\n\n### 2. Provide Context\n\nAI does not know your situation unless you tell it. Include relevant background information to help the model give you a tailored response.\n\n```\nBad: How should I invest my money?\n```\n\n```\nGood: I'm 30 years old, have $10,000 in savings, no debt, and a stable\njob earning $75,000/year. I want to start investing for retirement. I have\na moderate risk tolerance and prefer a hands-off approach. What investment\nstrategy would you recommend for someone in my situation?\n```\n\n### 3. Specify the Format\n\nTell the AI exactly how you want the output structured. Do you want bullet points? A table? A numbered list? An email? A code block? Say so explicitly.\n\n```\nGood: Compare the pros and cons of React vs Vue.js for a small team\nbuilding a dashboard app. Format your response as a markdown table with\ncolumns: Feature, React, Vue.js.\n```\n\n### 4. Set the Tone and Audience\n\nThe same information can be presented in wildly different ways depending on who it is for. Always specify:\n\n- **Who is the audience?** (executives, children, developers, customers)\n- **What tone?** (professional, casual, humorous, academic)\n- **What level of detail?** (overview, in-depth, executive summary)\n\n### 5. Iterate and Refine\n\nYour first prompt is a starting point, not a final draft. The best results come from a conversation:\n\n1. Write your initial prompt\n2. Review the output\n3. Identify what is missing, wrong, or not quite right\n4. Follow up with refinements: \"Make it shorter,\" \"Add more examples,\" \"Focus more on the cost savings angle\"\n\n---\n\n## The Anatomy of a Good Prompt\n\nA well-crafted prompt typically has some or all of these components:\n\n```\n[Role] You are an experienced marketing copywriter who specializes in\nB2B SaaS companies.\n\n[Task] Write 3 subject line options for a cold outreach email.\n\n[Context] The target audience is CTOs at mid-size companies (100-500\nemployees). We sell a developer productivity platform.\n\n[Format] Format each option as: Subject line | Why it works (1 sentence\nexplanation).\n\n[Constraints] Keep each subject line under 50 characters. No clickbait\nor spam-sounding language.\n```\n\nNot every prompt needs all five components. A quick question might just need the task. But for any important output, the more of these components you include, the better your results will be.\n\n---\n\n## Core Prompting Techniques\n\nThese are the essential techniques every prompt engineer should know. They are listed roughly in order of complexity.\n\n### Zero-Shot Prompting (Beginner)\n\nThis is the simplest approach: you give the AI a task with no examples. You are relying entirely on the model's training to understand what you want.\n\n```\nClassify the sentiment of this customer review as Positive, Negative,\nor Neutral:\n\n\"The product arrived on time but the packaging was damaged. The item\nitself works fine though.\"\n\nSentiment:\n```\n\nZero-shot works well for straightforward tasks where the AI has strong training data. It is less reliable for unusual or ambiguous tasks.\n\n### Few-Shot Prompting (Beginner)\n\nYou provide 2-3 examples of the input-output pattern you want before giving the AI the actual task. This is one of the **most powerful and universally useful** techniques.\n\n```\nClassify the sentiment of customer reviews.\n\nReview: \"Absolutely love this product! Best purchase I've made all year.\"\nSentiment: Positive\n\nReview: \"Terrible quality. Broke after two days of use.\"\nSentiment: Negative\n\nReview: \"The product arrived on time but the packaging was damaged. The\nitem itself works fine though.\"\nSentiment:\n```\n\nBy showing the model examples, you are teaching it exactly what format, style, and logic you expect. This dramatically improves consistency and accuracy, especially for classification, extraction, and formatting tasks.\n\n### Chain-of-Thought (CoT) Prompting (Intermediate)\n\nAsk the AI to \"think step by step\" before giving its final answer. This significantly improves accuracy on reasoning, math, and logic problems by forcing the model to show its work.\n\n```\nBad: A store sells apples for $2 each. If I buy 3 apples and pay with\na $20 bill, and there's an 8% sales tax, how much change do I get?\n```\n\n```\nGood: A store sells apples for $2 each. If I buy 3 apples and pay with\na $20 bill, and there's an 8% sales tax, how much change do I get?\n\nThink through this step by step, showing your calculations at each stage\nbefore giving the final answer.\n```\n\nChain-of-thought prompting is especially effective for:\n\n- Math and arithmetic problems\n- Logic puzzles\n- Multi-step reasoning tasks\n- Debugging code\n- Analyzing complex scenarios with multiple variables\n\n### Role Prompting (Beginner)\n\nAssign the AI a specific role or persona. This primes the model to draw on patterns associated with that expertise, producing more domain-appropriate responses.\n\n```\nYou are a senior software engineer with 15 years of experience in Python\nand distributed systems. You value clean, readable code and always\nconsider edge cases.\n\nReview this function and suggest improvements:\n\ndef process_data(items):\n    result = []\n    for i in items:\n        if i > 0:\n            result.append(i * 2)\n    return result\n```\n\nEffective roles to try: teacher, editor, critic, consultant, interviewer, translator, coach, devil's advocate. The more specific you make the role, the more targeted the output.\n\n---\n\n## System Prompts and Instructions\n\nMany AI platforms (including the APIs for ChatGPT and Claude) support **system prompts** -- special instructions set at the beginning of a conversation that guide the AI's behavior throughout the entire interaction.\n\nEven in consumer chatbots, you can achieve a similar effect by putting your instructions at the start of the conversation:\n\n```\nInstructions for this conversation:\n- You are a friendly, patient tutor helping me learn Spanish.\n- Always respond with both the Spanish phrase and the English translation.\n- Correct my mistakes gently and explain why.\n- Use simple vocabulary appropriate for a beginner (A1-A2 level).\n- At the end of each response, give me a short practice exercise.\n\nLet's start. How do I say \"Where is the nearest restaurant?\" in Spanish?\n```\n\nSystem-style instructions are especially useful when you want consistent behavior across a long conversation. Some tips:\n\n- Put instructions at the **very beginning** of the conversation for maximum effect\n- Use clear, direct language (do/do not rather than should/could)\n- Be explicit about what you want *and* what you do not want\n- You can restate key instructions mid-conversation if the AI starts drifting\n\n---\n\n## Advanced Techniques\n\nThese techniques build on the fundamentals and are useful for getting the best results on complex or high-stakes tasks.\n\n### Self-Consistency (Advanced)\n\nAsk the AI to generate multiple independent answers to the same question, then pick the most common answer or ask it to synthesize the best response. This reduces the chance of getting a random incorrect output.\n\n```\nI need to decide whether to lease or buy a car. Here are my details:\n- Annual mileage: ~12,000 miles\n- Budget: $500/month max\n- I keep cars for 5-7 years\n- Good credit score (740)\n\nGenerate 3 independent analyses of whether I should lease or buy,\nconsidering different angles (financial, practical, long-term value).\nThen synthesize these into a final recommendation with your confidence\nlevel.\n```\n\n### Tree-of-Thought (ToT) (Advanced)\n\nAn extension of chain-of-thought where the AI explores multiple reasoning paths, evaluates each one, and selects the most promising approach. Useful for complex problems with multiple possible solution paths.\n\n```\nI want to increase our SaaS product's free-to-paid conversion rate\n(currently 2.1%).\n\nExplore 3 different strategic approaches to solve this problem. For each\napproach:\n1. Describe the strategy\n2. List specific tactics\n3. Assess likely impact (high/medium/low)\n4. Identify risks or downsides\n\nAfter exploring all 3, recommend which approach (or combination) you'd\nprioritize and explain why.\n```\n\n### ReAct (Reasoning + Acting) (Advanced)\n\nA prompting pattern where you ask the AI to alternate between thinking (reasoning about what to do) and acting (taking a step). This is the pattern behind AI agents and tool-using systems.\n\n```\nHelp me debug why our website's contact form isn't sending emails. Work\nthrough this methodically.\n\nFor each step:\n- THOUGHT: What could be causing this issue? What should I check next?\n- ACTION: What specific thing should I do or check?\n- OBSERVATION: [I'll tell you what I find]\n\nThen repeat until we've identified and fixed the issue. Start with your\nfirst thought.\n```\n\n### Constraint-Based Prompting (Intermediate)\n\nExplicitly list what the AI should and should not do. This is especially useful for avoiding common failure modes like verbosity, off-topic tangents, or hallucinated information.\n\n```\nExplain how HTTPS encryption works.\n\nConstraints:\n- Use a metaphor that a 12-year-old could understand\n- Keep it under 150 words\n- Do NOT mention specific algorithms or cipher suites\n- Do NOT use the words \"key exchange\" or \"handshake\"\n- End with a one-sentence summary\n```\n\n---\n\n## Common Mistakes and How to Fix Them\n\n### Mistake 1: Being too vague\n\n\"Write me a marketing email\" gives the AI almost nothing to work with.\n\n**Fix:** Include the product, audience, goal, tone, length, and call-to-action. The more detail, the better.\n\n### Mistake 2: Asking multiple unrelated things at once\n\n\"Write a blog post, also create a social media calendar for next month, and analyze our competitor's pricing\" -- this overwhelms the model.\n\n**Fix:** Break complex requests into separate prompts. One task per prompt generally produces better results.\n\n### Mistake 3: Not specifying the output format\n\nWithout format instructions, the AI guesses what you want and often produces long, essay-style responses when you wanted bullet points.\n\n**Fix:** Always state the desired format: \"Respond with a bulleted list,\" \"Format as a table,\" \"Give me a one-paragraph summary.\"\n\n### Mistake 4: Accepting the first output\n\nThe first response is almost never perfect. Treating it as final means you are leaving quality on the table.\n\n**Fix:** Always do at least one round of refinement. Ask the AI to improve weak areas, add missing details, or try a different angle.\n\n### Mistake 5: Trusting AI output without verification\n\nAI can confidently state incorrect facts, invent fake sources, and produce plausible-sounding nonsense.\n\n**Fix:** Always fact-check specific claims, statistics, quotes, and citations. Use AI output as a starting draft, not a final source of truth.\n\n---\n\n## Prompting Tips by Model\n\nWhile the core principles work across all models, each AI has slight differences in how it responds. Here are some model-specific tips:\n\n### OpenAI GPT-5.4 / ChatGPT\n\n- GPT-5.4 responds well to **detailed system prompts** and follows formatting instructions closely\n- Tends to be verbose by default -- explicitly ask for concise responses if you want them\n- Excellent with **structured output** (JSON, tables, code blocks) when you specify the format\n- The \"Custom Instructions\" feature in ChatGPT lets you set persistent preferences that apply to all conversations\n- For complex reasoning, use **GPT-5.4 Thinking** mode which has built-in chain-of-thought reasoning for math, science, and hard problems\n- With a 1M token context window, you can now feed entire codebases or long documents in a single prompt\n\n### Anthropic Claude (Opus 4.6 / Sonnet 4.6)\n\n- Claude excels at **long, nuanced instructions** -- it handles complex multi-part prompts very well\n- Particularly strong at following **constraint-based prompts** (\"do this but not that\")\n- Has a massive 1M token context window across all tiers, so you can paste entire documents and codebases\n- Claude tends to be more measured and less likely to confidently state incorrect information\n- Works well with **XML-style tags** in prompts (e.g., `<instructions>`, `<context>`) for clearly separating different parts of your prompt\n- Opus 4.6 leads on coding benchmarks (80.8% SWE-bench) -- ideal for complex coding and agentic tasks\n\n### Google Gemini 3.1 Pro\n\n- Gemini has **built-in web access**, making it excellent for research and current events\n- Strong **multimodal capabilities** -- natively processes text, images, video, and audio in a single prompt\n- Integrates deeply with Google Workspace (Docs, Sheets, Gmail), so prompts can reference your existing documents\n- For factual queries, it often provides source links (since it can search the web), which makes verification easier\n- May default to shorter responses; ask for detailed or comprehensive output explicitly\n\n### Open-Source Models (Llama 4, Gemma 4, DeepSeek, Qwen)\n\n- Open-source models now rival proprietary ones on many tasks -- **Llama 4 Maverick** scored #2 on LMArena\n- **Gemma 4** from Google runs on phones to workstations and is excellent for local/private use\n- **DeepSeek R1** is great for math and reasoning but less polished on creative writing -- be explicit about the style you want\n- **Qwen 3.5** supports 201 languages and excels at multilingual tasks -- specify the output language clearly\n- When self-hosting, quantized models (Q4/Q5) are slightly less capable -- use more explicit prompts and verify outputs for critical tasks\n\n### xAI Grok 4.20\n\n- Grok has the **lowest hallucination rate** of any model -- ideal for factual, accuracy-critical tasks\n- Has real-time access to X/Twitter data, making it strong for current events and social media analysis\n- The multi-agent mode can tackle complex research tasks by coordinating parallel workflows\n- #1 on instruction following (IFBench) -- it sticks closely to what you ask for\n\nFor a detailed comparison of all 33+ models' capabilities, pricing, and hardware requirements, see our [AI Model Comparison](/models) page.\n\n---\n\n## Prompt Templates for Common Tasks\n\nHere are ready-to-use templates you can adapt for your own needs. Copy them, fill in the bracketed sections, and you are good to go.\n\n### Email Writing\n\n```\nWrite a [type: professional/casual/formal] email to [recipient].\n\nPurpose: [what you want to achieve]\nKey points to cover:\n- [point 1]\n- [point 2]\n- [point 3]\n\nTone: [friendly/direct/persuasive/apologetic]\nLength: [short (2-3 sentences) / medium (1 paragraph) / detailed]\nCall to action: [what you want the recipient to do next]\n```\n\n### Content Summarization\n\n```\nSummarize the following [document/article/report] in [number] bullet\npoints.\n\nFocus on: [key themes or questions you care about]\nAudience: [who will read the summary]\nInclude: [any specific details you need, e.g., statistics, action items,\ndeadlines]\nExclude: [anything you want left out]\n\n[Paste the content here]\n```\n\n### Code Review\n\n```\nReview this [language] code for:\n1. Bugs or logical errors\n2. Performance issues\n3. Security vulnerabilities\n4. Readability improvements\n5. Best practice violations\n\nFor each issue found, explain:\n- What the problem is\n- Why it matters\n- How to fix it (with corrected code)\n\n[Paste your code here]\n```\n\n### Learning / Explaining Concepts\n\n```\nExplain [concept] to me as if I'm [level: a complete beginner / an\nintermediate learner / a professional in a related field].\n\nUse:\n- A real-world analogy\n- One concrete example\n- No jargon (or define any technical terms you use)\n\nThen give me 3 follow-up questions I should explore to deepen my\nunderstanding.\n```\n\n### Decision Making\n\n```\nHelp me decide between [Option A] and [Option B].\n\nContext: [your situation, constraints, and goals]\n\nFor each option, analyze:\n1. Pros (at least 3)\n2. Cons (at least 3)\n3. Best-case scenario\n4. Worst-case scenario\n5. Who this option is best suited for\n\nThen give me your recommendation with a confidence level\n(high/medium/low) and explain your reasoning.\n```\n\nFor more model-specific templates and reusable structures, visit our [Prompt Patterns](/prompt-patterns).\n\n---\n\n## What to Read Next\n\nYou now have a solid foundation in prompt engineering. Here are some next steps:\n\n- **[Prompt Patterns](/prompt-patterns)** -- Browse model-specific prompting patterns you can adapt for writing, coding, analysis, and more.\n- **[Compare AI Models](/models)** -- Find the right model for your tasks with our detailed comparison.\n- **[What Is AI?](getting-started.md)** -- Go back to basics with our complete beginner's guide.\n- **[AI Glossary](/glossary)** -- Look up any AI term you encounter in plain English.","content_length":18456,"generated_at":"2026-04-24"}