Prompt engineering is the process of structuringnatural languageinputs (known asprompts) to produce specified outputs from agenerative artificial intelligence (GenAI) model.Context engineering is the related area ofsoftware engineering that focuses on the management of non-prompt contexts supplied to the GenAI model, such asmetadata,API tools, and tokens.
During the 2020sAI boom, prompt engineering became regarded as an important business capability across corporations and industries. Employees with the titleprompt engineer were hired to create prompts that would increase productivity and efficacy, although the individual title has since lost traction in light of AI models that produce better prompts than humans and corporate training in prompting for general employees.
Common prompting techniques include multi-shot, chain-of-thought, and tree-of-thought prompting, as well as the use of assigning roles to the model. Automated prompt generation methods, such asretrieval-augmented generation (RAG), provide for greater accuracy and a wider scope of functions for prompt engineers.Prompt injection is a type ofcybersecurity attack that targetsmachine learning models through malicious prompts.
The Oxford English Dictionary defines prompt engineering as "The action or process of formulating and refining prompts for anartificial intelligence program, algorithm, etc., in order to optimize its output or to achieve a desired outcome; the discipline or profession concerned with this."[1] In 2023, prompt ("an instruction given to an artificial intelligence program, algorithm, etc., which determines or influences the content it generates") was the runner-up to Oxford'sword of the year.[2]
A prompt is somenatural language text that describes and prescribes the task that an artificial intelligence (AI) should perform.[3] A prompt for a text-to-textlanguage model can be a query, acommand, or a longer statement referencing context,instructions, and conversation history. The process of prompt engineering may involve designing clear queries, refining wording, providing relevant context, specifying the style of output, and assigning a character for the AI to mimic in order to guide the model toward more accurate, useful, and consistent responses.[4][5]
When communicating with atext-to-image or a text-to-audio model, a typical prompt contains a description of a desired output such as "a high-quality photo of an astronaut riding a horse"[6] or "Lo-fi slow BPM electro chill with organic samples".[7] Prompt engineering may be applied to text-to-image models to achieve a desired subject, style, layout, lighting, and aesthetic.[8]
Common terms used to describe various specific prompt engineering techniques includechain-of-thought,[9]tree-of-thought,[10] andretrieval-augmented generation (RAG).[11] A 2024 survey of the field identified over 50 distinct text-based prompting techniques, 40 multimodal variants, and a vocabulary of 33 terms used across prompting research, highlighting a present lack of standardised terminology for prompt engineering.[12]
Vibe coding is anAI-assisted software development method where a user prompts an LLM with a description of what they want and lets it generate or edit the code. In 2025, "vibe coding" was theCollins Dictionary word of the year.[13]
Context engineering is a related process that focuses on the context elements that accompany user prompts, which include system instructions, retrieved knowledge, tool definitions, conversation summaries, and task metadata. Context engineering is performed to improve reliability, provenance and token efficiency inproduction LLM systems.[14][15] The concept emphasises operational practices such as token budgeting, provenance tags, versioning of context artifacts, observability (logging which context was supplied), and context regression tests to ensure that changes to supplied context do not silently alter system behaviour.[16]
Research has found that the performance oflarge language models (LLMs) is highly sensitive to choices such as the ordering of examples, the quality of demonstration labels, and even small variations in phrasing. In some cases, reordering examples in a prompt produced accuracy shifts of more than 40 percent.[12]
A model's ability to temporarily learn from prompts is known asin-context learning. In-context learning is anemergent ability[17] of large language models. It is an emergent property of model scale, meaning that breaks inscaling laws occur, leading to its efficacy increasing at a different rate in larger models than in smaller models.[17][18] Unlike training andfine-tuning, which produce lasting changes, in-context learning is temporary.[19] Training models to perform in-context learning can be viewed as a form ofmeta-learning, or "learning to learn".[20]
Research consistently demonstrates that LLMs are highly sensitive to subtle variations in prompt formatting, structure, and linguistic properties. Some studies have shown up to 76 accuracy points across formatting changes in few-shot settings.[21] Linguistic features significantly influence prompt effectiveness—such as morphology, syntax, and lexico-semantic changes—which meaningfully enhance task performance across a variety of tasks.[5][22] Clausal syntax, for example, improves consistency and reduces uncertainty in knowledge retrieval.[23] This sensitivity persists even with larger model sizes, additional few-shot examples, or instruction tuning.
To address sensitivity of models and make them more robust, several evaluative methods have been proposed. FormatSpread facilitates systematic analysis by evaluating a range of plausible prompt formats, offering a more comprehensive performance interval.[21] Similarly, PromptEval estimates performance distributions across diverse prompts, enabling robust metrics such as performance quantiles and accurate evaluations under constrained budgets.[24]
A prompt may include a few examples for a model to learn from in context, an approach calledfew-shot learning.[25][9] For example, the prompt may ask the model to complete "maison → house,chat → cat,chien →", with the expected response beingdog.[26]
Chain-of-thought (CoT) prompting is a technique that allowslarge language models (LLMs) to solve a problem as a series of intermediate steps before giving a final answer. In 2022,Google Brain reported that chain-of-thought prompting improvesreasoning ability by inducing the model to answer a multi-step problem with steps of reasoning that mimic atrain of thought.[9][27] Chain-of-thought techniques were developed to help LLMs handle multi-step reasoning tasks, such asarithmetic orcommonsense reasoning questions.[28][29]
When applied toPaLM, a 540 billion parameterlanguage model, according to Google, CoT prompting significantly aided the model, allowing it to perform comparably with task-specificfine-tuned models on several tasks, achievingstate-of-the-art results at the time on the GSM8Kmathematical reasoningbenchmark.[9] It is possible to fine-tune models on CoT reasoning datasets to enhance this capability further and stimulate betterinterpretability.[30][31]
As originally proposed by Google,[9] each CoT prompt is accompanied by a set of input/output examples—calledexemplars—to demonstrate the desired model output, making it afew-shot prompting technique. However, according to a later paper from researchers at Google and theUniversity of Tokyo, simply appending the words "Let's think step-by-step"[32] was also effective, which allowed for CoT to be employed as azero-shot technique.
Self-consistency performs several chain-of-thought rollouts, then selects the most commonly reached conclusion out of all the rollouts.[33][34]
Tree-of-thought prompting generalizes chain-of-thought by generating multiple lines of reasoning in parallel, with the ability to backtrack or explore other paths. It can usetree search algorithms likebreadth-first,depth-first, orbeam.[10]
In 2022,text-to-image models likeDALL-E 2,Stable Diffusion, andMidjourney were released to the public. These models take text prompts as input and use them to generate images.[35][8] Early text-to-image models typically do not understand negation, grammar and sentence structure in the same way aslarge language models, and may thus require a different set of prompting techniques. The prompt "a party with no cake" may produce an image including a cake.[36]
A text-to-image prompt commonly includes a description of the subject of the art, the desired medium (such asdigital painting orphotography), style (such ashyperrealistic orpop-art), lighting (such asrim lighting orcrepuscular rays), color, and texture.[37] Word order also affects the output of a text-to-image prompt. Words closer to the start of a prompt may be emphasized more heavily.[38]
Some text-to-image models are capable of imitating the style of particular artists by name. For example, the phrasein the style of Greg Rutkowski has been used in Stable Diffusion and Midjourney prompts to generate images in the distinctive style of Polish digital artistGreg Rutkowski.[39] Famous artists such asVincent van Gogh andSalvador Dalí have also been used for styling and testing.[40]
For text-to-image models,textual inversion performs an optimization process to create a newword embedding based on a set of example images. This embedding vector acts as a "pseudo-word" which can be included in a prompt to express the content or style of the examples.[41]
In 2023,Meta's AI research released Segment Anything, acomputer vision model that can performimage segmentation by prompting. As an alternative to text prompts, Segment Anything can accept bounding boxes, segmentation masks, and foreground/background points.[42]
The process of writing and refining a prompt for an LLM or generative AI shares some parallels with an iterative engineering design process, such as by discovering reusable best practices through reproducible experimentation. But the techniques that improve performance depend heavily on the specific model being used. Such patterns are also volatile and exhibit significantly different results from seemingly insignificant prompt changes.[43][44]
Recent research has explored automated prompt engineering, using optimization algorithms to generate or refine prompts without human intervention. These automated approaches aim to identify effective prompt patterns by analyzing model gradients, reinforcement feedback, or evolutionary processes, reducing the need for manual experimentation.[45]
Retrieval-augmented generation is a technique that enables GenAI models to retrieve and incorporate new information. It modifies interactions with an LLM so that the model responds to user queries with reference to a specified set of documents, using this information to supplement information from its pre-existingtraining data. This allows LLMs to use domain-specific and/or updated information.[11]
RAG improves large language models by incorporatinginformation retrieval before generating responses. Unlike traditional LLMs that rely on static training data, RAG pulls relevant text from databases, uploaded documents, or web sources. By dynamically retrieving information, RAG enables AI to generate more accurate responses and fewerAI hallucinations without frequent retraining.[46]

