Prompt engineering is an essential element in the development, training, and usage of large language models (LLMs) and involves the skillful design of input prompts to improve the performance and accuracy of the model.
In this post, we’ll look at why prompt engineering has been so popular recently, and why it will likely become even more necessary as LLM-enabled apps grow.
Table of Contents
What is Prompt Engineering?

Prompt engineering is the practise of developing and modifying the input to generative AI models such as ChatGPT, GPT-3, DALL-E, Stable Diffusion, Midjourney, and others. The ultimate purpose of prompt engineering is to improve the performance of the language model by providing well-structured, concise, and tailored input that is relevant to the job or application for which the model is designed.
Prompt engineering frequently involves the careful selection of words and phrases included in the prompt, as well as the overall structure and organization of the input, to achieve this purpose. This systematic approach to prompt engineering is essential because even tiny modifications to the prompt can have a major influence on the outcome.
Effective prompt engineering requires an in-depth understanding of the capabilities and limits of large language models (LLMs), as well as the ability to build engaging input prompts. Furthermore, prompt engineering often involves providing context to the LLM in order for it to generate coherent responses, such as by leveraging external documents or proprietary data or framing the input in a way that helps the model understand the context.
In summary, prompt engineering is an important component of dealing with LLMs, and it requires in-depth knowledge of the underlying technology, a sharp eye for detail, and a talent for creating high-quality input prompts.
Prompt Engineering: Key Terms
LLMs are a type of artificial intelligence that has been trained on a huge amount of text data to create human-like replies to natural language inputs.
LLMs are distinguished by their capacity to produce high-quality, cohesive writing that is frequently indistinguishable from that of a human. This cutting-edge performance is attained by training the LLM on a large corpus of text, often several billion words, allowing it to grasp the intricacies of human language.
Below are several key terms related to prompt engineering and LLMs, starting with the main algorithms used in LLMs:
- Word embedding is a basic approach used in LLMs since it is utilized to represent the meaning of words in a numerical manner that can subsequently be analyzed by the AI model.
- Attention mechanisms are LLM algorithms that allow the AI to focus on certain elements of the input text, such as sentiment-related phrases, while creating an output.
- Transformers a common sort of neural network design in LLM research that processes input data through self-attention techniques.
- Fine-tuning is the process of adapting an LLM for a given job or topic by training it on a smaller, relevant dataset.
- Prompt engineering is the expert design of input prompts for LLMs to provide high-quality, coherent outputs.
- Interpretability is the ability to understand and explain the outputs and decisions of an AI system, which is often a challenge and ongoing area of research for LLMs due to their complexity.
Elements of Prompts
- Instructions: The major purpose of the prompt is to offer clear instructions for the language model.
- Context: Context gives extra information to assist the LM in producing more relevant output. This information can come from external sources or be given by the user.
- Input data: Input data is the user’s inquiry or request for which we desire an answer.
- Output indicator: This specifies the format of the answer.
Prompt Engineering: Examples
Let’s take a look at some effective prompt engineering examples from the Awesome ChatGPT Prompts GitHub source.
Python Interpreter
I want you to act like a Python interpreter. I will give you Python code, and you will execute it. Do not provide any explanations. Do not respond with anything except the output of the code. The first code is: “print(‘hello world!’)”
Prompt Generator
I want you to act as a prompt generator. Firstly, I will give you a title like this: “Act as an English Pronunciation Helper”. Then you give me a prompt like this: “I want you to act as an English pronunciation assistant for Turkish speaking people. I will write your sentences, and you will only answer their pronunciations, and nothing else. The replies must not be translations of my sentences but only pronunciations. Pronunciations should use Turkish Latin letters for phonetics. Do not write explanations on replies. My first sentence is “how the weather is in Istanbul? “.” (You should adapt the sample prompt according to the title I gave. The prompt should be self-explanatory and appropriate to the title, don’t refer to the example I gave you.). My first title is “Act as a Code Review Helper” (Give me prompt only)
We can see also find a number of prompt templates in the OpenAI Playground.
Prompt Engineering: Roles
As you can see in these instances, each question includes “role,” which is an important aspect of directing the chatbot, as we saw with the ChatGPT API release. There are numerous roles that must be established:
- System: The “system” message controls the assistant’s general behavior. “You are ChatGPT, a large language model trained by OpenAI,” for example. Answer in as few words as possible. Knowledge cutoff: {knowledge_cutoff} Current date: {current_date}“
- User: These messages give precise instructions to the helper. This will mostly be utilized by application end users, but it can also be hard coded by developers for certain use scenarios.
- Assistant: The assistant message saves past ChatGPT answers or may be supplied by developers to offer examples of desired behavior.
Here’s an example of what a ChatGPT API request looks like:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
]
)
Prompt Engineering: Parameters
Aside from carefully constructing the written part of a prompt, there are several prompt engineering parameters to consider when working with LLMs. For example, let’s look at the API parameters available for GPT-3 Completions in the OpenAI Playground:
- Model: The model to be used for the text completion i.e., text-davinci-003
- Temperature: Lower temperatures provide more predictable and repeated reactions.
- Maximum length: The maximum number of tokens to generate, varies by model but ChatGPT allows for 4000 tokens (approx. 3000 words) shared between the prompt and completion (1 token = ~4 characters).
- Stop sequences: Up to four sequences in which the API stops returning replies.
- Top P: Refers to the probability distribution of the most likely choices for a given decision or prediction i.e., 0.5 means half of all likelihood weighted options are considered.
- Frequency penalty: Used to prevent the model from repeating the same word or parses too often. Frequency penalty is particularly useful for generating long-form text when you want to avoid repetition.
- Presence penalty: This increases the chance that the model will discuss new subjects, i.e., how much to penalize new tokens depending on whether they have previously been in the text.
- Best of: This is used on the server to produce numerous completions and only show the best results. Streaming completions are only available when set to 1.
To summarize, each use case of prompt engineering will have its own set of optimal parameters to get the desired outcomes, thus it’s important learning about and trying different parameter settings to optimize performance.
You can also read ChatGPT Plugins: Concepts and Use Cases.
Prompt Engineering: Use Cases
Now that we’ve covered the fundamentals, here are some of the most typical prompt engineering tasks:
- Text summarization: It can be used to extract essential points from an article or document.
- Answering questions: This is useful when interacting with external documents or databases.
- Text Classification: Helpful for applications such as sentiment analysis, entity extraction, and so on.
- Role-playing: Involves generating text that simulates a conversion for specific use cases and character types (tutors, therapists, analysts, etc.)
- Code generation: The most notable of which is GitHub Copilot
- Reasoning: Good for creating writing that demonstrate logical or problem-solving abilities, such as decision making.
This article is to help you learn about prompt engineering. We trust that it has been helpful to you. Please feel free to share your thoughts and feedback in the comment section below.