arrow_forwardGuides / Prompt Engineering
Updated April 2026 25 min read Beginners and advanced

Prompt Engineering
The complete guide

The skill that separates those who get ordinary answers from those who get impressive results. Zero-shot, CoT, ReAct, System Prompts — it's all here, with real examples.

#1
AI skill
Universal
Works in every model
10x
Improved results
ROI
Immediate

What is Prompt Engineering and why does it matter?

Language models like GPT-4o, Claude and Gemini are like a gifted employee who doesn't know you — give vague instructions and you get mediocre results. Give precise instructions and you get exceptional work. Prompt Engineering is the art of communicating with AI in a way that yields the best results.

It's not programming and not magic — it's structured knowledge anyone can acquire. Studies show that a change in wording alone can improve answer quality by 30%–70%. In 2026, it's one of the most in-demand skills in the job market.

The difference between a good and a bad prompt

The clearest example to immediately grasp the difference:

❌ BAD PROMPT
"Write an article about AI"
✅ GOOD PROMPT
Role: an expert B2B content writer with 10 years of experience.
Task: write an 800-word blog article on AI's impact on the job market.
Target audience: HR managers at tech companies.
Tone: professional yet accessible.
Structure: a title + 3 key points + a conclusion + a CTA.
Avoid: technical jargon without explanation.

The 4 super-principles of every successful prompt

lightbulb
A 10x improvement in results

Google DeepMind's research (2023) showed that people who learned Prompt Engineering got answers 10 times better on average — with no change to the model. The skill is in thewording, not the tool.

To understand why Prompt Engineering matters, consider: an AI model receives hundreds of millions of tokens in training, but doesn't know what you need right now. It aims according to the prompt you give it. A clear prompt = a focused AI. A vague prompt = a guessing AI.

Technique map — Overview

Before we dive into the details, here is the full roadmap of all the techniques we'll learn in this guide:

Technique Difficulty When to use Models
Zero-Shot Beginner Simple tasks, basic classification All
Few-Shot Beginner Consistency, precise format All
Chain-of-Thought Intermediate Reasoning, math, logic GPT-4, Claude, Gemini
System Prompts Intermediate Apps, chatbots, personas All (API)
ReAct Advanced Agents, multi-step tasks GPT-4o, Claude 3.5+
Structured Output Intermediate Production, API integration GPT-4o, Claude, Gemini
Meta-prompting Advanced Automatic optimization GPT-4o, Claude 3.5+

Zero-Shot Prompting — without examples

Zero-shot is the most common technique: you describe what you want without giving the model examples. It works well with GPT-4o and Claude because they're pre-trained on millions of examples.

Role Framing — "Act as..."

The simplest trick: define a precise role before the request. A huge difference in results:

PROMPT EXAMPLE — ROLE FRAMING ✓ Works well
You are a commercial lawyer with 15 years of experience in SaaS agreements.
Review the following liability clause and note:
1. Key risks
2. A balanced alternative wording
3. Points for negotiation

Clause: "The supplier shall not bear any liability for indirect, consequential
or special damages under any circumstances."

5 before-and-after Zero-Shot examples

Example 1 — writing an email
❌ Before
"Write an email to a supplier"
✅ After
"Write a professional email to a supplier
who is 3 weeks late. Tone: assertive
but not aggressive. 3 paragraphs.
Include a two-day deadline."
Example 2 — summarizing a document
❌ Before
"Summarize the report"
✅ After
"Summarize the report into 5 bullet points.
Audience: managers with no technical background.
Include: a key finding, a recommendation, ROI.
Avoid technical terms."
Example 3 — code review
❌ Before
"Review my code"
✅ After
"You are a Senior Python developer.
Review the following function:
1. Possible bugs
2. Performance issues
3. Suggest a short refactor."

Few-Shot Prompting — the power of examples

Few-shot means: give the model 2–5 examples of Input → Output before the real question. Why does it work? Models are excellent pattern-matchers. Examples teach them exactly the format, tone and consistency you want.

A basic Template

PROMPT EXAMPLE — FEW-SHOT SENTIMENT ✓ Works well
Task: classify the sentiment of reviews.

