Prompt engineering

What is prompt engineering and what techniques can be used to write prompts? Learn more about this topic here.

Definition

Prompt engineering is the art and science of designing prompts for generative AI models in such a way that they deliver optimal results. Especially for large language models (LLMs), it has been shown that the formulation of the user instruction has an enormous influence on the quality of the AI response. Prompt engineering comprises methods for controlling model behavior in a targeted manner using cleverly formulated or structured prompts.

Prompt engineering methods

Since generative models have no explicit understanding of the query, the prompt must contain all the necessary information. Techniques for this are

  • Provide context: A good prompt gives the model enough background. E.g. "You are a helper for medical questions." before the actual question can make the answer more relevant.

  • Provide examples (Few-shot learning): You can precede the prompt with example inputs and outputs to show the model what style of output is desired. This is called few-shot prompting. Example: First provide an example question-answer dialog, then say "Here is a new question: " – the model follows the pattern.

  • Restrict instructions: Explicitly say what the model should not do (e.g. "Answer briefly and avoid technical jargon.").

  • Specify format: For example, if you want a list, you can mention in the prompt, "Give the answer in the form of a numbered list."

  • Stimulate chains of thought (chain of thought): For complex tasks, you can ask the model to think step by step first ("Think step by step:") in order to arrive at a solution more systematically.

  • Assign roles: Putting the model in a specific role (e.g. "You are a historian...") can influence the style and level of detail of the answer.

Prompt engineering is necessary because generative models do not produce guaranteed outputs – however, appropriate inputs can be used to guide probabilities.

Examples

  • Image AI prompts: Prompt engineering is also important for text-to-image generators (such as DALL-E). A prompt "a photorealistic portrait of an old sailor with a pipe, in the style of Rembrandt" controls several aspects (subject, style, quality) and is likely to produce a more focused result than "man on boat".

  • Guide chatbot: In ChatGPT-like systems, specifying "Respond in a formal tone and provide quotes." causes the model to do exactly that – whereas without this instruction, the tone and structure are uncertain.

Meaning

Since the advent of powerful generative models, prompt engineering has become increasingly important because it represents the higher-level programming of these models. Instead of writing code, the task is formulated so precisely in natural language that the model can fulfill it. Good prompts can dramatically increase quality, bad prompts lead to unusable output or hallucinations. A new profession of prompt engineer is even emerging. In the long term, models could become even better, making prompt engineering less critical – but currently it is a key skill in dealing with generative AI.

Back to the overview