Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

Prompt Engineering Principles

Save for later
  • 5 min read
  • 04 Jun 2023

article-image

Prompt Engineering and design play a very vital role in controlling the output of the model. Here are some best practices you can use to improve your prompts, as well as some practices you should avoid:

  • Clarity: Use simple sentences and instructions that can easily be understood by ChatGPT. 
  • Conciseness: Favor short prompts and short sentences. This can be achieved by chunking your instructions into smaller sentences with clear intentions.
  • Focus: Keep the focus of the prompt on a well-defined topic so that you don’t risk your output being too generic.
  • Consistency: Maintain a consistent tone and language during the conversation so that you can ensure a coherent conversation.
  • “Acting as…”: The hack of letting ChatGPT act as someone or something has proven to be extremely powerful. You can shorten the context you have to provide to the model by simply asking him to act like the person or system you want information from. We’ve already seen the interview-candidate example, where ChatGPT acted as an interviewer for a data scientist position. A very interesting prompt is that of asking ChatGPT to act as a console. Here is an example of it:

 

prompt-engineering-principles-img-0

Figure 1 – Example of ChatGPT acting as a Python console

 

Note that the console, as it would be if it were real, is also reporting the error I made for the cycle, indicating that I was missing the brackets.

There is a continuously growing list of Act as prompts you can try in the following GitHub repository: https://github.com/f/awesome-chatgpt-prompts.

Considering the few-shot learning capabilities, there are some good tips for leveraging this feature in prompt designing. An ideal conversation is as follows:

 

On the other hand, there are some things you should avoid while designing your prompt:

  • Start with a concise, clear, and focused prompt. This will help you have an overview of the topic you want to discuss, as well as provide food for thought and potential expansion of particular elements. Here’s an example

prompt-engineering-principles-img-1
Figure 2 – Example of a clear and focused prompt to initiate a conversation with ChatGPT

  • Once you have identified the relevant elements in the discussion, you can ask ChatGPT to elaborate on them with much more focus

prompt-engineering-principles-img-2
Figure 3 – Example of a deep-dive follow-up question in a ChatGPT

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at $19.99/month. Cancel anytime

 

  • Sometimes, it might be useful to remember the model and the context in which you are inquiring, especially if the question might apply to various domains

prompt-engineering-principles-img-3
Figure 4 – Example of a reminder about the context in a conversation with ChatGPT

  • Finally, always in mind the limitations we mentioned in previous chapters. ChatGPT may provide partial or incorrect information, so it is always a good practice to double-check. One nice tip you could try is asking the model to provide documentation about its responses so that you can easily find proof of them

prompt-engineering-principles-img-4
Figure 5 – Example of ChatGPT providing documentation supporting its previous responses

 

On the other hand, there are some things you should avoid while designing your prompt:

 

  • Information overload: Avoid providing too much information to ChatGPT, since it could reduce the accuracy of the response.
  • Open-ended questions: Avoid asking ChatGPT vague, open-ended questions. Prompts such as What can you tell me about the world? or Can you help me with my exam? are far too generic and will result in ChatGPT generating vague, useless, and sometimes hallucinated responses.
  • Lack of constraints: If you are expecting an output with a specific structure, don’t forget to specify that to ChatGPT! If you think about the earlier example of ChatGPT acting as an interviewer, you can see how strict I was in specifying not to generate questions all at once. It took several tries before getting to the result since ChatGPT is thought to generate a continuous flow of text.
  • Furthermore, as a general consideration, we still must remember that the knowledge base of ChatGPT is limited to 2021, so we should avoid asking questions about facts that occurred after that date. You can still provide context; however, all the responses will be biased toward the knowledge base before 2021.

 

Summary

In this article, we get to learn some strong principles that can help you learn how to prompt effectively.  We cover the importance of a good prompt, and all the important Do’s and Don'ts while designing a good prompt with a practical example.

 

About the Author 

Valentina Alto graduated in 2021 in Data Science. Since 2020 she has been working in Microsoft as Azure Solution Specialist and, since 2022, she focused on Data&AI workloads within the Manufacturing and Pharmaceutical industry. She has been working on customers’ projects closely with system integrators to deploy cloud architecture with a focus on datalake house and DWH, data integration and engineering, IoT and real-time analytics, Azure Machine Learning, Azure cognitive services (including Azure OpenAI Service), and PowerBI for dashboarding. She holds a BSc in Finance and an MSc degree in Data Science from Bocconi University, Milan, Italy. Since her academic journey, she has been writing Tech articles about Statistics, Machine Learning, Deep Learning, and AI in various publications. She has also written a book about the fundamentals of Machine Learning with Python.