Prompt engineering is the practice of crafting inputs to AI language models that consistently produce high-quality, relevant outputs. The difference between a mediocre AI response and an exceptional one often comes down entirely to how the question is framed — not the model’s capability. This guide covers the core techniques that work across ChatGPT, Claude, Gemini, and any frontier model.
Why Prompting Matters
Modern large language models have extensive knowledge and reasoning capability, but they’re also highly sensitive to framing. The same question asked two different ways can produce responses that are:
- Accurate vs. hallucinated
- Specific vs. generic
- In the format you need vs. unusable
- Appropriately uncertain vs. confidently wrong
Good prompting doesn’t manipulate the model — it provides context that helps it produce what you actually want, rather than its best guess at what you might want.
Technique 1: Be Specific About Output Format
Vague: “Tell me about Python decorators.”
Specific: “Explain Python decorators in 3 paragraphs: what they are, how they work mechanically, and a practical use case. Include a code example for each concept.”
The specific prompt gives the model a clear deliverable: three paragraphs, a defined scope, and examples. The vague prompt could produce anything from a one-liner to a 2000-word essay.
For structured output, ask for it explicitly:
- “Respond in JSON format with keys: title, summary, tags”
- “Use a table with columns: Feature, Pros, Cons, Score”
- “Provide your answer as a numbered list”
- “Return only the code, no explanation”
Technique 2: Role Prompting
Assigning a role or persona helps the model calibrate its response to the appropriate expertise level and communication style:
- “You are a senior software architect. Review this code for scalability issues…”
- “Act as a skeptical security researcher. Evaluate this authentication scheme…”
- “You are a patient teacher explaining to a 15-year-old. Describe how DNS works…”
- “You are a technical writer. Rewrite this documentation for clarity…”
The role sets expectations for depth, vocabulary, and perspective. Don’t overdo it — assign roles relevant to your actual task.
Technique 3: Chain-of-Thought Reasoning
For complex problems, explicitly asking the model to reason step-by-step dramatically improves accuracy:
Without CoT: “What’s the best database for this application?”
With CoT: “Think step-by-step: first identify the key requirements from the description, then list the trade-offs of relevant database options, then recommend one and explain why.”
Or simply append: “Think through this step by step before answering.”
Chain-of-thought is particularly effective for:
- Math and logic problems
- Code debugging
- Multi-factor decisions
- Anything where intermediate reasoning matters
Technique 4: Few-Shot Examples
Provide examples of the input-output pattern you want, and the model will follow it:
Convert these sentences to a more formal tone. Examples:
Input: "The meeting was a mess and nothing got done."
Output: "The meeting was unproductive, with no actionable outcomes achieved."
Input: "I can't figure out why the code keeps breaking."
Output: "I am having difficulty identifying the root cause of the recurring code failures."
Now convert this:
Input: "The client is really upset about the delay."
Few-shot examples are one of the most reliable techniques — they’re essentially demonstrations rather than instructions. The more consistent your examples, the more consistent the output.
Technique 5: Constraint Setting
Tell the model what you don’t want as explicitly as what you do want:
- “Answer in under 200 words.”
- “Do not suggest any third-party libraries.”
- “Do not include caveats or disclaimers.”
- “Avoid jargon — assume no technical background.”
- “Do not repeat information already in the conversation.”
Negative constraints are particularly useful for avoiding the model’s tendency to over-caveat, pad responses with disclaimers, or provide generic answers when you need something specific.
Technique 6: Iterative Refinement
Don’t expect the perfect output on the first try. Treat prompting as a conversation:
- Initial prompt → response
- “That’s good but make the introduction shorter and add a section on X”
- “Move the table to after the first paragraph”
- “Rewrite the conclusion to be more actionable”
Building outputs iteratively is usually faster than trying to specify everything upfront. Start with the core requirement, then refine.
Technique 7: Provide Context, Not Just Questions
Models don’t know your situation unless you tell them. Context dramatically improves relevance:
Without context: “How should I handle this error?”
With context: “I’m building a FastAPI application in Python 3.11, deployed on AWS Lambda. Users are seeing intermittent 500 errors on POST /api/orders. The error logs show SQLAlchemy TimeoutError with a pool size of 5. How should I fix this?”
Include: what you’re working on, your constraints, your skill level, what you’ve already tried, and the exact error if applicable.
Technique 8: Explicit Uncertainty Handling
Frontier models can hallucinate confidently. Ask them to flag uncertainty:
- “If you’re not sure about any part of this answer, say so explicitly.”
- “List any assumptions you’re making.”
- “If this information might be outdated, note that.”
- “For each claim, indicate your confidence level: high/medium/low.”
This doesn’t eliminate hallucination but catches more of it. Always verify factual claims, especially for specific numbers, dates, or technical specifications.
Technique 9: System Prompts for Consistent Behavior
If you’re using an API or a system that supports system prompts, set global behavior at the top:
You are a helpful technical assistant specializing in Linux system administration.
- Always provide commands with brief explanations of what each flag does
- When security is relevant, proactively note security implications
- If you're unsure, say "I'm not certain — verify this before running in production"
- Format all commands in code blocks
System prompts define persistent behavior across the whole conversation — much more efficient than repeating instructions in every user message.
Technique 10: Ask the Model to Ask You
When your requirements are unclear, let the model clarify:
“I want to write a blog post about VPNs. Before drafting anything, ask me 3–5 questions that will help you write exactly what I need.”
This surfaces mismatches between what you think you asked for and what the model understood — catching ambiguity early.
Common Mistakes to Avoid
- Being too vague: “Improve this” gives the model nothing to work with
- Overloading one prompt: Ask for one thing at a time; split complex tasks
- Accepting the first response: Iterate; the first draft is rarely the best
- Not specifying length: Models default to verbose; be explicit about length
- Forgetting to specify the audience: “Explain X” without audience context defaults to a middle-ground that satisfies no one
Model-Specific Tips
ChatGPT (GPT-4o): Excellent at following formatting instructions. Use code blocks liberally. Handles long context well.
Claude: Responds well to explicit reasoning instructions and tends toward thoroughness. Use “be concise” when brevity matters. Strong at nuanced analysis.
Gemini 1.5 Pro/Ultra: Excellent for tasks involving long documents or code repositories (1M context window). Responds well to structured JSON output requests.
Local models (Llama, Mistral): Often need more explicit instruction than frontier models. Always include a system prompt; don’t assume implicit understanding.
The best prompt engineers treat prompting as an experiment — test, observe, iterate, and document what works for your specific use cases.