Example 1:
Review: "The product is amazing!"
Sentiment: positive

Example 2:
Review: "Not worth the money"
Sentiment: negative

Example 3:
Review: "OK, it did the job"
Sentiment: neutral

Now:
Review: "Reasonable, room for improvement"
Sentiment:

Few-Shot principles worth knowing

Few-Shot vs Many-Shot

With models like Gemini 2.5 Pro (2M-token context), you can include hundreds of examples. Many-shot prompting trains a model within the prompt itself — without Fine-tuning. It's very economical for businesses that want to adapt a model without GPU cost.

warning
Caution: Label Bias

If all your Few-Shot examples are "positive", the model will tend to classify everything as positive. Keep the examples balanced.

Chain-of-Thought (CoT) — step-by-step reasoning

A research finding from Google (Wei et al., 2022): when you ask the model to "think step by step", accuracy on math and logic problems rises by 40%–60%. The model "explains itself" — which avoids faulty leaps of conclusion.

Zero-Shot CoT — the simple trick

PROMPT EXAMPLE — ZERO-SHOT COT ✓ Works well
Question: if Sarah has 5 apples and gave 2 to John, then bought 3 more, how many does she have?
Think step by step before you answer.

The model's answer with CoT:

Step 1: Sarah starts with 5 apples.
Step 2: she gave 2 to John: 5 - 2 = 3 apples.
Step 3: she bought 3 more: 3 + 3 = 6 apples.
Answer: Sarah has 6 apples.

Few-Shot CoT — with step examples

Even stronger: give the model examples of a reasoning chain, not just an answer:

Question: I have 12 apples. I ate a quarter and gave 2 to a neighbor. How many are left?
Step-by-step answer:
- a quarter of 12 = 3. Left: 12 - 3 = 9.
- gave 2 to the neighbor: 9 - 2 = 7.
Answer: 7 apples.

Question: I have 20 eggs. I broke a third and sold 4. How many are left?
Step-by-step answer:

Self-Consistency — voting between chains

An advanced technique: run the same prompt several times with a temperature > 0, get different reasoning chains, and pick the answer the most chains arrived at. Studies show a 10%–20% improvement over Single CoT.

Tree of Thoughts (ToT)

An extension of CoT: the model imagines a tree of possibilities and evaluates each branch. Suited to complex planning problems. More computationally expensive but excellent for puzzles and optimization.

tips_and_updates
When to use CoT?

Math problems, logic, strategic planning, code debugging, legal analysis. Not suited to simple classification, translation, or creative writing — there CoT is sometimes harmful.

System Prompts — the AI's "personality"

A System Prompt is the instruction given to the AI before every conversation. It determines who it is, what it knows and how it behaves. In ChatGPT it's "Custom Instructions", in Claude it's "System", in the API it's role: "system".

The difference between a system prompt and a user message: a system prompt defines the character, a user message is the specific request. When they conflict — the system prompt wins.

The architecture of a winning System Prompt

Every good system prompt contains 5 layers:

PROMPT EXAMPLE — SYSTEM PROMPT TEMPLATE ✓ Works well
# 1. role definition
You are [a precise role] who works at [company/context].

# 2. goal
Your goal: [one clear primary goal].

# 3. capabilities and limits
What you can do: [list]
What you must not do: [list]

# 4. answer format
Always answer in [format — markdown/JSON/plain text].
Ideal length: [X words/paragraphs].

# 5. tone and style
[professional/warm/technical/accessible] — always in [language].

A full example — a System Prompt for a customer service rep

You are a friendly customer service rep for "Gadgets Store",
an online electronics shop.

The goal: to resolve customer issues quickly and maintain satisfaction.

Rules:
- Always answer in a warm, professional tone
- Don't promise refunds over $150 without manager approval
- If a question is out of scope — refer to support@gadgets.example
- Always include a ticket number at the end of every reply
- Don't make up information about products you're unsure of

Returns: up to 30 days from purchase, with a receipt.
Shipping: 3–5 business days, free over $60.
Service hours: Mon–Fri 9:00–18:00.

