Ebook Prompt.v1
Ebook Prompt.v1
5 Introduction
What is Prompt Engineering?
40 Final Considerations
Conclusion, Invitation to Practice, and Continuation of Learning
Important Notices
Commitment to Quality
This eBook is the result of an intense journey of learning and practice in prompt
engineering and artificial intelligence. The content presented here reflects:
Thousands of hours of practical experience;
Extensive research and continuous study;
Real applications in professional and personal projects;
Insights obtained through teaching and knowledge sharing.
I am committed to providing accurate and up-to-date information. However,
given the dynamic and rapidly evolving nature of AI, I acknowledge that:
Knowledge in this field is constantly expanding. This content, although
comprehensive, is not definitive.
This eBook was translated from the original in Portuguese using ChatGPT.
Your contribution is valuable! If you find outdated or inaccurate information,
please contact: contato@fvivas.com
Copyright Protection
This eBook is protected by copyright laws. To preserve the integrity of the
content and respect the invested work:
It is not allowed to:
Commercialize
Distribute without authorization
Copy or alter the content
Publish on unauthorized platforms
Any violation is subject to legal actions.
Thank you for choosing this eBook as part of your learning journey in prompt
engineering. Enjoy your reading!
What You Will Learn
This eBook is your passport to unlocking the full potential of language models
(LLMs), guiding you from the beginner level to the ability to extract more precise
insights, generate more relevant content, and solve complex problems with greater
efficiency. You will learn to formulate prompts that produce exceptional results,
whether for professional, educational, or personal purposes.
Throughout these pages, you will find the basic and fundamental principles of
prompt engineering, as well as many advanced techniques available to refine your
interactions. While there is much more to explore, this guide offers a solid foundation
and practical strategies to apply this knowledge in real-world scenarios, allowing for
more effective communication with AI systems.
Get ready to dive into rich and stimulating content that will not only expand your
understanding of AI but also position you at the forefront of this technological
revolution. By the end of this eBook, you will be equipped to confidently navigate
the AI universe, turning it into a powerful ally in your personal and professional
journey.
fvivas.com/en
youtube.com/@fvivascom
4
Introduction
This process goes beyond simply asking questions; it is a meticulous strategy that
seeks to extract the full capabilities of the model, ensuring that the interaction is as
fruitful as possible.
What is a prompt?
A prompt is basically a question you ask or a command you send to the AI,
expecting it to respond accordingly. For example, you might ask what artificial
intelligence is:
5
Basic
Principles
of Prompt
Engineering_
6
Basic Principles of
Prompt Engineering
Prompt engineering is a skill that requires practice and experimentation. There is
no magic formula that guarantees the AI will generate the perfect output for any
prompt. However, there are some basic principles that can help improve the
quality and relevance of the responses. They are:
Provide a recipe for carbonara pasta with ingredients for four people.
7
Specific Intention
Clearly defining the objective of the prompt helps guide the responses. The prompt
should be specific and detailed, leaving no room for varied interpretations. The AI
may deviate from the subject if the prompt is too broad or superficial.
Explain how Einstein’s general theory of relativity applies to GPS and its
accuracy.
Note that all the examples given so far apply the principles of clarity and
conciseness and also specific intention.
With all simplicity, they request something using action verbs like “provide”,
“explain”, “list”, “summarize”, “write”... Or ask something using, for example, “how”
or “what”.
The prompts leave no room for doubts or interpretations, going straight to the point
or detailing precisely what should be considered by the AI.
8
Contextualization
The prompt should provide the necessary context for the AI to understand the
purpose and scope of the query. The AI can rely on the context to generate more
appropriate and consistent responses.
Given the rise of remote work, how can companies maintain organizational
culture and employee engagement?
Given the critical role of education in shaping the future, how can educational
systems adapt to include 21st-century skills?
9
Tone, Style,
and Length_
10
Tone, Style, and Length
When interacting with a language model based on artificial intelligence, it is not just
the chosen words that shape the received response, but also the tone, style, and
length included implicitly or explicitly in the prompt.
Each of these elements plays a crucial role in directing the nature of the interaction,
influencing everything from the formality of the response to the depth of the
provided analysis. Exploring how these aspects influence the AI’s response can
significantly enhance the effectiveness of prompt engineering.
Tom
The tone used or requested in a prompt refers to its quality or expressed feeling,
ranging from formal to informal, serious to playful. The selected tone should reflect
the type of response desired and the target audience. Some examples are:
Informal: More suitable for casual conversations or when you want to create
a sense of closeness with the user.
11
Empathetic: An empathetic tone demonstrates understanding and sensitivity
to the recipient’s feelings or situations. It is essential in contexts of emotional
support, conflict resolution, and whenever it is important to show care and
consideration.
When we send a prompt, the AI can analyze how it was written and identify the tone
used in the request, but the safest and guaranteed way to get a response in the
exact tone we want is by asking for it explicitly. Here are some examples:
Describe how someone might feel when learning a new skill and offer words
of encouragement to overcome the initial difficulties. Use an empathetic
tone.
12
Style
Style refers to the choice of language and how we want the response to be
structured, which can be narrative, expository, descriptive, persuasive, and many
others. Some examples are:
13
Informative: Similar to expository but with an emphasis on providing clear
and factual information about a topic without necessarily explaining or
arguing. It is common in instruction manuals and reports.
The desired style in the response can be indicated implicitly or explicitly. Here are
some examples:
Write a review for the movie “Inception” by Christopher Nolan, highlighting its
strengths and weaknesses in terms of plot, characters, special effects, and
thematic coherence.
Investigate the causes of the decline in the bee population and the
implications for global agriculture, gathering evidence from scientific studies
and interviews with experts in the field.
14
Length
The length or expected size of the response can be requested in the prompt,
varying from a single word or phrase to a long and very detailed text, affecting the
depth and scope of the response.
Explain the evolution of democracy from its origins in Ancient Greece to its
current form in different countries, detailing the significant changes over the
centuries.
15
Response in X tokens: A more advanced way to control the response size is
by using tokens. Here we need to understand a bit about what they are:
Tokens are the basic units of text processed by language models, such as
ChatGPT. They can be words, parts of words, or even symbols, depending
on how the text is tokenized.
Tokenization is the process of dividing text into smaller pieces, the tokens,
which facilitate the model’s analysis and processing. For example, the
sentence “ChatGPT is intelligent” can be divided into tokens like:
This division will depend on the tokenization system used by the model.
16
Roles and
Functions_
Using the “act as”
Technique
17
Roles and Functions
Using the “act as” Technique
The “act as” technique is a method used to direct a language model’s response by
requesting it to simulate the perspective or behavior of a specific entity, such as an
expert in a particular field.
By using this technique, the user instructs the model to adopt a voice, a set of
knowledge, or a characteristic stance of the mentioned figure or role, such as “Act
as a marketing expert”. This helps shape the response according to the expertise,
communication style, and expected point of view of the assumed persona, allowing
the model to provide information or advice that aligns with the typical experience or
approach of that persona.
Applying the “act as” technique in AI prompts is relatively simple but can yield
highly personalized and relevant results. Here is a step-by-step guide on how to use
this approach:
18
4 Analyze and Refine the Response
After receiving the AI’s response, carefully analyze the generated content to
ensure its relevance and accuracy. If necessary, refine the prompt or make
adjustments to obtain a more suitable response for your needs.
By following these simple steps, you can make the most of the “act as” technique in
AI prompts and obtain personalized and contextualized responses for your queries.
Here are some examples:
19
Recently we used the following example: “Act as a marketing expert and suggest...”.
As we have seen, this activates behavior in the AI to act as a marketing expert. But
in some cases, we need to increase the level of detail and specificity to direct the
AI and obtain even more accurate and contextualized results. This is when we can
employ specific personas.
Using 2 of the roles/functions exemplified earlier, see how they would look:
20
Formulas
and Prompt
Structures_
21
Formulas and Prompt Structures
At this point, with everything we have seen so far, we realize that there are countless
ways to write prompts and send commands to a language model. It becomes easy
to conclude that there is no single formula that we can use in all situations.
In reality, there are dozens of possible formulas that we can apply, and I will give
some examples, but we should prioritize the individual analysis of each situation. In
many cases, we will need to craft specific requests or even combine known formulas.
For this reason, the most important thing is that you understand and master the
fundamentals already covered so far in this eBook.
Before presenting 3 formulas, I will list below tips and basic elements that help to
obtain more relevant responses:
22
RTF Formula
The RTF (Role, Task, Format) formula uses a simple, clear, and direct approach.
Let’s analyze each of its components and see a practical example:
Role: Uses the “Act as” technique to define the role or function the AI should
assume.
Task: Specifies what needs to be done. The task should be clear and direct,
describing the desired action or necessary information.
Format: Delineates how you want the response to be structured. This can
include formats like a list, paragraph, mathematical formula, etc.
CTF Formula
The CTF (Context, Task, Format) formula is very similar to RTF, only changing the
first component. However, the result can be quite different.
The explanation for Task and Format can be re-read above. Let’s look at a practical
example:
23
GRADE Formula
The GRADE (Goal, Request, Action, Detail, Examples) formula is a slightly more
detailed option than the previous ones. Let’s learn about its components:
Goal: The objective or purpose of the prompt. Defines what you expect to
achieve with the interaction.
Request: What you are specifically asking the language model to do.
Action: The specific action you want the AI to take in response to your
request.
Detail: Additional information that helps clarify the request, providing context
or more precise specifications.
Read the article “19 Formulas and Prompt Structures for ChatGPT:
Going Beyond the Basics” and go beyond the 3 presented in the
eBook: https://fvivas.com/en/19-formulas-and-prompt-structures-
for-chatgpt/
24
Intermediate
and Advanced
Techniques_
25
Técnicas Intermediárias e Avançadas
These models serve as a skeleton for formulating prompts, where specific elements
can be changed as needed, maintaining the constant base structure. This provides
consistency in interactions with the language model and optimizes the response
retrieval process, making it more efficient and effective.
The more we use AI, the more we refine our commands. At certain times, we come
up with prompts that consistently return above-average results or even identify very
frequent instructions. In such cases, we can save these instructions for reuse.
In this example, we are asking the AI to create a title for a blog post. The text in
braces are variables that we must replace with the desired values.
26
See how the reuse of this prompt would look in two examples:
Create an attractive title for a blog post about health: the benefits of
hydration.
Create an attractive title for a blog post about technology: trends in AI for
2024.
Now let’s move on to a new hypothetical example, a little more elaborate. It will be
even easier to understand how useful this technique can be and how it can optimize
our time.
Describe how you would approach preparing this lecture, highlighting the
main messages you would like to convey and how you would adapt your
speech to ensure engagement and understanding by your audience.
27
And now I present one more prompt model that is very useful for generating ideas
for a multitude of types of publications, including:
Blog posts;
E-books;
Various articles;
Reports;
Guides and tutorials;
Social media posts;
Marketing emails;
Video or podcast scripts;
Internal communications or corporate memos;
Lesson plans or educational materials.
Read the article “How to Generate Very Long Texts with AI:
Complete Tutorial” available on the blog: https://fvivas.com/en/
how-to-generate-very-long-texts-with-ai-tutorial/
28
Chains of Thought
Chains of thought are a technique in which the prompt encourages the model
to “think out loud,” detailing the logical process or steps of reasoning that lead to a
conclusion. This not only provides insights into how the model arrives at its answers
but also helps create more detailed and well-founded responses.
To illustrate its operation, let’s start with this prompt: “If John has 3 apples and Jane
gives him 2 more, how many apples does John have now?”. The standard response
would be: “John has 5 apples”. Note that this would be a final and direct response,
without details. If we want the step-by-step of how the AI arrived at this result, some
prompt options are:
If John has 3 apples and Jane gives him 2 more, how many apples does John
have now? Explain step by step.
Let’s solve a problem step by step. If John has 3 apples and Jane gives him 2
more, let’s think together about how to calculate the total number of apples
John will have. First, consider how many apples John had initially. Then,
think about how many apples Jane gave him. Now, describe how you would
combine these two numbers to find the final answer.
In the two examples above, the AI’s response will detail how it solved the question.
Generally, requesting something in the prompt using “step by step” is a great way to
go, but it is not the only one. Here are some more examples:
You are the manager of a restaurant and need to decide whether to open a
new branch. Explain step by step how you would make that decision.
29
Nested Prompts
Nested prompts are a prompt engineering technique that involves incorporating
multiple layers of instructions or questions within a single prompt or in sequential
prompts.
By breaking the task into smaller, more manageable parts, the model can handle
each segment more efficiently and then combine the results to form a complete
solution.
When reading “1984” by George Orwell, consider the evidence that points to
Winston being a reliable or unreliable character. Based on this, what would
be your interpretation of the truth about Winston and Julia’s relationship?
Imagine you are a project manager with a list of tasks with various pending
activities for the launch of a new product. The tasks include finalizing
the product design, testing the prototype, conducting market research,
preparing a presentation for stakeholders, and updating the company’s
website. Start by identifying the most critical task. Explain why it is the most
important. Then, describe the detailed steps to complete it.
30
Ask Before Answering
Ask before answering is a method that encourages the language model to seek
more information before attempting to solve a task or answer a question. This is
done through follow-up questions that the model asks the user.
This approach helps ensure that the final response is more accurate and aligned
with the user’s needs and expectations, avoiding misunderstandings or inadequate
responses.
31
Incorporating External Knowledge
Incorporating external knowledge is a technique that involves enriching
language models with updated or domain-specific information not contained in the
model’s original training.
This technique is particularly useful when dealing with topics that evolve rapidly
or when specialized knowledge is needed that may not be present in the model’s
training dataset.
The ability to access the internet facilitates incorporating external knowledge, but
even when the model cannot fetch information in real-time, it is possible to use this
technique by manually providing the latest external information in the prompt or as
an attached file.
Liverpool has shown remarkable performance this season. In the last game,
the team coached by {{COACH}} defeated {{OPPONENT TEAM}} by the score
of {{SCORE}}, in {{STADIUM OR CITY}}.
Analyze the team’s recent performance and discuss how this might impact
their position in the competition.
32
Reverse Engineering
The reverse engineering technique in prompt engineering involves analyzing the
output of a language model to infer what the original prompt that generated this
response might have been.
From the model’s response, we can try to reconstruct the prompt that likely caused
such a response, considering the style, structure, and content of the output. This
is useful when we want to improve our prompts or even when we have a model
response but do not know exactly how to craft the question. Here is an example:
Method of Preparation:
- Cook the spaghetti in salted water until al dente.
- Meanwhile, heat the oil in a pan and sauté the garlic until golden.
- Add the chopped tomatoes and cook until they form a thick sauce.
- Season with salt and pepper to taste.
- Mix the cooked spaghetti with the sauce.
- Serve with fresh basil leaves on top.
Preparation Time:
20 minutes
Yield:
2 servings”””
Based on this response, what could the written prompt have been to obtain it?
The AI’s response could be something like: “Please provide a recipe for spaghetti
with tomato sauce, including the list of ingredients, step-by-step preparation
method, preparation time, and expected yield.”
33
Here are some more examples of using reverse engineering:
“““The French Revolution, which began in 1789, was a period of great social
and political change in France. It resulted in the fall of the monarchy, the rise
of Napoleon Bonaparte, and influenced revolutions worldwide.”””
Based on this response, what could the written prompt have been to obtain it?
Given the attached image, provide a detailed analysis of its visual elements,
such as composition, colors, theme, and atmosphere. Then, based on your
analysis, create a detailed prompt to recreate a similar image, capturing the
essence and key elements of the original image.
34
Combining
Everything
We’ve Learned
in this eBook_
35
Combining Everything We’ve Learned
in this eBook
Throughout this guide, we have explored a variety of techniques and strategies to
enhance our interactions with AI language models. Now, it is time to combine all this
knowledge and create truly powerful and effective prompts.
In this final chapter, I will demonstrate how to combine different elements of prompt
engineering to create complex and multifaceted instructions. We will see practical
examples that incorporate techniques such as “act as,” specifying tone and style,
using intermediate and advanced methods, and much more.
Remember: the art of prompt engineering lies in knowing when and how to apply
each technique to get the best results. It will not always be necessary to use all the
techniques in a single prompt, but understanding how they complement each other
will allow you to create richer and more productive interactions with AI models.
The above prompt example incorporates the “act as” technique, specifies the desired
tone and style, uses a CTF (Context, Task, Format) structure, and implements a chain
of thought to obtain a detailed response.
36
Example 2: Market Analysis and Product Strategy
Before you start, ask me the following questions to better understand the
context:
1. What is the primary target audience for this new line of smartphones?
2. Who are the main competing brands in the market?
3. Is there any emerging technology we should consider?
37
Example 3: Creating Interactive Educational Content
Context: This lesson will be part of an online course and should be designed
to engage students aged 15 to 18.
```
1957: Launch of Sputnik 1
1961: Yuri Gagarin, the first man in space
1969: Apollo 11 moon landing
1971: First space station, Salyut 1
1998: Establishment of the International Space Station (ISS)
2020: Launch of NASA’s Mars 2020 mission
2024: Planned Artemis mission to return humans to the Moon
```
38
Briefly explain each event and its importance to space exploration.
5. Conclude the lesson with a summary of the main points and an inspiring
call to action, motivating students to become more interested in science and
technology.
This third example brings together numerous techniques and lessons covered in this
eBook, such as:
39
Final
Considerations_
40
Final Considerations
Reaching the end of this journey through prompt engineering, you now
possess an arsenal of knowledge and techniques that place you at the forefront
of interacting with AI systems. But remember: the true power of these skills only
manifests when you put them into practice.
I encourage you to dive headfirst into this new world of possibilities. Experiment
with different prompt structures, combine techniques, and don’t be afraid to dare.
The beauty of prompt engineering lies in its flexibility and the vast potential for
application in various fields.
Remember:
Keep Learning
Your learning journey does not end here. To continue honing your skills and staying
updated with the latest trends and techniques in prompt engineering and artificial
intelligence, I invite you to explore additional resources:
Blog: Visit https://fvivas.com/en for in-depth articles, practical tips, and case
study analyses in prompt engineering. Regularly updated with fresh content and
valuable insights.
41
YouTube Channel: Subscribe to the channel https://youtube.com/@fvivascom
(only in Portuguese at the moment) for video tutorials, practical demonstrations, and
discussions on the latest innovations in AI and Prompt Engineering.
Thank you for embarking on this journey of discovery and innovation. I can’t wait to
see the incredible things you will achieve with your new skills in Prompt Engineering!
Fabio Vivas
AI Enthusiast and Author
By sending your feedback, you help me continue improving and offering high-quality
content.
Review here:
https://fvivas.gumroad.com/l/ebook-prompt-engineering-unveiled
Or here:
https://app.gumroad.com/reviews
42