All guides
Practice now
D3 · Prompt engineering

Prompt engineering: techniques and when to use them

The way a prompt is written directly affects the quality, accuracy, and usefulness of an LLM's response. The GENAI-L expects you to recognize the basic prompting techniques and know when to escalate to advanced techniques such as chain-of-thought or ReAct.

What prompt engineering is and why it matters

Prompt engineering is the practice of designing and refining the instructions sent to an LLM (the prompt) to obtain the desired result more reliably and accurately, without modifying the model's weights.

Why it matters

The same model can produce very different results depending on how the task is requested: a vague prompt produces generic or inconsistent responses, while a well-structured prompt (with context, expected format, constraints, and examples) reduces ambiguity and guides the model toward the desired result. It's the fastest and cheapest way to improve a model's output, because it requires no retraining or additional data.

Basic prompting techniques

These five techniques are the foundation of any prompt engineering strategy. They differ mainly in how many examples are included in the prompt and how the interaction is structured.

Zero-shot

The model is asked to perform the task without giving it any prior example, relying on its general knowledge.

"Classify the sentiment of this review as positive, negative, or neutral: 'Shipping took 3 weeks.'"

One-shot

Exactly one example of what the response should look like is included, to calibrate the expected format or style.

"Example: 'It arrived fast' → Positive. Classify: 'Shipping took 3 weeks.'"

Several examples (typically between 2 and 10) are included so the model can better infer the pattern, the format, or the expected nuances of the task, especially useful for classifications with ambiguous categories.

"'It arrived fast' → Positive. 'It never arrived' → Negative. 'It arrived on the estimated date' → Neutral. Classify: 'Shipping took 3 weeks.'"

The model is assigned a specific role or persona (expert, assistant, formal/casual tone) to condition the style, technical level, and approach of the response.

"Act as a lawyer specialized in data protection. Explain in plain language what GDPR means for a small business."

Prompt chaining

A complex task is split into a sequence of simpler prompts, where the output of one step is used as the input for the next, instead of trying to solve everything in a single monolithic prompt.

Step 1: "Summarize this 40-page contract into its key clauses." → Step 2: "From these clauses, identify which ones represent legal risk for the buyer."

Watch out for this on the exam

Zero-shot, one-shot, and few-shot differ only by the number of examples included (0, 1, or several). Role prompting and prompt chaining are orthogonal techniques to that classification: they can be combined with any of the above (for example, few-shot + role prompting in the same prompt).

Advanced techniques: chain-of-thought and ReAct

When a task requires multi-step reasoning, calculations, or interacting with external tools, the basic techniques above tend to fall short. For those cases, there are two advanced techniques.

The model is asked to show its reasoning step by step before giving the final answer, instead of jumping straight to the conclusion. It notably improves accuracy on math, logic, or multi-step problems, because it forces the model to "break down" the problem.

"A train leaves at 14:00 and arrives at 17:30, with a 20-minute stop. Think step by step before calculating the effective total travel time."

When to use it: reasoning problems, math, logic, or decisions with several factors to weigh.

Combines explicit reasoning with the ability to take intermediate actions (such as calling a tool, searching for information, or querying an API) and observing the result before continuing to reason and decide the next step.

"I need the current stock price of a company. Reason about which tool to use, query it, observe the result, and then respond."

When to use it: agents that need to interact with external tools or real-time data, not just generate text.

Chain-of-thought vs. ReAct

Chain-of-thought improves the quality of the model's internal reasoning, but the model still works only with the information it already has in the prompt. ReAct goes a step further: it lets the model pause its reasoning, execute an external action (such as or a search), incorporate the observed result, and keep reasoning — essential for agents that need data that wasn't in their original prompt.

Did you get this topic?

Test what you just learned

A team is building an agent that must check the real-time inventory of an external system before answering whether a product is available, and needs to reason about which action to take at each step of the conversation. Which prompting technique is best suited?

Ready to test "Prompt engineering: techniques and when to use them"?

Put what you learned to the test with original Gen AI Leader exam questions.

Start Gen AI Leader mock exam

Unlimited mock exams with the Pro plan

Log in to track your progress.