In this article
The basics
What is prompt engineering, and is it more than writing a good sentence?
Prompt engineering is the practice of designing, testing and versioning the input to a language model so that it produces the output an application needs. It is more than wording: it covers the structure of the input, examples, output format, evaluation against success criteria and change control. Anthropic's guide assumes you begin with a clear definition of success and a way to test against it empirically, then improve a first draft (Anthropic documentation, read 2026-10-24).
Why it is asked: it separates people who tinker from people who measure.
Read the full explanation: the prompting hub.
What goes into a well-built prompt?
A well-built prompt separates five things: the standing rules and role, the context or reference material, the examples, the task, and the required output format. OpenAI's guide puts the rules in developer messages and the inputs in user messages. It suggests identity, instructions, examples and context, usually in that order, and notes that the best order varies by model. It also advises Markdown headers or Extensible Markup Language (XML) tags to mark each part (OpenAI documentation, read 2026-10-24).
Why it is asked: it tests whether you think in structure rather than in clever phrases.
Read the full explanation: the prompting hub.
Text description of the diagram
- Developer or system messages carry the standing rules and business logic.
- User messages carry the input the rules act on.
- Markdown headers or Extensible Markup Language (XML) tags mark each part.
- Examples should show a diverse range of possible inputs with the desired outputs.
When do you prompt, and when do you fine-tune instead?
Prompt first, because a prompt is cheaper to change and test, and move to fine-tuning only when evaluation shows prompting cannot reach the success criteria. Anthropic's guide notes that not every failing criterion is best solved by prompting: latency and cost can sometimes be improved more easily by choosing a different model. The Generative Pre-trained Transformer (GPT) 3 paper presented few-shot prompting as an alternative to the thousands or tens of thousands of task-specific examples that fine-tuning needs (Brown et al., 2020).
Why it is asked: it tests judgment about cost, speed and evidence.
Read the full explanation: the prompting hub.
How do you know a prompt change made things better?
Run both versions on a fixed set of representative inputs and compare scores against written success criteria; never judge from a handful of samples. OpenAI's guide recommends building tests and evaluation suites that measure prompt behaviour so you can monitor performance as you iterate, and pinning production applications to specific model snapshots so that a model upgrade does not silently change results (OpenAI documentation, read 2026-10-24).
Why it is asked: evaluation is the skill that makes the rest credible.
Read the full explanation: large language model (LLM) observability.
Examples and reasoning
What is the difference between zero-shot, one-shot and few-shot prompting?
The difference is the number of worked examples placed in the prompt: none, one, or a handful. The GPT-3 paper showed that a large model can do tasks when the task and the demonstrations are specified purely as text, with no gradient updates, and that few-shot performance improves with scale (Brown et al., 2020). Choose examples that cover varied cases: OpenAI advises showing a diverse range of possible inputs with the desired outputs.
Why it is asked: it is the vocabulary every other prompting question builds on.
Read the full explanation: the prompting hub.
Few-shot answers change on near-identical inputs. How do you stabilise them?
Treat it as a bias problem and test across orderings. Zhao et al. found that changing the prompt format, the examples or their order can move accuracy from near chance to near state-of-the-art, because models favour answers near the end of the prompt or common in pre-training data. Their contextual calibration estimates that bias with a content-free input such as "N/A" and corrects for it, raising average accuracy by up to 30 points (Zhao et al., 2021). In practice: shuffle examples and balance labels.
Why it is asked: it checks that you know few-shot prompting is fragile.
Read the full explanation: the prompting hub.
Do the labels in your examples have to be correct?
Less than you would expect for smaller models, but scale changes this. Min et al. found that randomly replacing demonstration labels barely hurt classification and multiple-choice performance across 12 models including GPT-3, because demonstrations mainly show the label space, the input distribution and the format (Min et al., 2022). Wei et al. later found that large models follow flipped labels and override what they learned in pre-training, while small models ignore them (Wei et al., 2023). Keep labels correct.
Why it is asked: it tests whether you know what examples actually teach.
Read the full explanation: the prompting hub.
What is chain-of-thought prompting?
Chain-of-thought prompting is a technique that asks the model to write intermediate reasoning steps before its final answer, usually by showing worked examples that include the reasoning. Wei et al. reported gains on arithmetic, commonsense and symbolic tasks and found that the ability emerges in sufficiently large models: with a 540-billion-parameter model and eight exemplars they reached state-of-the-art accuracy on the GSM8K benchmark (Wei et al., 2022). It costs extra output tokens, so use it where several steps are needed.
Why it is asked: it is the standard technique for reasoning tasks and has a clear cost.
Read the full explanation: the prompting hub.
Does "think step by step" work without examples?
Often yes: adding a reasoning trigger such as "Let's think step by step" is called zero-shot chain-of-thought. Kojima et al. reported that with InstructGPT (text-davinci-002) accuracy on MultiArith rose from 17.7% to 78.7% and on GSM8K from 10.4% to 40.7% (Kojima et al., 2022). These are results for one model family in 2022, so test the trigger on your own model rather than assuming it helps.
Why it is asked: it checks that you cite evidence and caveat it.
Read the full explanation: the prompting hub.
What is self-consistency, and when does it help?
Self-consistency is a decoding method that samples several reasoning paths and returns the most common final answer. Wang et al. reported 17.9 points more than greedy chain-of-thought on GSM8K with PaLM 540B, and gains even where most samples were wrong, such as LaMDA 137B rising from 17.1% to 27.7%, because wrong paths scatter across different answers (Wang et al., 2022, Table 2). Voting needs the right answer to be the most common one. On a two-answer task, that means each sample is right more than half the time.1
Why it is asked: it tests whether you understand when ensembling helps and when it hurts.
Read the full explanation: the prompting hub.
Text description of the diagram
- On a two-answer task with independent samples, a majority of 5 is right 68.3 percent of the time at 60 percent per-sample accuracy and 31.7 percent at 40 percent.
- Real samples are correlated, so real gains are smaller.
- Open-ended self-consistency votes on the most common final answer, so it can help even when most single samples are wrong (Wang et al., Table 2).
Is a model's chain-of-thought a faithful account of how it decided?
Not necessarily: a written explanation can be plausible without being the true reason for the answer. Turpin et al. showed that biasing features, such as reordering the options in a few-shot multiple-choice prompt so the answer is always "(A)", heavily influenced explanations that systematically failed to mention them, and biasing models toward incorrect answers cut accuracy by as much as 36% on 13 tasks from a public benchmark (Turpin et al., 2023). Treat reasoning text as useful for the answer, not as proof of the mechanism.
Why it is asked: it separates users of the technique from people who know its limits.
Read the full explanation: chain-of-thought follow-up questions on the prompting hub.
What is ReAct prompting?
ReAct is a prompting method that has a model interleave reasoning steps with actions, such as querying a search or Wikipedia tool, so that reasoning can plan and update while actions bring in outside facts. Yao et al. reported that it reduced the hallucination and error propagation seen in chain-of-thought on question answering and fact verification, and outperformed imitation and reinforcement learning baselines on two interactive tasks using one or two in-context examples (Yao et al., 2022). It is the pattern that tool-using agents build on.
Why it is asked: it bridges prompting and agent design.
Read the full explanation: AI agents.
Knowing it is half the job. Saying it is the other half.
Interview Clozo is an AI interview copilot for real interview rounds: it hears the question and puts a strong answer on your screen, and you say it in your own words. See the features or how it works.
Start Free Trial →Structure, long context and production
How do you get reliable structured output such as JSON from a model?
Specify the schema in the prompt, show an example, validate the output in code, such as by parsing the JavaScript Object Notation (JSON) it returns, and retry or repair on failure, using constrained decoding where the provider offers it. OWASP lists defining and validating expected output formats as an injection control (OWASP, Prompt Injection, 2025), and the same habit keeps downstream code from trusting free text. Measure format failures like any other defect: count how many of a hundred test inputs fail to parse.
Why it is asked: it tests whether you treat a model as an unreliable component.
Read the full explanation: getting reliable JSON from an LLM.
How do you handle long contexts and many retrieved documents?
Put the most important material at the start or end and send fewer, better passages. Liu et al. found that performance is often highest when relevant information is at the beginning or end of the input and drops significantly when it is in the middle, even for models built for long contexts (Liu et al., 2023). Retrieve broadly, rerank, trim to what is needed, and test where the answer-bearing passage sits.
Why it is asked: it connects prompting to retrieval design.
Read the full explanation: what a cross-encoder reranker is and how it works and the vector search hub.
What is the difference between a system (developer) message and a user message?
The system or developer message carries the application's standing rules; the user message carries the input for this request. OpenAI describes developer messages as providing the system's rules and business logic, like a function definition, and user messages as the inputs those rules act on (OpenAI documentation, read 2026-10-24). Keeping rules apart from untrusted input also limits what a user message can change, though it does not eliminate injection.
Why it is asked: it checks that you separate trusted from untrusted text.
Read the full explanation: the prompting hub.
How do you version and test prompts in production?
Treat a prompt like code: keep it in version control, pin the model snapshot, run an evaluation suite on every change and monitor live behaviour. OpenAI recommends pinning production applications to specific model snapshots and building evaluation suites that measure prompt behaviour. Without pinning, a provider's model update can change outputs with no change in your repository.
Why it is asked: it separates prototypes from production systems.
Read the full explanation: LLM observability.
Safety
What is prompt injection?
Prompt injection is input that changes a model's behaviour in ways the developer did not intend. OWASP's 2025 list separates direct injection, where the user's own prompt alters behaviour, from indirect injection, where the model ingests external content such as a web page or file that contains instructions. Impacts it lists include information disclosure, unauthorised access to model functions and arbitrary commands in connected systems (OWASP, Prompt Injection, 2025).
Why it is asked: any application that reads outside text has this risk.
Read the full explanation: prompt injection in the AI engineer question list.
How do you reduce the risk of prompt injection?
Layer controls, because OWASP says it is unclear whether prompt injection can be fully prevented. Its mitigations are to constrain behaviour in the system prompt, validate output formats, filter input and output, enforce least-privilege access, require human approval for high-risk actions, segregate and label untrusted content and run regular adversarial tests (OWASP, Prompt Injection, 2025). In agent systems least privilege matters most: a model that cannot delete files cannot be tricked into deleting them.
Why it is asked: it tests defence in depth rather than one trick.
Read the full explanation: defending against prompt injection in the AI engineer question list.
Judgment and design
What are the "5 P's of prompting"?
No standard five-P list appears in the papers or in the OpenAI and Anthropic guides cited on this page, and blog guides define their own. Ask which list the interviewer means. A safe reply names the sections OpenAI's guide lists (identity, instructions, examples and context), adds the output format, then says you evaluate the result against success criteria. Do not invent an expansion you cannot source.
Why it is asked: it checks that you do not bluff on a vague term.
Read the full explanation: the prompting hub.
How would you design a prompt that screens incoming news for relevance to one person?
Define the role and objective, the relevance criteria and the exclusions; fix the output schema, for example keep or skip, a one-line reason and a confidence; add two or three diverse labelled examples; then evaluate on a labelled sample before launch. Put each article inside delimiters, tell the model to answer from the article only, and route low-confidence cases to a person. Fix mistakes by changing the criteria and examples, not only the wording.
Why it is asked: it tests the whole method on one concrete task.
Read the full explanation: the prompting hub.
When would you chain several prompts instead of using one?
Chain prompts when a task has distinct stages you want to check or fix separately, such as extract, then decide, then write. Anthropic's guide lists prompt chaining among the techniques it covers. A chain costs extra calls and latency, and an error in an early stage carries forward, so each stage needs its own validation. Use one prompt when the stages are tightly coupled and quality is already acceptable.
Why it is asked: it tests trade-off thinking about cost, latency and debuggability.
Read the full explanation: prompt chaining as an AI agent workflow pattern.
For how these models work underneath, see the transformers hub.
- Prompt engineering is design plus measurement: write a clear definition of success and test every change against it.
- Few-shot prompting is fragile; test example order and balance labels, and spend effort on representative inputs and a consistent format.
- Self-consistency helps when the right answer is the most common one among the samples; on a two-answer task that needs single-sample accuracy above one half.
- Reasoning text is not proof of how the model decided, and long inputs are used least reliably in the middle.
- OWASP says it is unclear whether prompt injection can be fully prevented, so layer least privilege, output validation and human approval.
Sources
- Larger language models do in-context learning differently — arXiv (Wei et al.), v2 revised 2023-03-08, 7 Mar 2023
- Chain-of-Thought Prompting Elicits Reasoning in Large Language Models — arXiv (Wei et al.), v6 revised 2023-01-10, 28 Jan 2022
- Large Language Models are Zero-Shot Reasoners — arXiv (Kojima et al.), NeurIPS 2022, 24 May 2022
- Self-Consistency Improves Chain of Thought Reasoning in Language Models — arXiv (Wang et al.), ICLR 2023, 21 Mar 2022
- Rethinking the Role of Demonstrations: What Makes In-Context Learning Work? — arXiv (Min et al.), 25 Feb 2022
- Calibrate Before Use: Improving Few-Shot Performance of Language Models — arXiv (Zhao et al.), ICML 2021, 19 Feb 2021
- Language Models are Few-Shot Learners — arXiv (Brown et al.), 28 May 2020
- ReAct: Synergizing Reasoning and Acting in Language Models — arXiv (Yao et al.), ICLR 2023, 6 Oct 2022
- Language Models Don't Always Say What They Think: Unfaithful Explanations in Chain-of-Thought Prompting — arXiv (Turpin et al.), NeurIPS 2023, 7 May 2023
- Lost in the Middle: How Language Models Use Long Contexts — arXiv (Liu et al.), v3 revised 2023-11-20, 6 Jul 2023
- LLM01:2025 Prompt Injection — OWASP Top 10 for LLM Applications 2025, 1 Jan 2025
- Prompt engineering overview — Anthropic documentation (read 2026-10-24), 24 Oct 2026
- Prompt engineering guide — OpenAI documentation (read 2026-10-24), 24 Oct 2026