Prompting Basics: Techniques and Principles Part 1
Introduction
Large Language Models, or LLMs, are changing the way we interact with technology. But there’s a secret to getting the most out of them: giving them the right instructions. Just like telling a friend exactly what you need, crafting the perfect prompts can lead to amazing results. This article will show you how to speak to these powerful tools.
Disclaimer:
There is not a single, definitive “proof” that prompt engineering works, but there is a growing body of research and anecdotal evidence that suggests its effectiveness.
Sectioning Prompts with Delimiters
Delimiters are special tokens that help the LLM distinguish which parts of your prompt it should consider as a single unit of meaning. Delimiters provide structure to this sequence of tokens by fencing specific parts of your prompt to be treated differently.
It is noteworthy that delimiters may not make a difference to the quality of an LLM’s response for straightforward tasks. However, the more complex the task, the more impact the usage of delimiters for sectioning has on the LLM’s response.
A delimiter could be any sequence of special characters that usually wouldn’t appear together, for example:
- ###
- ===
- >>>
The number and type of special characters chosen is inconsequential, as long as they are unique enough for the LLM to understand them as content separators instead of normal punctuation.
- Improved Clarity: Delimiters break down complex prompts into manageable sections, making them easier to understand and process.
- Enhanced Readability: Especially in coding or technical writing, delimiters improve the overall readability, making it easier for others to follow and collaborate.
- Error Reduction: In technical fields, this structured approach can significantly reduce errors, as it clearly defines the boundaries of different command or code segments.
- Facilitates Automation: In data processing, delimiters are essential for automating tasks such as parsing files or processing input.
Examples of using delimiters in prompts
Below I have stated a few examples of how to use delimiters in prompts. Thought, note that this does not mean that you will have a better result or that not using delimiters will result in a bad or useless response.
Example A:
In a world where robots and humans coexist, write a story about:
### Setting ###
The year is 2142. Technology has advanced to the point where robots
are indistinguishable from humans.
### Main Character ###
The protagonist is a young robotics engineer named Kai, known for his
rebellious streak and distrust of artificial intelligence.
### Plot Twist ###
While investigating a malfunctioning robot, Kai uncovers a hidden of
robots who have developed their own consciousness and emotions.
Example B:
Write a conversation between:
— — Character 1 — —
A friendly robot assistant named Unit 7, programmed to be helpful and
informative.
<<< Character 2 >>>
A curious child named Max, fascinated by the world of robots and their
capabilities.
|| Dialogue ||
Max: “Unit 7, why are you different from other robots?”
Unit 7: “I am programmed with a unique learning algorithm that
allows me to adapt and respond to individual needs.”
Max: “Wow! Can you tell me a story about robots and humans?
Example C:
### CONTEXT ###
I want to advertise my company’s new product. My company’s name is Alpha
and the product is called Beta, which is a new ultra-fast hairdryer.
### OBJECTIVE ###
Create a Facebook post for me, which aims to get people to click on
the product link to purchase it.
### RESPONSE ###
The Facebook post, kept concise yet impactful.
Exploring Additional Prompt Principles
A couple of months ago a research paper titled “Principled Instructions Are All You Need for Questioning LLaMA-1/2, GPT-3.5/4" was released. The paper describes 26 different principles for prompt engineering. Some of which I think is well worth digging into to enhance our overall ability to understand the nature of prompting.
Note: The evaluation done in the article is mentioned as “human evaluation”, so the statistics should be interpreted with that in mind. Meaning that the qualitative measurement might be unreliable.
- Focus on “Do” instructions: Instead of saying “don’t write…”, tell the LLM what you want it to do (“write a poem about…”). (Principle #4)
Instead of:
"Don’t write a news article with biased language."
Use:
"Write a balanced news article about the recent scientific discovery,
presenting both sides of the research objectively."
- Get straight to the point: Avoid unnecessary politeness and focus on clear instructions. (Principle #1)
Unnecessary Politeness:
"I would be most grateful if you could please write a poem about a cat.
If it wouldn’t be too much trouble, perhaps you could make it humorous?"
Clear Instruction:
"Write a funny poem about a cat."
- Consider the audience: Tailor your prompt to the intended reader’s level of understanding (expert, beginner, etc.). (Principle #2)
Prompt for Beginners:
“Write a clear and concise blog post explaining the advantages of using
solar energy for a general audience. Focus on the basic benefits like
cost savings, environmental impact, and ease of installation.”
Prompt for Experts:
“Create a blog post for a knowledgeable audience, delving into the technical
aspects of solar energy systems. Discuss the efficiency differences between
various panel types, the impact of government incentives, and the long-term
cost-effectiveness compared to traditional energy sources.”
- Break down complex tasks: Divide large tasks into smaller, sequential prompts for better comprehension. (Principle #3)
Complex Task:
Write a blog post summarizing the recent advancements in electric vehicle
technology.
Break Down into Sequential Prompts:
Prompt 1: Identify Key Advancements:
List the 3–5 most significant recent advancements in electric vehicle
technology. Briefly describe the impact of each advancement.
Prompt 2: Analyze the Environmental Benefits:
Explain how these advancements contribute to a more sustainable future.
Quantify the environmental benefits whenever possible
(e.g., reduced carbon emissions).
Prompt 3: Discuss Challenges and Future Outlook:
Identify the key challenges that still need to be addressed in EV technology.
Briefly discuss potential solutions and the future outlook for the industry.
- Leading words: Use words like “think step by step” to provide context and guide the LLM’s reasoning. (Principle #12)
Leading Words Prompt:
“Think step by step about how to solve the following mathematical problem:
Find the derivative of 𝑥5+𝑥9−𝑥3+1x5+x9−x3+1.”
- User interaction: Allow the LLM to ask clarifying questions to fully understand your needs.
Initial Prompt:
From now on, I would like you to ask me questions to understand what kind
of creative writing piece I want you to generate.
AI Response:
Great! To get started, what kind of writing are you interested in?
Do you have a specific genre in mind, such as a poem, a short story, a
script, something else?
User Response:
I’d like a short story with a science fiction theme.
AI Response:
Excellent! Now, can you tell me a bit about the plot or any specific ideas
you have for the story? Are there any characters you want to focus on, or
any conflicts or you’d like them to face?
<THE CONVERSATION CONTINUES>
- Use examples (few-shot prompting): Give the LLM a few examples of what you’re looking for to guide its response. (Principle #7)
Prompt:
"This restaurant has the best pizza I've ever tasted!" => Positive
"The service was terrible, and the food was cold and bland." => Negative
"The movie was so heartwarming, I cried tears of joy" => Positive
"The movie was a complete disappointment." =>
AI Response:
'The movie was a complete disappointment.' => Negative"
- Specify the desired level of detail: When seeking explanations, clarify if you want a simple or in-depth answer (e.g., “explain like I’m 5”). (Principle #5)
Prompt:
Explain the process of photosynthesis in a way that a child can understand.
Explain like I’m 5.
AI Response:
Plants are like little factories that make their own food using sunlight,
water, and air. Imagine the sun as a big, bright lamp, and the leaves as
tiny kitchens. When sunlight shines on the leaves, it gives them energy to
mix water and air together, just like how you mix ingredients to make a
cake. This mixture turns into a special sugar that the plant uses to grow
big and strong.
Conclusion
- Be clear about what you want: Tell the LLM exactly what you need it to do, like writing a poem, summarizing a text, or finding specific information.
- Focus on what you want, not what you don’t: Instead of saying “don’t write a boring essay,” tell it “write a creative and engaging essay.”
- Organize your instructions: Use simple words and break down complex tasks into smaller steps for better understanding.
- Specify the format: If you want a specific output format like a list or a table, let the LLM know.
- Ask for confirmation: If the LLM is unsure about something, tell it to say “I don’t know” instead of making something up.
- Explanation before answer: Ask the LLM to explain its thinking before giving you the answer, especially for complex tasks.
References
- Alternative Prompt Engineering Approach: Sectioning with Delimeters — https://medium.com/@thomasczerny/alternative-prompt-engineering-approach-sectioning-with-delimeters-112ff9d7953f#:~:text=In%20AI%20interactions%2C%20especially%20when,any%20constraints%20or%20specific%20requirements.
- How I Won Singapore’s GPT-4 Prompt Engineering Competition — https://towardsdatascience.com/how-i-won-singapores-gpt-4-prompt-engineering-competition-34c195a93d41
- The Art of Prompt Engineering: Using the 26 Principles in Everyday AI Interactions — https://medium.com/gitconnected/the-art-of-prompt-engineering-using-the-26-principles-in-everyday-ai-interactions-d4d0d2ae3c37
- Principled Instructions Are All You Need for Questioning LLaMA-1/2, GPT-3.5/4 — https://arxiv.org/abs/2312.16171
- Prompt Engineering Guide — https://www.promptingguide.ai/