Prompt Engineering 101
Prompt Basics for Generative AI
Based on best practices from Open.AI, my own testing, and review of AI prompting research, here are some basics about prompt engineering:
- Be clear and concise
- Be moderately polite (use please and thank you) but not excessively servile (as of 02/2024)
- Say what to do, instead of what not to do
- Put instructions at the beginning of the prompt and use ### to separate the instruction and context
- Be specific, descriptive, and detailed about the desired context, outcome, length, format, style, etc
- Add examples of expected output
- If asking for help with code, give it some code to start with
- Ask it to try again
- Ask it to give you 5 more options
- If it’s not going well, start a fresh chat with a new prompt updated based on what you learned from the first go around
- If your prompt is related to math, consider prompting as if you are on a Star Trek mission (as of 02/2024)
“Genius in a Room” Mental Model
Open.AI Jessica Shieh’s “genius in a room” mental model is a great place to start:
Imagine you live next door to a genius (or at least a very smart friend who reads a ton, up until 2021) and the only way you can communicate with him/her is to slide a piece of paper under the door and ask for a reply.
This genius in the room does not have any context on you nor the problems you trying to solve.
He/She can’t see your face, doesn’t know where you are, cannot read your emotions, doesn’t have the unique knowledge you have and has no idea what you are trying to do.
The genius only accepts questions when they are written on a piece of paper and slipped underneath the door.
Given that, how would you write your prompts differently?
With this “genius in the room” mental model, you now know – context is key.
Providing the right context can have a huge impact on the quality of the output as you perceived it.
Some best practices:
- Explain the problem you want the model to solve
- Articulate the output you want – in what format (” answer in a bulleted list”), in what tone/style (“answer the question as a patient math teacher…”)
- Provide the unique knowledge needed for the task”
Mega-Prompt
Another model is the “mega prompt” which consists of three parts:
- a specific role or scenario
- examples for the AI to follow
- the parameters for how you want to receive the AI output
Prompt Libraries
Here are some prompt libraries to help you get started:
- Anthropic’s Prompt Library
- Prompt Library by Ethan Mollick and Lilach Mollick (More Useful Things)