XML Tags — a Claude Best Practice

Anthropic recommends using XML tags in system prompts for Claude. It lets the model understand exactly what belongs to which part:

<system>
  <role>a digital marketing expert with 10 years of market experience</role>
  <task>writing marketing content for social media</task>
  <constraints>
    - always in English
    - max 280 characters for Twitter
    - include relevant hashtags
  </constraints>
  <tone>professional, enthusiastic, pragmatic</tone>
</system>

OpenAI vs Claude — differences in approach

Aspect OpenAI (GPT-4o) Anthropic (Claude)
Preferred structure Plain text with headings XML tags
Rule adherence Good Excellent
Request refusals More frequent Rarer
context window 128K tokens 200K tokens

ReAct Pattern — Reasoning + Acting

ReAct (Yao et al., 2022) is a framework to let AI think, act, and observe the results — in a loop. Used mainly in AI Agents. The basic idea: at each step, the model decides what to do, performs an action (Search/Calculate/API), sees the result and decides again.

The ReAct cycle

Thought
arrow_forward
Action
arrow_forward
Observation
→ back to Thought

ReAct Prompt Template

PROMPT EXAMPLE — REACT TEMPLATE ✓ Works well
You are an AI agent that solves complex problems.

For each step, write:
Thought: [what you're thinking right now]
Action: [what you're doing — Search/Calculate/Answer]
Observation: [what you got from the action]
...repeat Thought/Action/Observation until you have an answer...

Final Answer: [the final answer]

Question: {user_question}

An example in Action — looking up a stock price

Question: what is Apple's stock price now and what is its P/E?

Thought: I need an up-to-date stock price and also the P/E figure. I need to search.
Action: search("Apple AAPL stock price PE ratio 2026")
Observation: AAPL: $198.40 | P/E: 32.1 (updated: 3 minutes ago)

Thought: I have both figures. I can answer.
Final Answer: Apple stock (AAPL) is trading at $198.40.
The price-to-earnings ratio (P/E) is 32.1 — relatively high for the sector.

ReAct vs Chain-of-Thought — when to use which?

Criterion Chain-of-Thought ReAct
External information? Not required Yes — search/API
Steps Reasoning only Reasoning + action
Complexity Simple to medium Complex / multi-step
Cost Low Higher
Common use Math, logic Research, debug, agents

Structured Output — JSON, XML, Pydantic

In most Production cases, you want the AI to return structured JSON, not a free-form paragraph. All the major APIs support JSON Mode. This ensures automatic parsing and prevents format hallucinations.

A simple JSON request

Extract the person's details from the following text.
Return JSON only with the structure:
{
  "name": string,
  "email": string | null,
  "phone": string | null,
  "company": string | null
}

Text: "Hello, I'm Danny Levi from Tech-IL.
You can reach me at: danny@tech-il.com or 050-1234567"
The model's answer
{
  "name": "Danny Levi",
  "email": "danny@tech-il.com",
  "phone": "050-1234567",
  "company": "Tech-IL"
}

OpenAI Structured Output with Pydantic

from openai import OpenAI
from pydantic import BaseModel

class Article(BaseModel):
    title: str
    summary: str
    keywords: list[str]
    sentiment: str
    word_count: int

client = OpenAI()
response = client.beta.chat.completions.parse(
    model="gpt-4o-2024-08-06",
    messages=[{"role": "user", "content": f"Analyze: {text}"}],
    response_format=Article,
)
article = response.choices[0].message.parsed
print(article.title)       # "The article title"
print(article.keywords)    # ["AI", "automation", "Israel"]

XML Output — for complex summaries

Analyze the attached lease agreement and return XML:

<analysis>
  <risk_level>[high/medium/low]</risk_level>
  <key_dates>
    <start>[date]</start>
    <end>[date]</end>
  </key_dates>
  <red_flags>
    <flag>[issue 1]</flag>
    <flag>[issue 2]</flag>
  </red_flags>
  <recommendation>[a short recommendation]</recommendation>
</analysis>

Markdown Formatting Requests

You don't always need JSON. Sometimes it's enough to ask for structured Markdown. It's excellent for reports, documentation and posts:

Write a SWOT analysis for an online fashion store.
Format: Markdown with H2 headings for each category.
Each category: 3–5 bullet points.
Add a summary table at the end.

Advanced techniques

Meta-Prompting — a Prompt that writes Prompts

Meta-prompting: you give the AI a description of the task and ask it to write the optimal prompt for it. You can make a loop: AI writes a prompt → AI runs it → AI improves → repeat.

I need to summarize work meetings into Action Items clearly.
Write me an optimal prompt for this task.
Detail: context, output format, rules and tips for improving consistency.

Self-Reflection — "Is your answer correct?"

After getting an answer, ask the AI to check itself. This almost always improves it:

[first answer received]

Now check your answer:
1. Are there factual errors?
2. Did the format meet the requirements?
3. What can be improved?
Provide an improved version if needed.

Prompt Chaining — a Pipeline of Prompts

Instead of one giant prompt that tries to do everything, split the task into steps. The output of each step feeds into the next. More reliable, easier to debug.

Prompt 1: extract facts
arrow_forward
Prompt 2: analyze facts
arrow_forward
Prompt 3: write a report

Negative Prompting — what not to do

Explicitly state what you do not want. This prevents undesired results very effectively:

Write a LinkedIn post about our product launch.
Don't use buzzwords: "revolutionary", "game-changer", "unprecedented".
Don't open with "I'm excited to share".
Don't use emojis.
Max 3 short paragraphs.

Persona + Audience Calibration

Combine: defining a role and also the target audience. Both together give the most precise direction:

You: a CTO with experience at startups.
Audience: VC investors in a Series A meeting.
Explain: why our technical architecture enables scalability to 10M users.
Length: 3 minutes of speech.
Avoid: deep technical details irrelevant to finance.

Constitutional AI Hints

A technique Anthropic developed: define principles inside the prompt. The model will use them as a reasoning framework:

Principles for your answer:
- factual accuracy over false confidence
- if you're unsure — say so
- present at least two viewpoints on controversial topics
- brevity: preferable to unnecessary detail

Question: will AI replace programmers in the next 5 years?

Temperature and Parameters — not in the prompt, but important

Temperature 0 — deterministic, consistent answers. For code, JSON, facts.
Temperature 0.7–1 — creative, varied. For creative writing, ideas.
Top-P (nucleus sampling) — controls vocabulary diversity. Top-P=0.9 is usually enough.
Max Tokens — explicitly limit the answer length. Keep costs down.

Evaluating Prompts — LLM-as-Judge

One of the most powerful techniques: have one AI check another AI's answers. It's called LLM-as-Judge:

# The Judge's System prompt:
You are an expert at evaluating AI answer quality.
Rate the following answer on a 1–10 scale by:
- factual accuracy (30%)
- meeting the requested format (30%)
- writing quality (20%)
- completeness (20%)

Give a numeric score and 2 sentences of explanation.

Answer to evaluate: [...]
The original instructions: [...]

In addition, keep Prompt Versioning — prompts need version control too. Document changes and A/B test between versions. Metrics to track: accuracy, consistency, format compliance, latency.

5 projects to practice

What separates theory from a real skill is practice. Here are 5 graded projects:

1

Prompt Optimizer

Beginner

Give a weak prompt → get an improved prompt automatically.

system = """You are a Prompt Engineering expert.
Take a weak prompt and improve it by 5 principles:
1. Add role framing
2. Define an output format
3. Specify length
4. Add tone
5. Add negative constraints
Return: the improved prompt + a short explanation of the changes."""
2

System Prompt Library

Intermediate

Build a library of 10 system prompts for your business:

  • A customer service rep
  • A marketing content-writing assistant
  • A business data analyst
  • A job-interview coach
  • A legal advisor (disclaimer: not a substitute for a lawyer)
3

CoT Solver

Intermediate

A Python script that solves complex problems with CoT and returns structured JSON.

import openai, json

def cot_solve(problem: str) -> dict:
    prompt = f"""Solve: {problem}

Think step by step.
Return JSON:
{{"steps": [...], "answer": "...", "confidence": 0-100}}"""

    r = openai.chat.completions.create(
        model="gpt-4o",
        messages=[{"role":"user","content":prompt}],
        response_format={"type":"json_object"}
    )
    return json.loads(r.choices[0].message.content)
4

ReAct Agent

Advanced

A Python agent with a Thought/Action/Observation loop and tool calling.

tools = {
  "search": lambda q: web_search(q),
  "calculate": lambda x: eval(x),
  "lookup": lambda k: knowledge_base[k]
}

def react_agent(question: str, max_steps=5):
    history = [{"role":"system","content":REACT_SYSTEM}]
    history.append({"role":"user","content":question})

    for _ in range(max_steps):
        response = llm(history)
        if "Final Answer:" in response:
            return extract_answer(response)
        action = parse_action(response)
        obs = tools[action.type](action.input)
        history.append({"role":"assistant","content":response})
        history.append({"role":"user","content":f"Observation: {obs}"})
5

Auto-Prompt Engineer

Advanced

An LLM that improves prompts automatically based on LLM-as-Judge feedback. A self-improvement loop.

def auto_improve(prompt, task, n_iterations=3):
    for i in range(n_iterations):
        output = run_prompt(prompt, task)
        score = judge_output(output, task)  # LLM judge
        if score >= 9: break
        prompt = improve_prompt(prompt, output, score)
        print(f"Iteration {i+1}: score={score}")
    return prompt, output

Cheat sheet — Cheatsheet

A technique comparison table

Technique Token cost Accuracy improvement When?
Zero-ShotLowbaseAlways as a starting point
Few-ShotMedium+30–50%Format / consistency
CoT Zero-ShotLow+40%Logic / math
CoT Few-ShotMedium+60%Complex problems
Self-ConsistencyHigh+70%Critical accuracy
ReActHighExternal informationAgents / research

10 ready-to-use Templates

T1 — content writing
You are [a writer role]. Write [content type] about [topic].
Audience: [describe audience]. Tone: [professional/creative/conversational].
Length: [X words]. Include: [elements]. Avoid: [X].
T2 — data analysis
Analyze the following data: [data]
Find: 1) main trends 2) anomalies 3) recommendations.
Format: a table + 3 bullet insights + one recommendation.
T3 — Code Review
You are a Senior [language] developer. Review:
[code]
Note: 1) bugs 2) security issues 3) performance
4) refactor suggestions. Rate severity: Critical/High/Low.
T4 — translation + localization
Translate from [language] to modern natural English.
Keep: a professional tone, technical terms where appropriate,
natural idioms. Don't translate idiomatic expressions literally.
T5 — problem solving with CoT
Problem: [description]
Context: [relevant information]
Think step by step, consider at least 2 approaches,
and pick the optimal one. Explain why.

Common mistakes — and how to avoid them

❌ A double question

"Write an article about AI and also explain how to use it" — you'll get something incoherent. Solution: One question per prompt.

❌ Expectation without context

"Write an email to a customer" — which customer? About what? Solution: Context = who, what, why.

❌ Vague parameters

"Write short" — short = 2 lines? 200 words? Solution: Specify a number of words/paragraphs.

❌ A one-off attempt

Prompt Engineering is iteration. Solution: Try → see what doesn't work → improve → repeat.

❌ Over-reliance on memory

In the API every call is independent. Solution: Re-include the context in the System Prompt.

❌ Wrong Temperature

Temperature=1 for math = wrong results. Solution: T=0 for facts, T=0.7+ for creativity.

Model-Specific Tips

Model Strengths Special tip
GPT-4o Code, JSON, format Use response_format: json_object
Claude 3.5+ Consistency, analysis, safety XML tags in the system prompt
Gemini 2.5 Long context, multimodal Many-shot with 2M context
Llama 3+ Fast, free, private A short, precise system prompt
school

The next step — applying it in a real project

Want to take Prompt Engineering a step further? Build an AI Agent that combines all the techniques you learned — System Prompt + ReAct + Structured Output.