Efficient Prompt Engineering Guide

Efficient Prompt Engineering Guide

Core mindset: Prompt is code — not a magic word, not a chatbot message. It must be structured, version-controlled, and iteratively tested.


Framework 1 — C-T-R Formula

Every effective prompt needs 3 parts:

Talk to Claude like briefing a smart new colleague — natural, concise, with enough context. No "keyword magic" needed.


Framework 2 — 3 Layers of Description

Layer Question Example
Product What should AI create? Format, length, audience, style, constraints
Process How should AI approach it? Step-by-step method, frameworks, references
Performance How should AI behave? Concise or detailed? Challenge or follow? Ask or infer?

Most people only specify Product. Good prompters add Process. Fluent prompters nail all three — especially Performance, which is most often skipped.

Weak prompt (Product only):

Write an email to a customer complaining about a bug.

Strong prompt (all 3 layers):

[Product] Write a professional email (≤150 words, markdown not needed) 
to a customer who reported Bug #4521 in our payment module.

[Process] Step 1: Acknowledge the issue with empathy. Step 2: State the 
fix ETA (48 hours). Step 3: Offer a 10% discount coupon as goodwill.

[Performance] Tone: warm but professional. Do NOT over-apologize. 
Ask me before sending if the ETA needs to change.

The 6 Core Techniques

You don't need all 6 in every prompt. Pick based on the task.

1. Give Context (W5H)

AI knows a lot but knows nothing about your specific context. You must feed it.

Structure your context using W5H:

❌  "Write an announcement for the team"

✅  "Write a Slack announcement for our 15-person engineering team 
    (non-technical managers included). Purpose: inform them that 
    the production deploy is delayed by 2 hours due to a hotfix. 
    Tone: calm, transparent. Max 3 sentences."

When to use: Task has stakeholders, domain-specific context, or history.


2. Show Examples (Few-Shot Prompting)

One example = 10× better than an abstract description. Show, don't tell.

Type Strength Weakness
Zero-shot Concise, works for common tasks May miss corner cases
One-shot Clarifies expected format Doesn't cover nuance
Few-shot (2–5) Covers edge cases, tone, style More tokens, risk of overfitting

When to use: Style-heavy tasks, pattern repetition (taglines, headlines), when you have good past outputs.


3. Specify Constraints

AI tends to over-engineer. Constraints make it focus.

Categories to constrain:

Positive constraints are easier for AI to follow than negative ones.
Start simple — only add constraints when you see the output going wrong.


4. Break Complex Tasks into Steps

LLMs struggle with implicit multi-step reasoning. Make it explicit.

❌  "Analyze competitors and recommend a strategy"

✅  "Analyze competitors and recommend a strategy using these steps:
    1. List 5 direct competitors for Product Y
    2. Profile each: offering, pricing, USP, customer reviews
    3. Build a comparison matrix (5 competitors × 8 dimensions)
    4. Identify gaps (where all competitors are weak → opportunity)
    5. Identify saturation (where all are strong → table stakes)
    6. Recommend 3 strategies based on gap analysis (rationale + risk each)
    7. Pick the top 1 with full justification"

Benefits: Easier to verify each step, reduces reasoning drift, transparent thinking.


5. Ask AI to Think First

Force the AI to output reasoning before the final answer — this drastically reduces hallucinations.

4 ways to trigger thinking:

  1. "Before answering, think step by step. Put your reasoning in <thinking> tags, then give your final answer."
  2. "Before writing the full essay, share your outline for me to review."
  3. "Before solving, list 5 assumptions or questions you need to clarify."
  4. Enable Extended Thinking mode in Claude (for complex tasks).

When to use: Reasoning-heavy tasks, high-stakes output, ambiguous data.


6. Define Role & Tone

The same question asked to different personas gives vastly different answers. Calibrate the AI with a Role + Audience + Tone combo.

Level 1 — Role:    "You are a senior financial analyst with 15 years 
                    covering the tech sector."
Level 2 — Tone:    "Tone: professional, analytical, no fluff. 
                    Use data whenever possible."
Level 3 — Audience:"Audience: non-technical CEO with a 5-minute 
                    attention span. Avoid jargon, use analogies."

Advanced Strategies

Clear & Direct: The First Line Rules Everything

The first line is the most important. Claude orients from line 1.

