26 Prompt Engineering Principles
I wanted to start off this Substack with some extremely practical tips. There are enough articles on theories about artificial intelligence and prompt engineering; this isn’t the place for that. This is a place where we share research backed techniques and strategies to help you get better outputs from LLMs. That’s what we’ve done on our blog at PromptHub, and what we will be doing here.
I couldn’t think of a better way to start off this Substack other than going over some of the best prompt engineering principles we’ve picked up along the way through 2023.
We’ll be pulling some information from a recent research paper Principled Instructions Are All You Need for Questioning LLaMA-1/2, GPT-3.5/4.
Prompt principle categories
The principles are broken down into 5 categories. I’ve added a few use cases for each category so you can self-asses where you might want to focus.
Complex Tasks and Coding Prompts: Code generation & auditing, reasoning tasks
Specificity and Information: Content creation, creative writing
Content and Language Style: Creative writing, matching specific tones
Prompt Structure and Clarity: General formatting tips
User Interaction and Engagement: Chatbots
Principles and their performance
We took the 26 principles and added performance metrics inline so you could quickly visualize which principles pack the most punch. The metrics come directly from the results of the experiments from the research paper.
The table below correlates to GPT-4 specifically. You can get the full metrics for both GPT-4 and GPT-3.5 from this GoogleSheet we created.
Three principles we love
While there are 26 principles, there are three that stood out. These are principles that we find ourselves often repeating the most when helping teams with their prompt engineering.
Principle 1
No need to be polite with LLM so there is no need to add phrases like “please”, “if you don’t mind”, “thank you”, “I would like to”, etc., and get straight to the point.
This is something I’ve wondered for awhile, but I’ve never tested extensively. This is the type of question I get from my parents or uncle over the holidays. I am both surprised and not surprised.
I’m surprised because you would assume since LLMs are trained on human data, things like pleasantries and other nuances of our language would impact prompts and prompt outputs.
On the other side of things, I often will see teams over engineer prompts, that end up confusing the model. So the “get straight to the point” part of this principle makes a lot of sense to me.
Principle 6
Add "I'm going to tip $xxx for a better solution!"
This tactic has gained some popularity over the last few months. Isn’t it interesting how these LLMs hold up a mirror to ourselves?
Principle 7
Implement example-driven prompting (Use few-shot prompting).
Few-shot prompting is one of the best ways we’ve found to get better responses from LLMs. When helping teams with their prompts, the first question I like to ask is if they are sending any examples via few-shot prompting.
For context, few-shot prompting is when you include some examples in your prompt to help the model learn about the task.
For example, let’s say we wanted to write a prompt that analyzed the sentiment of certain movie reviews.
A normal prompt would be:
“Categorize this movie review as negative, positive, or neutral:
The movie was not good //”
A few-shot version of this prompt would be
“Categorize this movie review as negative, positive, or neutral:
The movie was bad // negative
The movie rocked! // positive
The movie was not good // ”
In this case we send a few examples before setting the model up to categorize that last review.
Principle 8
When formatting your prompt, start with ‘###Instruction###’, followed by either ‘###Example###’ or ‘###Question###’. Use one or more line breaks to separate instructions, examples, questions, context, and input data.
Using delimiters, like triple backquotes, helps the model understand the different sections of your prompts.
If you want to see a few examples of prompts with good structure, you can check out system messages prompts from top AI companies like OpenAI, Vercel, and Perplexity in one of our recent blog posts: What We Can Learn from OpenAI, Perplexity, TLDraw, and Vercel's System Prompts
Wrapping up
Not every one of these principles is guaranteed to boost the performance of your prompts, but they provide a good source of inspiration. If you’re hitting a wall with your current prompt, you’ve now got 26 ideas to test.