Skip to content

Day 2: How to Write Better Prompts for ChatGPT?

I write a newsletter called Above Average where I talk about the second order insights behind everything that is happening the big tech. If you are into tech and want to be above average, subscribe to it.

I don’t know if prompt engineer will actually become a role in companies in the future. But writing better prompts will become more and more important if you want to be more productive. So to learn how to write better prompts to get desired output I did a short course on called ChatGPT Prompt Engineering for Developers. Here are some take aways that will help you become a better prompter.

  1. Getting to the right Prompt with desired output is an Iterative Process: You will not get the right prompt on the first try. You need to start with a basic prompt, and refine it using the best principles (which I will talk about below). If you are developer creating an application you might want to test multiple similar prompts with large sets of data to evaluate the right prompt for you application.
  2. Principle 1 – Write clear and specific instructions: Clear doesn’t mean short. It means using delimiters (quotes, backticks, dashes etc.,) to highlight the text the prompt should work on. It means asking for a structured output. Explicitly asking the LLM to check whether conditions you have instructed are satisfied. Or sometime giving explicit examples of successfully completing a task. In the example below you can see how we used delimiters
from openai import OpenAI
client = OpenAI()
client.api_key = 'YOUR_SECRET_KEY'

text_1 = f"""
Making a cup of tea is easy! First, you need to get some  
water boiling. While that's happening, 
grab a cup and put a tea bag in it. Once the water is
hot enough, just pour it over the tea bag.
Let it sit for a bit so the tea can steep. After a
few minutes, take out the tea bag. If you
like, you can add some sugar or milk to taste.
And that's it! You've got yourself a delicious
cup of tea to enjoy.

prompt = f"""
You will be provided with text delimited by triple quotes. 
If it contains a sequence of instructions, \ 
re-write those instructions in the following format:

Step 1 - ...
Step 2 - …
Step N - …

If the text does not contain a sequence of instructions, \ 
then simply write \"No steps provided.\"



response =
      "role": "user",
      "content": prompt


Principle 2 – Give the model time to think: Instead of directly asking the model to do the final goal you want to achieve, break down the goal into multiple tasks. Also instruct the model to give the out put in the format you require explicitly. Models tend to hallucinate and take the solution from the text you give instead of calculating independently, so explicitly tell the model to work its own solution.

That’s if for day 2 of AI.

Follow me on twitter for latest updates on 100 days of AI or bookmark this page.