GraphRAG (coined byMicrosoft Research) is a technique that extends RAG with the use of aknowledge graph to allow the model to connect disparate pieces of information, synthesize insights, and understand summarized semantic concepts over large data collections. It was shown to be effective on datasets like the Violent Incident Information from News Articles.[47][48][49]
LLMs themselves can be used to compose prompts for LLMs.[50] Theautomatic prompt engineer algorithm uses one LLM tobeam search over prompts for another LLM:[51][52]
CoT examples can be generated by LLM themselves. In "auto-CoT", a library of questions are converted to vectors by a model such asBERT. The question vectors areclustered. Questions close to thecentroid of each cluster are selected, in order to have a subset of diverse questions. An LLM does zero-shot CoT on each selected question. The question and the corresponding CoT answer are added to a dataset of demonstrations. These diverse demonstrations can then added to prompts for few-shot learning.[53]
Automatic prompt optimization techniques refine prompts for large language models by automatically searching over alternative prompt strings using evaluation datasets and task-specific metrics:
In "prefix-tuning",[58] "prompt tuning", or "soft prompting",[59]floating-point vectors are searched directly bygradient descent to maximize the log-likelihood on outputs. An earlier result uses the same idea of gradient descent search, but is designed for masked language models like BERT, and searches only over token sequences, rather than numerical vectors. Formally, it searches for where ranges over token sequences of a specified length.[60]
In 2018, researchers first proposed that all previously separate tasks innatural language processing (NLP) could be cast as question-answer problems over a context. In addition, they trained a first single, joint, multi-task model that would answer any task-related question like "What is the sentiment" or "Translate this sentence to German" or "Who is the president?"[61]
TheAI boom saw an increased focus within academic literature and professional practice on applying prompting techniques to get the model to output the desired outcome and avoidnonsensical output, a process characterized bytrial-and-error.[62] After the release ofChatGPT in 2022, prompt engineering was soon seen as an important business skill; companies began hiring dedicated prompt engineers, although, given advances in AI's ability to generate prompts better than humans, the employment market for prompt engineers has faced uncertainty.[4] According toThe Wall Street Journal in 2025, the job of prompt engineer was one of the hottest in 2023, but has become obsolete due to models that better intuit user intent and to company trainings.[63]
A repository for prompts reported that over 2,000 public prompts for around 170 datasets were available in February 2022.[64] In 2022, thechain-of-thought prompting technique was proposed byGoogle researchers.[9][65] In 2023, several text-to-text and text-to-image prompt databases were made publicly available.[66][67] The Personalized Image-Prompt (PIP) dataset, a generated image-text dataset that has been categorized by 3,115 users, has also been made available publicly in 2024.[68]
Prompt injection is acybersecurity exploit in which adversaries craft inputs that appear legitimate but are designed to cause unintended behavior inmachine learning models, particularly large language models. This attack takes advantage of the model's inability to distinguish between developer-defined prompts and user inputs, allowing adversaries to bypass safeguards and influence model behaviour. While LLMs are designed to follow trusted instructions, they can be manipulated into carrying out unintended responses through carefully crafted inputs.[69][70]
We demonstrate language models can perform down-stream tasks in a zero-shot setting – without any parameter or architecture modification
Next, I gave a more complicated prompt to attempt to throw MusicGen for a loop: "Lo-fi slow BPM electro chill with organic samples."
In prompting, a pre-trained language model is given a prompt (e.g. a natural language instruction) of a task and completes the response without any further training or gradient updates to its parameters... The ability to perform a task via few-shot prompting is emergent when a model has random performance until a certain scale, after which performance increases to well-above random
By the time you type a query into ChatGPT, the network should be fixed; unlike humans, it should not continue to learn. So it came as a surprise that LLMs do, in fact, learn from their users' prompts—an ability known as in-context learning.
Training a model to perform in-context learning can be viewed as an instance of the more general learning-to-learn or meta-learning paradigm
Prompt engineering is the process of structuring words that can be interpreted and understood by atext-to-image model. Think of it as the language you need to speak in order to tell an AI model what to draw.
Using only 3-5 images of a user-provided concept, like an object or a style, we learn to represent it through new "words" in the embedding space of a frozen text-to-image model.
In this paper, we propose prefix-tuning, a lightweight alternative to fine-tuning... Prefix-tuning draws inspiration from prompting
In this work, we explore "prompt tuning," a simple yet effective mechanism for learning "soft prompts"...Unlike the discrete text prompts used by GPT-3, soft prompts are learned through back-propagation