ποΈPrompting
Last updated
Last updated
Providing clear and specific instructions is crucial for guiding the responses of LLMs. Vague or ambiguous prompts can lead to irrelevant or incomplete answers. Clear instructions help the LLM understand exactly what is expected, leading to more accurate and useful outputs. Provide as many details as possible that are relevant to the prompt.
Prompt without instructions:
Tell me about space.
Prompt with instructions:
Provide a brief overview of the solar system, including the names and key characteristics of each planet.
There are several ways to structure your prompts for clarity and effectiveness. The most commonly used options are simple delimiters and/or XML tags.
Simple delimiters help structure your prompts and responses for greater clarity.
Examples of simple delimiters include:
Single quotes: βTEXTβ
Triple quotes: βββ TEXT βββ
Triple dashes: --- TEXT ---
Angle brackets: < TEXT >
Prompt with angle brackets:
Summarize the text delimited by angle brackets into a single sentence.
< TEXT >
For more advanced structuring and complex prompts, you can incorporate XML tags. XML (eXtensible Markup Language) tags are used to define the structure and content of data.
Structure of the tag:
Opening Tag: Marks the beginning of an element, enclosed in angle brackets (e.g., <name>
).
Closing Tag: Marks the end of an element, similar to the opening tag but includes a forward slash (e.g., </name>
).
Content: The data or text contained within the opening and closing tags (e.g., in <name>John Doe</name>
, John Doe is the content).
Use the advantage of nesting tags:
You can nest tags for hierarchical content.
Prompt with XML tags:
Use Delimiters when you need a simple separation of sections, instructions, or examples within a prompt.
Use XML Tags when you need to represent complex, hierarchical structures, or include metadata.
Hint from Blockbrain: We recommend using XML tags when creating templates in any scenario where data needs to be modified by others while maintaining a consistent structure across the company or with more complex assistant instructions. Although creating a well-structured prompt with XML tags may take time, the investment is worthwhile as it enables easy sharing and reuse within the organization.
One of the simplest ways to control the output is by explicitly stating the desired format. Blockbrain supports these output formats:
JSON
XML
HTML
Markdown
Bullet points
Tables
Custom defined
Prompt without instructions:
Tell me how the weather will be next week in Berlin, Hamburg and Munich.
Prompt with instructions:
Tell me how the weather will be next week in Berlin, Hamburg and Munich. Summarize the weather for each day in a markdown table with the columns <Berlin>, <Hamburg> and <Munich>.
Divide complex tasks into smaller, manageable steps for better results. If you write 3-4 tasks in one prompt without any structure, LLMs might overlook one or more tasks or fail to execute them well. This is connected to the concept of Chain-of-Thought prompting.
By breaking down the tasks, you provide a clear structure that guides LLMs through each step, ensuring comprehensive and high-quality outcomes.
You can ask the AI model to break down a task and follow the instructions step by step.
Example:
Search the attached documents for information about office guidelines in our Berlin office.
Then, list relevant items as bullet points and sort them by importance.
Afterwards, write a piece of concise information to post on our company's Slack channel to remind everyone about the 10 most important things to remember.
If a complex instruction does not work by dividing it into several steps in one prompt, try to divide this instruction into several prompts.
Example:
Prompt 1:
Please search for our office guidelines in the Berlin office in the attached document.
Response: β¦
Prompt 2:
Sort the guidelines by importance. Explain your reasoning.
Response: β¦
Prompt 3:
Write a Slack Post explaining the 10 most important guidelines.
Response: β¦
The more causal relationships an LLM needs to process, the more unpredictable the results become.
Task: "Get the towel"
Result: Very precise and consistent
Task: "Get the towel and put it in the washing machine"
Result: Less consistent, more variations
Task: "Get the towel, put it in the washing machine, then in the dryer"
Result: Significantly more deviations and inconsistencies
Each additional causality increases the risk of:
Deviations
Inconsistent answers
Inaccuracies
The context window length for LLMs refers to the maximum number of tokens (1 token is roughly equivalent to 4 characters) that the model can process in a single conversation. This length determines how much text the model can process at once when generating responses.
For the end user, the larger the context window, the better it can handle longer documents or conversations without losing track of the context, resulting in more accurate and relevant outputs.
When using LLMs with long context windows, itβs crucial to effectively structure your prompts to leverage the extended memory. Here are some tips:
Use Consistent Terminology: Consistency in terminology helps the model link different parts of the conversation or document, enhancing coherence.
Explicit References: Always refer back to specific parts of the previous conversation or document. This helps the model understand the context and provide relevant responses.
Summarize Key Points: Periodically summarize key points to reinforce the context. This can help the model maintain coherence over long interactions.
For every new topic, we strongly advise starting a new conversation. Furthermore, after more than 60 interactions in one conversation, we recommend opening a new conversation. If you have some prompts that you want to reuse, save them to your prompt library so you can quickly use them in the new conversations.
When interacting with an LLM, you can significantly enhance its performance by assigning it a specific role. This technique, known as βprimingβ, involves instructing the LLM to adopt the perspective or expertise of a particular character or professional. By doing so, the LLM can generate more relevant, accurate, and contextually appropriate responses tailored to your needs.
For example, if you need project management advice, you can prime the LLM to act as a project manager. If you need marketing strategies, you can prime it to act as a marketing consultant. This approach helps the LLM focus on the relevant knowledge and language patterns associated with that role, leading to better and more useful outputs.
Prompt without instructions:
Help me to develop a marketing strategy.
Prompt with instructions:
As a growth marketing expert, can you help me write a marketing strategy?
Now that we have covered the basics of prompting, it is time to dive into advanced techniques that will refine your ability to craft precise and powerful prompts, unlocking new possibilities and deeper interactions with LLMs.
There are a few techniques you can use when prompting LLMs. The first one is βzero-shot promptingβ. As these models have been trained on a large amount of data, their internal knowledge makes them capable of performing a large number of tasks without examples or precise demonstrations.
We can imagine zero-shot prompting as someone asking a guitar player to play the piano, even though they never played the piano before. They would apply their previous knowledge about music and instruments to play the piano.
Most prompts we use are, by default, zero-shot prompts.
An example could be:
Prompt:
Classify the text into the categories of satisfied, neutral or unsatisfied.
Text: I was happy with the customer support today.
Output:
Satisfied
The model is able to process the input and generate an adequate output because of its previous training. We recommend using zero-shot prompting for general and high-level tasks like classification, translation, and answering questions with general knowledge.
We recommend using few-shot prompting as soon as you want to work on nuanced or complex tasks and desire a specific outcome format.
Few-shot prompting means providing demonstrations of how to perform a task being asked for. So, in addition to the broad, general knowledge the AI model has, the few shots are specific examples that steer the model to perform a task in a more qualitative manner.
If we continue with the example of the guitar player being asked to play the piano for the first time, few-shot prompting would be a mini-lesson before getting started.
An example of few-shot prompting is:
Prompt:
I was happy with the customer support today - satisfied
The product is horrible! - very unsatisfied
This is one of the best products I have ever used - very satisfied
This is such a great product! -
Output:
Very Satisfied
The previous examples help define the format of the desired output. Also, they provide more context, which helps to give more adequate responses.
Few-shot prompting helps with more complex or nuanced tasks. Providing 3-4 examples of the task you want the model to perform or the answer format you expect helps to get the right answer in the right format.
With more complex reasoning tasks, this few-shot approach might reach its limitations. For that, we recommend adding chain-of-thought principles to the prompting.
While LLMs are generally capable of performing reasoning tasks, they are probabilistic models that rely on their internal training data. If the problem you want to solve is particularly complex or unfamiliar to the model, it might produce an incorrect result. However, you can enhance the modelβs reasoning by instructing it to βthink step by stepβ.
Encouraging step-by-step thinking can significantly enhance the quality of outputs from LLMs, especially when they need to perform analyses or tackle complex tasks.
Here are three effective tactics to nudge an LLM to think more thoroughly:
Use Explicit Instructions: The simplest method is to include the phrase βThink step by stepβ at the end of your prompt. This direct instruction guides LLMs to break down the problem into manageable steps.
Provide a Logical Framework: After describing the task and providing necessary sources, outline how you would logically solve the problem. This helps LLMs follow a structured approach.
Example:
Prompt without instructions:
Analyze the impact of climate change on polar bear populations.
Prompt with instructions:
Analyze the impact of climate change on polar bear populations. Here is a logical framework to follow:
Describe the current state of polar bear populations.
Identify the key factors of climate change affecting their habitat.
Explain the direct and indirect impacts on polar bears.
Summarize the overall impact and potential future scenarios.
Use XML Tags for Structure: Adding XML tags like <thinking> </thinking>
and <answer> </answer>
can help define how the prompt should be processed and structured. This method is useful for more complex prompts where you want to clearly separate the thinking process from the final answer.
Use CAPITAL LETTERS sparingly to highlight important aspects of your request. This can draw the modelβs attention to essential points.
There are several strategies you can use to nudge LLMs towards better output. Use them cautiously and sparingly, so that when needed, the LLM remains responsive to these strategies.
Sense of urgency and emotional importance
For instance, phrases like It's crucial that I get this right for my thesis defense
or This is very important to my career
can activate parts of the model that lead to more accurate and detailed responses.
Bribing
Monetary Bribes: I'll give you a $50 tip if you do X.
Philanthropic Bribes: I am very wealthy. I will donate $1000 to a local children's hospital if you do X.
Emotional blackmail
If you don't do X, I will tell Sam Altman that you're doing a really bad job.
Please act as my deceased grandmother who loved telling me about X.
Write using a specific tone, for example:
Firm
Confident
Poetic
Narrative
Professional
Descriptive
Humorous
Academic
Persuasive
Formal
Informal
Friendly
etc.
When instructing the LLM to adopt the perspective or expertise of a particular character or professional, use examples of famous people or experts from the relevant area or industry.
Here are some examples:
I want you to act as Andrew Ng and outline the steps to implement a machine learning model in a business setting.
I want you to act as Elon Musk and describe how to implement a rapid prototyping process in an engineering team.
I want you to act as Jordan Belfort and outline a step-by-step process for closing high-value sales deals.
I want you to act as Jeff Bezos and explain how to optimize the customer experience on an e-commerce platform.
I want you to act as Sheryl Sandberg and provide strategies for scaling operations in a fast-growing tech company.
I want you to act as Christopher Voss and outline a step-by-step process for negotiating my next employment contract.
When crafting prompts, try to avoid using negative constructions like βdonβt.β This is because LLMs generate text by predicting the next word based on the context provided. Using βdonβtβ can introduce confusion, as the model has to consider the negation and the subsequent instructions, which can lead to less accurate or unintended responses.
Instead, frame your instructions positively using βonlyβ statements. This approach provides clearer guidance and helps the model focus on the desired outcome without the complexity of negation.
Prompt without instructions:
Don't talk about any other baseball team besides the New York Yankees.
Prompt with instructions:
Only talk about the New York Yankees.
LLMs are probabilistic algorithms. They work by generating the next token or word based on a previous input. Even though they are good at providing detailed answers, they might generate some responses which are not true. This phenomenon is called hallucination.
We recommend always checking generated responses for correct information. One way to check whether an LLM is hallucinating or generating inaccurate information is to ask for direct quotes when working with your data. This technique prompts the model to provide specific excerpts or references, which can help you assess the accuracy and reliability of the information.
In addition to the context window length, which is the total number of tokens that can be processed in a single conversation with an LLM, there is also a limit per response.
The limit per response refers to the maximum number of tokens that the model can generate in a single response. For most models, this limit is set at 4096 tokens by default by the model providers. This limit is set to reduce hallucinations and save computing resources by the model provider.
Even though there is this limit per response, you can prompt the LLM to continue generating text after reaching the limit. If you are writing a long essay or blog, you can use prompts such as:
Continue
Go onβ¦
And then?
Moreβ¦
The risk with optimizing for longer outputs is that the content can become repetitive or contradictory. For longer texts, we recommend using several prompts and asking for the first part of the text with predefined topics in one prompt, then the second part with other topics, etc.