Pattern Example
Start with a strong action verb Generate, Write, Analyze, Extract, Summarize, Compare
Command, don't question "List 3 options" not "Could you please list..."
Be specific "solar panel" not "that thing on the roof"
No filler words Remove "kind of", "maybe", "if possible"
❌  "Could you maybe write something about photosynthesis for students?"
✅  "Generate a 10-question quiz on photosynthesis for Grade 9. 
    Mix: 5 multiple-choice, 3 short-answer, 2 essay. Include an 
    answer key with explanations."

Structure with XML Tags

For prompts 20+ lines or mixing instructions with data, use XML tags to help Claude parse boundaries.

<task>
Summarize the following customer reviews and classify sentiment.
</task>

<brand_guidelines>
- Tone: empathetic and solutions-focused
- Never mention competitor names
</brand_guidelines>

<reviews>
Review 1: "The product is great but shipping took 3 weeks..."
Review 2: "Customer support was amazing when I had an issue..."
</reviews>

<output_format>
Return a JSON with: summary (string), sentiment (positive/neutral/negative), 
top_issue (string)
</output_format>

Rules: Max 2 levels of nesting. Use descriptive tag names (<sales_data> not <data>). Only use XML for complex prompts — overkill for short ones.


Context Engineering: Place Information Strategically

LLMs have a "lost in the middle" effect — attention is strongest at the beginning and end, weakest in the middle.

Stanford 2023 research: Accuracy drops >30% for facts placed in the middle of long prompts.

Rules:

  1. Place critical instructions at the top (system prompt) and repeat them at the end
  2. Curate ruthlessly — 5 relevant pages > 50 pages of "all the info I have"
  3. Every extra context you add pushes other context into the attention dead zone

IPO Framework: Intent → Purpose → Output

Avoids the "letter over spirit" failure — where AI follows your literal words but misses your actual goal.

❌  "Make this email shorter."  
    (AI deletes the call-to-action — technically shorter, useless)

✅  "Make this email shorter. 
    Goal: keep executive attention while preserving the final 
    recommendation and the Friday deadline."

Rule: Any time you use a comparative ("shorter", "better", "more X") — always add what goal it serves.


Meta-Prompting: Use AI to Improve Your Own Prompt

The most powerful technique that 90% of people ignore.

Paste your draft prompt and ask:

"Identify what is missing or ambiguous in this prompt. 
Suggest specific improvements."

Why it works:


Eval-Driven Development: The 5-Step Loop

True prompt engineering requires measurement, not just gut feel.

Set Goal → Write v1 → Evaluate → Apply ONE Technique → Re-evaluate → Repeat
Step What to do
1. Set a testable goal Define exactly what success looks like (pass/fail checklist)
2. Write v1 (baseline) Simplest possible prompt. Don't over-engineer. Score 2–3/10 is normal
3. Evaluate Run against 30+ diverse cases (happy paths + edge cases + adversarial)
4. Apply ONE technique Add constraints, examples, or XML. One change per iteration only
5. Re-evaluate Compare score vs baseline. Ship if improved, rollback if not

Real example score progression:

Version Change Score
v1 Baseline 2.3/10
v2 Clear & direct wording 3.9/10 (+70%)
v3 Specific guidelines added 7.8/10
v4 Examples added 8.9/10

Anti-Patterns to Avoid

Anti-pattern Problem Fix
Over-politeness ("Could you please, if possible…") Noise and wasted tokens Command directly
Iterate multiple things at once Can't tell what helped 1 change per iteration
Only test 2–5 cases Misses real user distribution 30+ cases with edge cases
No version control on prompts Can't track what's in production Store prompts in .md or .py, commit to Git
Long prompt = more control Lost-in-middle, contradicting signals Tight IPO structure, critical info at edges
Nested XML > 2 levels Claude misparses scope Max 2 levels, flatten if needed
Using XML for short prompts Overkill Only for 20+ lines or mixed content

Quick-Reference Checklist

Before sending a complex prompt, check:


Model Selection Guide

Model Best for
Sonnet Default — balanced speed and quality
Opus Complex reasoning, high-stakes decisions
Haiku Speed, cost-sensitive tasks, generating test datasets
Extended Thinking Deep reasoning, math, ambiguous multi-step problems

Source: Claude Course 2026 — NotebookLM notebook
Notebook: Open in NotebookLM

Powered by Forestry.md