Techniques

Prompt engineering techniques: what to use and when

Fifteen prompt engineering techniques compared, from few-shot and chain-of-thought to ReAct, prompt chaining, and compression, with a rule for choosing each.

A technique is a deliberate way of structuring a prompt, or a sequence of prompts, to solve a problem that plain instructions do not. Every technique has a cost in tokens, latency, or complexity. The skill is using the lightest one that works.

The techniques at a glance

Technique What it does Cost
Few-shot prompting Shows examples of the desired output Tokens per call
Role-based prompting Sets expertise, audience, and tone Minimal
Context injection Adds the facts the model lacks Tokens per call
Output constraints Fixes length, format, and allowed values Minimal
Structured output prompting Returns data that matches a schema Minimal
Chain-of-thought Reasons step by step before answering Output tokens, latency
Self-consistency Samples several answers and takes the majority Several calls
Prompt decomposition Splits a problem into sub-questions Design effort
Prompt chaining Runs sub-tasks as separate prompts in sequence Several calls
ReAct Alternates reasoning with tool calls Several calls, tools
Iterative optimization Improves a prompt by measurement Your time
Prompt refinement Edits wording for clarity and precision Your time
Prompt evaluation Scores output against criteria A test set
Prompt testing Reruns checks after every change Automation
Prompt compression Removes tokens without losing meaning Minimal

Techniques that shape a single prompt

Few-shot prompting. Include input and output pairs. Best for judgment calls and custom styles. Guide: few-shot prompting.

Role-based prompting. Open with who the model is and who it is talking to. It selects a register; it does not add knowledge. Guide: system prompts and role prompting.

Context injection. Insert the document, record, or search result the answer depends on, inside delimiters, and instruct the model to answer from it. When the context is fetched automatically, this becomes RAG prompting.

Answer using only the policy in the tags. If it does not say, reply "not covered".

<policy>
{{policy_text}}
</policy>

Output constraints and structured output. Specify the format, the fields, the length, and what to do with missing data. Guide: structured output prompting.

Techniques for reasoning

Chain-of-thought. Ask the model to work through the problem before giving its answer. It helps on multi-step logic and arithmetic with models that do not reason internally. Models with built-in reasoning already do this, and telling them to “think step by step” adds little.

Self-consistency. Run the same reasoning prompt several times and take the most common answer. It trades cost for accuracy on problems with a single correct result.

Both are covered in chain-of-thought prompting and self-consistency.

Techniques that use several prompts

Prompt decomposition. Break a hard question into smaller ones that can each be answered well, then combine the answers.

Prompt chaining. Run those pieces as separate calls, passing each output to the next step. Each prompt stays simple and testable. Guide: prompt chaining and decomposition.

ReAct. Let the model alternate between reasoning and acting: it decides what it needs, calls a tool, reads the result, and continues. This is the loop behind most AI agents. Guide: ReAct prompting.

Techniques for improving a prompt

Iterative optimization and refinement. Run the prompt on a test set, find the failures, change one thing, and measure again. Guide: iterative prompt optimization.

Evaluation and testing. Define what “good” means, score it, and rerun the checks whenever the prompt changes. Guide: prompt testing and evaluation.

Prompt compression. Remove filler, repetition, and unneeded context to cut cost and latency. Guide: token optimization.

How to choose

Work down this list and stop at the first step that solves the problem.

  1. Write a clear instruction with an output format. Most problems end here.
  2. Add the missing context. If the answer is generic or wrong on facts.
  3. Add examples. If the style or the judgment is off.
  4. Ask for reasoning. If the task needs several logical steps and the model is not a reasoning model.
  5. Split the task into a chain. If one prompt is doing too many things.
  6. Give the model tools. If it needs live data or has to take actions.
  7. Sample several times. If accuracy on a single-answer problem justifies several calls.

Adding a technique the task does not need makes a prompt longer, slower, and harder to debug.

Combining techniques

Techniques stack. A typical production prompt uses a role, injected context, two examples, and a schema. A typical agent uses ReAct over a chain of such prompts. Add one technique at a time and measure, so you know which one earned its place.

Start from a sound base

Techniques amplify a prompt; they do not repair one. Before adding any, run the prompt through the PromptFlowEngine prompt analyzer to clear out vague wording, conflicts, and missing formats, and use the prompt optimizer to structure it.