Dan Kuyper

Dan Kuyper

People Builder | Product Creator | Technology Leader | Team Catalyst

Guidelines for AI Prompt Engineering – Giving the Model Time to Think

LinkedIn
Twitter
Facebook
Email
Print

Given an overview of prompt engineering, the next step is to dive deeper into the principles and tactics of prompt engineering.

The two fundamental principles for AI prompt engineering are:

  1. Writing clear and specific instructions
  2. Giving time for the model to think

Giving the Model Time to Think

If you give a model a task that’s too complex to do in a short amount of time or a small number of words, it may make up a guess, which is likely incorrect.

This principle would happen to a person too. If you gave someone a complex problem and didn’t provide them time to work on it, they would likely make a guess or mistake.

So, in these situations, you can instruct the model to think longer about the problem, which means it’s spending more computational effort on the task.

There are some tactics to employ to give the model time to think.

Tactic 1: Specify the Steps to Complete a Task

For example, we could run the following command, which will parse the text in a series of steps and return it in JSON format:

				
					prompt_2 = f"""
Your task is to perform the following actions: 
1 - Summarize the following text delimited by 
  <> with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains the 
  following keys: french_summary, num_names.

Use the following format:
Text: <text to summarize>
Summary: <summary>
Translation: <summary translation>
Names: <list of names in Italian summary>
Output JSON: <json with summary and num_names>

Text: <{text}>
"""
response = get_completion(prompt_2)
print("\nCompletion for prompt 2:")
print(response)
				
			

The results:

				
					Completion for prompt 2:
Summary: George Washington was the first president of the United States and played a crucial role in the nation's founding, leading the Continental Army to victory in the Revolutionary War and helping to create and ratify the Constitution of the United States.

Translation: George Washington a été le premier président des États-Unis et a joué un rôle crucial dans la fondation de la nation, menant l'armée continentale à la victoire lors de la guerre révolutionnaire et aidant à créer et ratifier la Constitution des États-Unis.

Names: George Washington

Output JSON: {"french_summary": "George Washington a été le premier président des États-Unis et a joué un rôle crucial dans la fondation de la nation, menant l'armée continentale à la victoire lors de la guerre révolutionnaire et aidant à créer et ratifier la Constitution des États-Unis.", "num_names": 1}
				
			

Tactic 2: Instruct the model to work out its own solution before rushing to a conclusion

In this prompt, the model is supposed to validate the student’s solution, which is incorrect. So, we can first have the model work out its own solution and then compare it to the student’s solution.

				
					prompt = f"""
Your task is to determine if the student's solution \
is correct or not.
To solve the problem do the following:
- First, work out your own solution to the problem. 
- Then compare your solution to the student's solution \ 
and evaluate if the student's solution is correct or not. 
Don't decide if the student's solution is correct until 
you have done the problem yourself.

Use the following format:
Question:
```
question here
```
Student's solution:
```
student's solution here
```
Actual solution:
```
steps to work out the solution and your solution here
```
Is the student's solution the same as actual solution \
just calculated:
```
yes or no
```
Student grade:
```
correct or incorrect
```

Question:
```
I'm building a solar power installation and I need help \
working out the financials. 
- Land costs $100 / square foot
- I can buy solar panels for $250 / square foot
- I negotiated a contract for maintenance that will cost \
me a flat $100k per year, and an additional $10 / square \
foot
What is the total cost for the first year of operations \
as a function of the number of square feet.
``` 
Student's solution:
```
Let x be the size of the installation in square feet.
Costs:
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 100x
Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
```
Actual solution:
"""
response = get_completion(prompt)
print(response)
				
			

By giving the model time to come up with it’s own solution, we validate the student’s solution is incorrrect.

				
					To calculate the total cost for the first year of operations, we need to add up the costs of land, solar panels, and maintenance.

Let x be the size of the installation in square feet.

1. Land cost: $100 / square foot
The cost of land is 100 * x = 100x.

2. Solar panel cost: $250 / square foot
The cost of solar panels is 250 * x = 250x.

3. Maintenance cost: $100,000 + $10 / square foot
The maintenance cost is a flat $100,000 per year, plus $10 per square foot. So the maintenance cost is 100,000 + 10 * x = 100,000 + 10x.

Total cost: 100x + 250x + 100,000 + 10x = 360x + 100,000.

Is the student's solution the same as the actual solution just calculated:
No

Student grade:
Incorrect
				
			

Model Limitations – Hallucinations

Even though models have been exposed to a vast amount of knowledge during their training process, it has not perfectly memorized the information it’s seen, so it doesn’t know the boundary of it’s knowledge very well.

This limitation means that it may “hallucinate” when answering. That is, it may make up statements that sound plausible but are not true. By the way, people do this too.

For example, the model could make up something about a fabricated product, drawing from a real product with this prompt.

				
					prompt = f"""
Tell me about AeroGlide UltraSlim Smart Toothbrush by Boie
"""
response = get_completion(prompt)
print(response)
				
			

Which would return information on a fabricated product:

				
					The AeroGlide UltraSlim Smart Toothbrush by Boie is a technologically advanced toothbrush designed to provide a superior brushing experience. Boie is a company known for its innovative oral care products, and the AeroGlide UltraSlim Smart Toothbrush is no exception.

One of the standout features of this toothbrush is its ultra-slim design. The brush head is only 2mm thick, making it much thinner than traditional toothbrushes. This slim profile allows for better access to hard-to-reach areas of the mouth, ensuring a thorough and effective clean.

The AeroGlide UltraSlim Smart Toothbrush also incorporates smart technology. It connects to a mobile app via Bluetooth, allowing users to track their brushing habits and receive personalized recommendations for improving their oral hygiene routine. The app provides real-time feedback on brushing technique, ensuring that users are brushing for the recommended two minutes and covering all areas of their mouth.

The toothbrush itself is made from a durable and hygienic material called thermoplastic elastomer. This material is non-porous, meaning it doesn't harbor bacteria or mold, making it more hygienic than traditional toothbrush bristles. The bristles are also ultra-soft, providing a gentle yet effective clean without causing any damage to the gums or enamel.

In addition to its technological features, the AeroGlide UltraSlim Smart Toothbrush is also eco-friendly. It is designed to last for up to six months, reducing the need for frequent replacements. The brush head is also replaceable, further reducing waste.

Overall, the AeroGlide UltraSlim Smart Toothbrush by Boie offers a combination of advanced technology, slim design, and eco-friendly features. It aims to provide users with a superior brushing experience, helping them maintain optimal oral health.
				
			

You can help avert hallucinations by writing clear and specific instructions and giving the model time to think.

You can also reduce hallucinations by asking the model first to find any relevant quotes from the text, then use those quotes to help answer any questions, and then tracing the answer back to the source document.

Next: Iterative Prompt Development

More to explore

Iterative Prompt Development

You want to have a good process to make your prompt iteratively better because, odds are, your first prompt won’t work as