- Introduced by
- Tom Brown et al. (GPT-3 / few-shot framing, 2020); chain-of-thought extended by Jason Wei et al. (2022)
- Year
- 2020 (few-shot prompting); 2022 (chain-of-thought)
- Type
- NLP pipeline — structured instruction design for large language models
What does it do?
Prompt engineering is the practice of writing natural-language instructions, or prompts, that steer a large language model (LLM) toward a target output without changing the model's weights.
Brown et al. (2020) showed with GPT-3 that such models can perform new tasks from a few in-context examples, and Wei et al. (2022) showed that asking the model to produce intermediate reasoning steps, known as chain-of-thought prompting, improves performance on multi-step reasoning tasks. The main strategies named on this page are zero-shot, few-shot, chain-of-thought and tree-of-thought prompting.
The intuition behind the method
A large language model can only use what is in its current input, so the wording of that input largely determines what it returns. Prompt engineering is the discipline of writing that input so the model produces the output you need, much as one would brief a capable assistant who has no prior context on the project. Zero-shot prompting states the task with no examples. Few-shot prompting places worked examples before the live item to show the expected format and reasoning pattern. Chain-of-thought prompting asks the model to reason step by step before answering, and tree-of-thought prompting asks it to consider several reasoning branches before settling on an answer.
History
Brown et al. (2020) introduced GPT-3 and showed that a large language model can perform tasks from a small number of in-context examples, including zero-shot and few-shot settings, without gradient updates. Wei et al. (2022) then showed that prompting the model to produce intermediate reasoning steps, chain-of-thought prompting, substantially improved performance on arithmetic, commonsense and symbolic reasoning benchmarks.
When to use it
Choose prompt engineering when you have access to a capable LLM and a text task that can be stated clearly, such as classification, extraction, summarisation, generation or multi-step reasoning. It suits situations where labelled training data are scarce, where fine-tuning is too costly or slow, or where prototypes need to be tested quickly. Do not rely on it when no LLM API is accessible, when the task requires exact numerical computation (model arithmetic should be checked with a calculator or code), or when required accuracy is so high that prompt-only results cannot be validated against a labelled set. In those cases, fine-tuning (for example LoRA, listed under related methods) or retrieval-augmented generation should be considered.
Limitations and considerations
- Output quality depends heavily on the model's pre-training knowledge; tasks requiring domain-specific or recent knowledge not in the model may fail.
- LLMs can hallucinate — generate plausible-sounding but factually incorrect outputs — especially when prompted on topics outside their training distribution.
- Prompt sensitivity: small changes in wording can lead to substantially different outputs (Webson & Pavlick, 2022 report that seemingly minor prompt adjustments can have disproportionately large effects), making robust evaluation over multiple prompt variants necessary.
- API cost and latency scale with the number of tokens; large few-shot prompts or complex chain-of-thought traces can be expensive at scale.
- Confidentiality and data protection: text sent to a third-party LLM API leaves the local environment, and the provider's retention and training policies may not suit personal or sensitive data. Such use should be reviewed against data-protection and ethics requirements before any prompt is run.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- No model training or labelled dataset is needed to obtain a first result; zero-shot prompting uses only the task description.
- Highly flexible: the same underlying model can be directed to classify, summarise, extract, translate or reason simply by changing the prompt.
- Fast to iterate: changes to prompt design can be tested immediately, without a training cycle.
- As reported by Wei et al. (2022), chain-of-thought prompting improves results on multi-step reasoning tasks on which direct answering performs poorly.
Applications
- Text classification when labelled training data are limited or unavailable — zero-shot and few-shot prompts ask the model to assign categories.
- Information extraction: prompting the model to identify named entities, relationships or fields in unstructured documents.
- Summarisation of source documents, with outputs checked against the source text.
- Step-by-step reasoning on problems where a justification trace is required; such traces should be reviewed by a domain expert before use.
- Structured extraction into JSON or other machine-readable formats, with the required format stated explicitly in the prompt.
How it works
How it works
Before drafting a prompt, specify the task precisely: the input the model will receive, the form the output must take, and what counts as a correct answer. Vague task definitions tend to produce inconsistent outputs, so these criteria should be fixed before any prompt is written. Access to an LLM API and a task that can be stated unambiguously are preconditions for the method.
The prompt is built to match the chosen strategy. A zero-shot prompt states the task directly, for example 'Classify the following review as positive, negative, or neutral: ...'. A few-shot prompt prepends a small number of worked input–output examples to the live item, conveying the format and reasoning pattern without any weight update. The number of examples that works best depends on the task and the model, so it should be tested on a validation set. A chain-of-thought prompt adds an explicit instruction to reason step by step; Wei et al. (2022) reported substantial gains with this approach on arithmetic, commonsense and symbolic reasoning benchmarks. A tree-of-thought prompt frames generation as a search over alternative reasoning branches. Prompt design also covers role specification, output-format constraints (such as JSON or a bullet list) and any safety instructions.
The finished prompt is sent to the model through an API call. The model version, maximum output length, temperature (randomness) and top-p sampling are set to suit the task: low temperature is usually preferred for classification and extraction, where consistency matters, and higher temperature for open-ended generation. The returned completion should be stored together with the exact prompt, the exact model identifier, the API date and the generation settings, so that the run can be reproduced as far as the provider allows. Outputs may still vary between calls, even at low temperature. Hosted models are also updated or retired by their providers, so a result obtained from one model version may change or become unavailable; the evaluation should be re-run whenever the provider changes or retires the model.
The output is assessed against the task specification. Classification outputs are scored with metrics such as accuracy, precision, recall and F1 against a labelled reference set. Free-text outputs can be scored automatically with measures such as ROUGE or BERTScore, or judged by people against a quality rubric. Failures and off-format responses are examined, and the findings feed back into prompt revision. Because prompt design is iterative, this stage usually loops back to design-prompt until the output meets the required standard.
Common pitfalls
- Vague task definitions produce inconsistent outputs — specify the task, the expected output format, and any constraints explicitly in the prompt.
- Hallucination risk is highest when the model is asked to recall specific facts, statistics, or citations; always verify factual claims against authoritative sources.
- Evaluating only on a handful of examples can give a misleading picture of reliability — test prompts on a representative sample before deploying.
- Applying a prompt designed for one model to a different model family without revision often degrades performance, since instruction-following behaviour varies across architectures and training regimes.
- Omitting output-format constraints (e.g., requiring JSON) frequently results in free-form text that downstream code cannot parse — always specify the exact format expected.
- Test-set contamination: public benchmark items or other labelled data may already appear in the model's pre-training corpus, which can inflate measured accuracy. Interpret results with this possibility in mind and, where possible, check performance on data the model is unlikely to have seen.
Frequently asked questions
What is the difference between zero-shot, few-shot, and chain-of-thought prompting?
Zero-shot prompting states the task and asks the model to respond with no examples. Few-shot prompting prepends a small number of worked examples to show the model the desired format and reasoning pattern. Chain-of-thought prompting adds an explicit instruction to reason step by step before giving the final answer, which markedly improves performance on tasks that require multi-step reasoning.
Do I need labelled data to use prompt engineering?
Not necessarily. Zero-shot prompting requires no labelled data at all. Few-shot prompting needs only a small number of hand-crafted or carefully selected examples, which are embedded directly in the prompt. Evaluation against a labelled reference set is, however, recommended before deploying any prompt in a production or research context.
How do I know if my prompt is good enough?
Run the prompt on a labelled sample drawn from your own data and compute the metrics suited to your task: accuracy and F1 for classification, ROUGE or BERTScore for summarisation, or human ratings for open-ended generation. Inspect the failures, revise the prompt and repeat. The sample should be large enough that differences between prompt versions are not driven by a few items. The adequate size depends on the task and the variability of the labels, so it should be judged for your case rather than assumed.
When should I switch from prompt engineering to fine-tuning?
When prompting consistently fails to meet accuracy requirements on a well-defined task, when the task requires knowledge or formatting conventions that prompting alone does not capture, or when inference cost at scale makes large prompts impractical, fine-tuning or parameter-efficient methods such as LoRA become the preferred path.
Related methods
Sources
Brown, T. et al. (2020). Language Models are Few-Shot Learners. Advances in Neural Information Processing Systems (NeurIPS), 33, 1877-1901.
Open publication referenceWei, J. et al. (2022). Chain-of-Thought Prompting Elicits Reasoning in Large Language Models. Advances in Neural Information Processing Systems (NeurIPS), 35.
Open publication referenceBATDI-BASARAN-nitel-arastirmada-yapay-zeka-II, p. 173