A Brief Guide to Prompt Engineering
Prompt engineering is a fundamental technique to get the best results from conversational AI models like ChatGPT. A well-structured prompt is essential to guide the model to provide high quality answers. In this brief guide we will analyze in detail what prompt engineering is and how to apply it most effectively through practical prompt examples.
What is prompt engineering
Prompt engineering consists of carefully structuring the instructions and information provided to the AI model to guide it towards the desired answer.
Example: ChatGPT, I am providing you with some key instructions and information that you must use to answer my question relevantly.
How it works
- It involves providing a clear context and all relevant details for the task assigned to AI.
Example: ChatGPT, the context is as follows: I am preparing a presentation on artificial intelligence for an audience of university students. I need you to provide detailed information on how supervised machine learning works, explaining it simply with concrete examples that can be understandable for students without technical knowledge.
- Guidelines and constraints within which the model must operate must be established.
Example: ChatGPT, I expect an answer of maximum 4-5 sentences, in simple language and free of jargon. Do not include mathematical formulas or complex diagrams.
- A well-constructed prompt helps AI focus on the goal.
Example: ChatGPT, the goal of this conversation is to get from you a simplified explanation of how deep learning works. Keep this goal firmly in mind while building your response.
Assigning a role to the AI
Attributing a role to the AI model, such as “you are an expert in artificial intelligence” can help better guide its responses making them more relevant. By specifying the role it must assume, for example “you are a professional translator”, the model will have a clearer context to provide answers consistent with that role.
Example: ChatGPT, your role in this conversation is that of an artificial intelligence expert. I ask you to provide answers about the functioning and future developments of AI while always maintaining an educational tone and a simple but rigorous explanation.
Why is it important
Prompt engineering is crucial for several reasons:
Avoid wrong or misleading answers
- A vague prompt can confuse the AI and lead it astray.
Example: ChatGPT, explain Einstein’s theory of relativity to me.
Obtain high quality results
- A well-structured prompt maximizes the model’s capabilities.
Example: ChatGPT, I ask you to simply but rigorously explain the basic concepts of Einstein’s theory of relativity to me. Include only verified essential information, avoiding digressions. Use language understandable also to non-experts.
Save time and effort
- With a good prompt, satisfying results are obtained immediately.
Example: ChatGPT, give me a reasoned list of the 10 most fundamental books on 20th century economics, explaining in 2-3 lines for each the reason for its inclusion in the list.
How to build an effective prompt
Here are some practical tips for creating effective prompts:
Clear context and objective
- Clearly explain the context and objective of the question posed.
Example: ChatGPT, I need to write a blog post explaining the advantages and disadvantages of artificial intelligence. Can you provide me with an outline structured in this way: introduction on what AI is, 5 paragraphs on benefits, 5 paragraphs on drawbacks, summarizing conclusion.
Concrete examples
- Provide one or more practical examples of what is expected.
Example: ChatGPT, I want you to write a captivating advertising slogan to promote a new home robot vacuum cleaner. Here are some effective slogans: “Cleaner than ever, more convenient than you thought”, “Smart cleaning comes to your home”.
Define the scope
- Precisely indicate the scope within which the answer must remain.
Example: ChatGPT, I want a simple definition of no more than 500 characters of what is meant by “machine learning”.
Define constraints and rules
- Establish limits, prohibitions or rules that the model must adhere to.
Example: ChatGPT, write me a four-line rhyme about artificial intelligence suitable for 5-year-old children. Do not use difficult words or overly complex concepts.
Desired tone and style
- Specify the desired tone, style and language register.
Example: ChatGPT, write an enthusiastic and captivating promotional text to present the benefits of a new food delivery app. Use a creative and engaging style.
Mistakes to avoid in prompts
To get the best results, it is good to avoid some common mistakes:
Overly vague or generic prompts
- It is important to be as specific as possible about the task requested.
WRONG Example: ChatGPT, let’s talk about economics.
Lack of context
- The model needs sufficient details to understand the request.
WRONG Example: ChatGPT, tell me about World War II.
Absence of concrete examples
- Examples help the AI understand what is expected.
WRONG Example: ChatGPT, write me a romantic poem.
Unclear objective
- The AI must clearly understand the focus of the question.
WRONG Example: ChatGPT, let’s talk about travel.
Unlimited scope
- Clearly indicate boundaries for the AI to operate within.
WRONG Example: ChatGPT, describe the history of humanity.
Advanced prompt engineering
There are more advanced techniques to make prompts even more effective:
Breaking down into sub-prompts
- Break down the request into simpler sub-questions.
Example: ChatGPT, please answer the following questions separately:
- What is machine learning?
- What are its main fields of application?
- What ethical limitations should be considered?
Explanatory comments
- Insert comments explaining the rationale of the prompt to the AI.
Example: ChatGPT, can you provide a reasoned list of books on the history of artificial intelligence? //With this question I mean to obtain 5-7 relevant titles
Debugging in case of errors
- Correct prompts based on AI errors to improve performance.
Example: ChatGPT, in the previous response you provided incorrect information about Alan Turing’s date of birth. Please re-formulate the answer correcting that specific error.
Meta-prompts
- Use a prompt to explain to the AI how to best build subsequent prompts.
Example: ChatGPT, when I provide you with instructions to answer specific questions, it is important that you carefully follow those instructions and remain focused on the objective indicated in each prompt, without digressing. This will help me obtain high quality answers.
Sequential prompts
- Build a series of interconnected prompts for more complex conversations.
Example: ChatGPT, can you provide a brief biography of Alan Turing? [ChatGPT provides biography] Excellent, now I would like you to write a paragraph of about 5 lines summarizing his importance for computer science and AI.
Funnel prompts
- Start with broad requests then gradually narrow the scope.
Example: ChatGPT, give me an overview of the evolution of computers. Good, now focus only on the 1980s and 1990s. Excellent, can you finally describe in detail the characteristics of personal computers from that time?
Conclusions
In summary, prompt engineering is a core skill for maximizing the potential of conversational AI. Creating effective prompts requires creativity, but by following some of the best practices illustrated in this article, results achieved from AI chatbots can be significantly improved. Experimenting with concrete prompt examples, as shown, is the best way to master this art.
