← Back to WeighMyPrompt

6 Prompt Engineering Techniques Every Developer Should Know

Last updated: April 15, 2026 · 12 min read

Good prompts aren't about being polite or verbose — they're about being structured and precise. These 6 techniques are what separate a $0.05 prompt that gets mediocre results from a $0.03 prompt that gets excellent results.

1. Chain of Thought (CoT)

Force the model to reason step by step instead of jumping to an answer. Best for: math, logic, debugging, analysis.

Think step by step:
1. Identify the core problem
2. Break it into sub-parts
3. Address each part with evidence
4. Synthesize into a final answer

Problem: [your question here]

~35 tokens overhead. Increases output quality significantly for reasoning tasks.

2. Few-Shot Examples

Show the model 2-3 examples of the input/output pattern you want. Best for: classification, formatting, extraction.

Input: "The service was terrible"
Output: {"sentiment": "negative", "confidence": 0.95}

Input: "Pretty good, would recommend"
Output: {"sentiment": "positive", "confidence": 0.80}

Input: "[your text here]"
Output:

~50 tokens per example. 2-3 examples is usually optimal — more doesn't help much.

3. XML Tags

Structure your prompt with XML-like tags. Models (especially Claude) parse these as semantic boundaries. Best for: complex prompts with multiple sections.

<context>
[paste relevant documentation here]
</context>

<task>
Based on the context above, write a migration plan.
</task>

<constraints>
- Maximum 3 steps
- No breaking changes
</constraints>

~20 tokens overhead for tags. Dramatically improves output quality for multi-section prompts.

4. Expert Persona

Give the model a specific role with years of experience. Best for: domain-specific tasks, code review, writing.

You are a senior PostgreSQL DBA with 15 years of experience in high-traffic systems. You prioritize query performance and data integrity.

Review this query for performance issues: [query]

~25 tokens. The persona primes the model to use domain-specific terminology and reasoning patterns.

5. Constraints

Explicitly state what the model should NOT do. Best for: preventing hallucination, controlling output format.

Constraints:
- Do not make up information. If unsure, say "I don't know."
- Stay within scope. Do not add features not requested.
- Maximum 200 words.
- Respond in valid JSON only.

~30 tokens. Essential for production prompts where reliability matters more than creativity.

6. Evaluation Rubric

Give the model scoring criteria before asking it to evaluate. Best for: code review, content quality, grading.

Evaluate using this rubric:
- Correctness (0-5): Is the code logically correct?
- Security (0-5): Are there vulnerabilities?
- Readability (0-5): Is it easy to understand?

Provide scores first, then detailed feedback.

~35 tokens. Forces structured, consistent evaluation output.

Combining techniques

The real power is in combining: use a Persona + XML Tags + Constraints for complex system prompts, or Few-Shot + CoT for tricky classification tasks.

Use WeighMyPrompt's Prompt Builder to combine these techniques visually — pick a task, select techniques, and see the prompt build in real time with a live token counter.

Token cost comparison

A typical production prompt using 3 techniques costs 80-120 tokens of overhead. At GPT-4o pricing ($5/M input), that's $0.0004-$0.0006 per request. The quality improvement easily justifies this cost.

Calculate your exact cost with WeighMyPrompt — free, private, and accurate.