Two Rules That Fix Most Bad Prompts
DeepLearning.AI and OpenAI put out a free one-hour course on prompt engineering, taught by Andrew Ng and Isa Fulford. It uses GPT-3.5 Turbo, comes with Jupyter notebooks you can run, and splits into two halves: writing good prompts, and calling the LLM from your own app. The part worth your time is the first section, the guidelines. Everything else is an application of two principles.
Principle one: write clear and specific instructions. It comes with four tactics. Use delimiters to separate the text you are asking about from your instructions. Ask for structured output, HTML or JSON, instead of free-form prose, so you can use the answer in code. Check whether the conditions a task needs are satisfied, so the model cannot make up an answer when the input is missing something. Few-shot prompting: give an example of a correct answer and the model will match its shape. Say exactly what you want, in a format you can check.
Principle two is to give the model time to think. Specify the steps instead of asking for the answer in one leap, and tell it to work out its own solution before rushing to a conclusion. For maths this matters a lot. Asked to solve a problem in one go, the model often gets it wrong. Break it into steps and it usually gets it right. It is a next-word predictor, and a long chain of reasoning needs room to unfold.
Then comes iteration, and the course is blunt. You will almost never write the ideal prompt on your first try. The loop is simple: write a prompt, read the response, find what is wrong, change the prompt, repeat. There is no universal perfect prompt, because every application is different. What matters is having a system for getting there, not a memorized prompt you paste everywhere.
The rest covers what the model is good at. Summarizing: feed it long product reviews and get one or two sentences back. Inferring: ask for the sentiment of a review, so you can flag angry customers for a human. Transforming: translate, proofread, or change an email's tone from informal to formal. Expanding: generate something new, a poem, a draft, a first version. The reviewer makes a sharp point here. If one person expands a short note into a long email and the other end summarizes it back down, everyone did extra work for nothing. Sometimes the original text was fine.
The most useful nugget in the course is temperature. It controls how creative or precise the model is. At zero, asked "my favourite food is", the model answers pizza, about 53% of the time. Turn it up and it starts saying sushi, about 30% of people, and at 0.7 it gets more creative, tacos and less common answers. Bing's chat modes map to this: precise around zero, balanced around 0.3, creative around 0.7 and up. Precise is boring but right for facts. Creative is fun but wrong for anything you need to rely on.
Most common answers to 'my favourite food is'Data from the sources listed below.
The last section is for developers building a chatbot with the API. The key idea is three roles. The user is the customer, the assistant is the model, and the system is the instruction you bake into your app, like "act politely", which the web interface hides from you. The example is a pizza ordering bot. The system prompt is where you set the behaviour, not each user message.
The course is free and an hour long. Take the two principles: be specific, and give the model room to think. Most bad prompts fail one of those two.
Try this
bashpip install openai python -c "import openai; print(openai.__version__)"
Sources
Source: ChatGPT PROMPT Engineering Course Review - DeepLearningAI & OpenAI / Andrew Ng and Isa Fulford - AI Matej
