Amazon Titan Text Prompt Engineering Guidelines
Amazon Titan Text Prompt Engineering Guidelines
Copyright © 2024 Amazon Web Services, Inc. and/or its affiliates. All rights reserved.
Amazon's trademarks and trade dress may not be used in connection with any
product or service that is not Amazon's, in any manner that is likely to cause
confusion among customers, or in any manner that disparages or discredits
Amazon. All other trademarks not owned by Amazon are the property of their
respective owners, who may or may not be affiliated with, connected to, or
sponsored by Amazon.
Table of Contents
Introduction 3
Titan Text Prompt Engineering Best Practices 4-13
Applications 14-20
2
Amazon Titan Text: Prompt Engineering Guidelines
Introduction
Prompt engineering refers to the critical process of optimizing the textual input
provided to FMs in order to obtain the desired responses. Effective prompting enables
FMs to perform a wide variety of tasks with high quality outputs. The structure and
quality of the prompts supplied to Amazon Titan Text models can have a significant
impact on the quality of the model's responses.
The primary aim of this guide is to provide users with best practices for prompt
engineering, along with illustrative examples demonstrating how to effectively
prompt the model. Furthermore, it will showcase key applications that can be built by
employing the appropriate prompting techniques with Titan Text models. This
information is intended to help users get started with prompt engineering and enable
them to build robust applications with Amazon Titan Text models.
NOTE: The format and sections presented below serve as a guide and do not impose a
strict requirement to adhere to this specific approach. Feel free to adapt and modify
the structure as needed.
3
Amazon Titan Text: Prompt Engineering Guidelines
This section of the guide demonstrates some best practices for crafting prompts to
return optimal results from Titan Text models.
9 Prompting Strategies
for getting better results with Titan Text models
These strategies and tips can be used in combination with other prompt engineering
efforts to produce better overall results from the model.
NOTE: Prompt Engineering is both an art and a science, and requires iterative rounds
of testing, prompt engineering, and re-testing to get optimized model performance.
It is recommended to follow a Test-Driven Development (TDD) approach for building
an evaluation dataset with composition from both standard use cases and edge cases.
These test cases can then help in evaluating different versions of prompts to create a
final robust, generic, most performant prompt template.
NOTE: The double curly braces {{ and }} mark the places to insert data-specific
information in the template, and should not be included in the prompt text.
4
Amazon Titan Text: Prompt Engineering Guidelines
Titan Text models are specifically trained to recognize User: and Bot: prefixes. Use
User: to indicate the user prompt and Bot: to trigger the model to start the text
completion. For single turn use cases, User: and Bot: prefixes are optional, while for
multi-turn use cases such as conversational chat, User: and Bot: turn should always
be used to indicate conversational turns.
Single Turn Prompt Template: For single turn use cases, User: and Bot: prefixes are
optional.
Prompt Template:
{{ user_prompt }}
Prompt Template:
User: {{ user_prompt}}
Bot: {{ model_response }}
User: {{ user_prompt_second_turn }}
Bot: {{ model_response_second_turn }}
User: {{ user_prompt_third_turn }}
Bot: {{ model_response_third_turn }}
(Source: AWS)
Titan Text models work best if the instructions are clear, well structured, short, and
specific. When prompting the model, try to keep instructions as clear as possible in a
way a human would understand them (as opposed to a machine). This is because the
model has seen much more natural language than it has code, so it will understand
this format better.
5
Amazon Titan Text: Prompt Engineering Guidelines
Example:
Prompt Optimized Prompt
Write steps to create a blog post Write a bulleted list of easy-to-
on Generative AI follow steps when creating a blog
post on Generative AI. Follow the
instructions below:
Instructions:
- Instruction 1
- Instruction 2
- Instruction 3
Titan Text Model works best if all the instructions that the model needs to pay close
attention to are consolidated under one section. If there are convoluted instructions,
break down the instructions into multiple easy to follow instructions.
Prompt Template:
Instructions:
- {{Instruction 1}}
- {{Instruction 2}}
- {{Instruction 3}}
- {{Instruction 4}}
(Source: AWS)
6
Amazon Titan Text: Prompt Engineering Guidelines
3.2. Break down: Titan Text models work best with simple and easy-to-follow
instructions. Break down multiple series of instructions into smaller steps.
Example:
Prompt Optimized Prompt
Please follow the instructions Please follow the instructions
below: below while responding:
- Do A which is a subset of B and
then do C such that D's condition Instructions:
is met - Do A
- Use A's output to do B
- If D is met, then do C
(Source: AWS)
4. Use a persona
Titan Text models work best if instructions are associated with a role or persona.
Assigning a role or persona and providing additional context, helps the model’s
responsiveness, accuracy, and adaptability to the context, as the model can take on
the role’s perspective while answering the question. It is generally recommended to
place this in the prompt preamble or in the instructions section.
Example:
Prompt Optimized Prompt
Write a product feature request for Act like you are an experienced
XYZ product product manager at XYZ company. You
are tasked to write a product
feature request for XYZ product.
Please follow the instructions
below in crafting a feature request
based on the provided context.
Instructions:
{{ instructions }}
(Source: AWS)
7
Amazon Titan Text: Prompt Engineering Guidelines
Prompt Template:
Act like you are {{persona}} who when given {{input}} generates
{{required output constraints}}
Follow these instructions while answering the question:
{instructions}
Titan Text models work better in reasoning if given time to think through the
problem before arriving at the answer. This process, of guiding the model to think
step-by-step and make attempts at reasoning before arriving at an answer, is called
chain-of-thought (CoT) prompting.
Example:
Prompt Optimized Prompt
I had $50. I spent $20 on gas and I had $50. I spent $20 on gas
spend $15 on my lunch sandwich. I and spend $15 on my lunch
ended up at the casino and bought a sandwich. I ended up at the
ticket for $10. Out of that ticket, I casino and bought a ticket for
won $420. I met a friend on my way $10. Out of that ticket, I won
home and gave him the rest of my $20. I met a friend on my way
money. How much money did I spent in home and gave him the rest of my
total today? money. How much money did I
spent in total today? Do not
directly answer this, first
formulate the problem and think
step by step and walk me through
your reasoning.
(Source: AWS)
8
Amazon Titan Text: Prompt Engineering Guidelines
Example:
Prompt Optimized Prompt
Your task is to Classify the Your task is to Classify the following
following texts into the texts into the appropriate categories.
appropriate categories. The The categories to classify are:
categories to classify are:
Categories:
Categories: - Food
- Food - Entertainment
- Entertainment - Health
- Health - Wealth
- Wealth - Other
- Other
Examples:
Input: I have 20$ in my pocket. User: I love to eat pizza.
Bot: Food
9
Amazon Titan Text: Prompt Engineering Guidelines
Prompt Template:
{{Describe the task you want the model to perform}}
Examples:
You can bring extra attention to specific parts of the prompt with specific formatting.
7.1. Use delimiters: Bring model’s focus to specific sections of the prompt by using
new line separators along with defining each section’s name. To define the name of
the section, use {{Section Name}} followed by a colon, replacing “Section Name” with
a meaningful title.
Example:
Prompt Optimized Prompt
Here are the Here are the instructions below
instructions Instructions:
- Instruction 1 - Instruction 1
- Instruction 2 - Instruction 2
- Instruction 3 - Instruction 3
10
Amazon Titan Text: Prompt Engineering Guidelines
based on the
provided inputs Please respond in the following provided schema
format:
Output Schema:
...{{ output schema }}
7.2. Other types of emphasis: To further emphasize certain parts of the prompts or
instructions, use capitalization on instructions that the model should strictly obey
such as DO this or DO NOT do this. Quotes can also be used to help the model focus
on the quoted strings.
Example:
Prompt Optimized Prompt
You should You MUST answer in JSON format only.
answer in a JSON
DO NOT use any other format while answering the
question
(Source: AWS)
To control the format of the responses, provide explicit instructions on how to format
the results. In addition to giving the model instructions to respond in certain format,
it is also recommended to provide an output schema as an example for the model.
Example:
Prompt Optimized Prompt
Make sure you You MUST answer in JSON format only.
output the DO NOT use any other format while answering the
response in question.
JSON
11
Amazon Titan Text: Prompt Engineering Guidelines
{{json content}}
```
(Source: AWS)
9. Minimize hallucinations
9.1. Instruct the model to say “I don’t know”, instead of making up information:
One way to prevent hallucinations is by providing better prompting guidance to the
model. To do this, explicitly tell the model to not make up information if it does not
have an answer.
12
Amazon Titan Text: Prompt Engineering Guidelines
Example:
DO NOT make up any information if you do not know the answer to the
asked question.
In case you do not know the answer, just say "Sorry, I do not have
access to this information."
(Source: AWS)
9.2. Prompt leakage: There is a risk that LLMs may reveal parts of the input prompt
in its generated output. For example, while providing few shot examples or
instructions, the model can suffer from prompt leakage, which means that sometimes
the model over-indexes on the examples provided instead of just learning stylistic and
formatting patterns from those examples. To mitigate this behavior, provide a
separation between Instructions block and the Input Query by using delimiters such
as Section Name: with new line separator as mentioned above. Apart from that, it is
advised to provide strong instructions for the model to not regurgitate the input
prompt contents in its output.
Example:
Prompt Optimized Prompt
Below are the instructions Follow the instructions when
{INSTRUCTIONS} responding.
.... Instructions:
Use the examples below to make a {{INSTRUCTIONS}}
recommendation.
Below are some examples for
reference.
Examples:
{{EXAMPLES}}
13
Amazon Titan Text: Prompt Engineering Guidelines
Applications
1. Chatbots
Amazon Titan can be used to build chatbot applications. In this section, we provide
the best practices for developers writing prompts for chatbots using Titan text
models on Amazon Bedrock.
Applicable models:
Titan Text Lite, Titan Text Express, Titan Text Premier
Components of a Prompt
The prompt for a chatbot application contains the following components:
• Conversation history: since the model is stateless and does not keep records of
the previous conversation turns, developers need to explicitly include the
previous turns in the prompt to enable the model to respond coherently.
Example:
User: hey
Bot: Hello! How may I assist you today?
User: how long should i cook pasta for?
Bot: The general rule of thumb is to cook pasta for 8-12 minutes, or
until it is al dente. However, the exact cooking time can vary depending
on the type and thickness of the pasta, as well as your personal
preference. For example, thin spaghetti or angel hair pasta may cook
more quickly than thicker pasta like spaghetti or linguine.
Additionally, if you are cooking pasta for a meal that includes other
ingredients, you may need to cook it for a shorter amount of time to
ensure that it is not overcooked. It is also important to note that you
should always check the pasta for doneness before serving it. The best
way to do this is to bite into a piece of pasta and see if it is firm
but still has a little bit of chewiness. If it is too soft or mushy, it
may need to cook for a few more minutes. Overall, cooking pasta is a
simple and enjoyable process, and with a little bit of practice, you can
become a master at it!
(Source: AWS)
14
Amazon Titan Text: Prompt Engineering Guidelines
• End-user input: the utterance or question from users in the current turn during the
conversation.
Example:
User: what about for fresh pasta instead of dried pasta?
Bot:
By combining the two components above to a single prompt, we can get the
following response from Titan:
Response:
Fresh pasta is a great option if you want a lighter and more delicate
texture. It is made from scratch using simple ingredients like flour and
eggs, and it does not require any drying or processing. One of the
benefits of fresh pasta is that it cooks much faster than dried pasta.
This is because the dough is not dried out, so it does not need to
absorb as much water during cooking. This means that you can have fresh
pasta on your table in less than 10 minutes, which is great for busy
weeknights or last-minute meals. Another benefit of fresh pasta is that
it has a higher moisture content, which can result in a more flavorful
and tender pasta dish. This is because the pasta is not dried out, so
the starches and flavors are preserved.
15
Amazon Titan Text: Prompt Engineering Guidelines
However, fresh pasta does have some drawbacks. It is more expensive than
dried pasta, and it does not last as long. Fresh pasta needs to be used
within a few days of making it, or it will start to spoil. Additionally,
it is more difficult to store than dried pasta, as it needs to be kept
in the refrigerator to prevent it from drying out. Overall, fresh pasta
is a great option for those who want a lighter and more delicate
texture, and who are willing to pay a higher price for it. It is quick
and easy to cook, and it has a higher moisture content, which can result
in a more flavorful and tender pasta dish. However, it does have some
drawbacks, such as being more expensive and more difficult to
store than dried pasta.
(Source: AWS; Model used: Titan Text G1 – Express)
Prompt template:
It is recommended to have the following in the chatbot prompt:
• Append User: and Bot: prefixes to before the user input and model response
for each turn in multi-turn conversations
• Separate each conversation turn with double line breaks \n\n
• Add User: to the stop sequence for proper conversation generation
Template
{{system instruction}}
{{conversation history}}
User: {{user input}}
Bot:
(Source: AWS)
16
Amazon Titan Text: Prompt Engineering Guidelines
2. Text2SQL
The process of converting natural language questions to executable SQL queries for
relational databases are known as Text-to-SQL or Text2SQL. Large language models
(LLMs) like Titan can be used for Text2SQL tasks in building applications where users
retrieve information from databases by asking questions in natural language
statements. An important step in the process is the construction of prompts that give
Titan all of the information it needs about the database to output useful SQL queries.
In this section, we share best practices for using Titan on a Text2SQL task.
Applicable models:
Titan Text Lite, Titan Text Express, Titan Text Premier
Let’s start with a simple example where we assume that we have a database named
“university” which contains two tables about university attendance and graduation
rates:
Table: Attendance
university_id name number_students
1 UC Berkeley 7325
2 UC Davis 7350
3 UC Santa Barbara 5400
4 UCLA 7700
Table: Graduation
university_id name graduation_rate
1 UC Berkeley 0.76
2 UC Davis 0.55
3 UC Santa Barbara 0.69
4 UCLA 0.74
(Data from https://nces.ed.gov/)
Let’s say the user is interested in the number of seniors who graduate from each
university. Here is a query that will return the appropriate calculation:
17
Amazon Titan Text: Prompt Engineering Guidelines
Writing SQL queries to extract information is a skill that must be learned, and queries
can be extremely complex. Fortunately, LLMs can help by translating natural
language questions into SQL queries.
In order for Titan to return a SQL query, it must be provided with the full schema of
the database within the prompt. Since the language model does not have direct
access to the tables themselves, it must get all of the necessary information about
them from the prompt.
Components of a Prompt:
The general structure of a prompt for Text2SQL with Titan should be as follows:
Depending on the use case, the database schema can be very long. Concise and self-
explanatory names result in shorter prompts and often produce better responses.
Here is an example prompt based on the table described above for the task, “Multiply
the number of seniors attending by the graduation rate to find how many students
graduate”.
18
Amazon Titan Text: Prompt Engineering Guidelines
Running the SQL statement output by Titan will return an answer to the question as
desired.
Prompt Template:
In order to build a prompt like this for your own database, please follow the above
example, and fill in the specifics for the SQL tables using the template described
below.
For the schema entries in the prompt template below, “table_1” refers to the name
of the first table, “table_2” to the second, etc. Within the schema entries, “column
19
Amazon Titan Text: Prompt Engineering Guidelines
1_1” is the name of the first column of table_1, “column 1_2” is the name of the
second column of table_1, “column 2_1” is the name of the first column of table_2,
etc. For the column names entries, “format 1_1” is the data type (e.g., “text” or
“number”) of the first column of the first table, “format 1_2” is the data type of the
second column of the first table, “format 2_1” is the data type of the first column of
the second table.
Primary keys are columns that serve as index columns for a table. For the primary
keys entries, “column 1_primary1” is the name of the column that is the first primary
key from table 1.
Foreign keys are columns present across more than one table that can be used in join
operations. For the foreign keys entries, “column 1_foreign1” is the name of the
column that is the first foreign key from table 1.
Prompt Template:
This is a task converting text into a SQL statement. We will first give
the dataset schema and then ask a question in text. You are asked to
generate a SQL statement.
[Schema (values)]: | {{database_name}} | {{table 1}} : {{column 1_1}},
{{column 1_2}},
{{column 1_3}}, ... | {{table 2}} : {{column 2_1}}, {{column 2_2}},
{{column 2_3}}, ...
[Column names (type)]: {{table 1}} : {{column 1_1}} ({{format 1_1}}),
{{column 1_2}}
({{format 1_2}}), {{column 1_3}} ({{format 1_3}}), ... | {{table 2}} :
{{column 2_1}} ({{format
2_1}}), {{column 2_2}} ({{format 2_1}}), {{column 2_3}} ({{format
2_1}}), ...
[Primary keys]: {{table 1}}: {{column 1_primary}}, ... | {{table 2}} :
{{column 2_primary}}, ...
[Foreign keys]: {{table 1}}: {{column 1_foreign}}, equals {{table 2}} :
{{column 2_foreign}}, ....
20
Amazon Titan Text: Prompt Engineering Guidelines
User prompt:
This is a task converting text into SQL statement. We will be first
given the dataset schema and then ask a question in text. You are asked
to generate SQL statement.
21
Amazon Titan Text: Prompt Engineering Guidelines
Running the SQL statement output by Titan will return an answer to the question as
desired.
Prompt Template:
In order to build a prompt like this for your own database, please follow the above
example, and fill in the specifics for the SQL tables using the template described
below.
This is a task converting text into a SQL statement. We will first give
the dataset schema and then ask a question in text. You are asked to
generate a SQL statement.
22
Amazon Titan Text: Prompt Engineering Guidelines
[Q]: {{question}}
[SQL]:
The natural language question included in the prompt should be concise and focused,
and keywords from the SQL schema should be included in the question. For example,
if there is a “graduation_rate” column, that refers to the “graduation rate” in the
question, as above. This conveys the relevant tables and columns for the query to
Titan. Questions should be placed at the end of the prompt for best results.
Avoid long questions with ambiguous references. For complex queries with multiple
conditions or joins, the question should be broken up into multiple simpler questions.
Titan can translate each question into a SQL statement, and the fragments can be
combined into a full query. This divide-and-conquer approach produces better results
than a single, long question.
23
Amazon Titan Text: Prompt Engineering Guidelines
3. RAG
For building any generative AI application, it is imperative to enrich the large
language models (LLMs) with new data. This is where the Retrieval Augmented
Generation (RAG) technique comes in. RAG is a technique in which the retrieval of
information from data sources augments the generation of model responses. In order
to ingest these external data sources, Vector databases are employed, which can store
vector embeddings of the data source and allow for similarity searches.
Another method is to build your own RAG solutions using the various components
needed for an effective RAG architecture. In this case, you can bring your own
embedding models and create a vector store database. It can then be combined with
the retrieval logic to retrieve the relevant and similar document chunks. The key here
is to properly position the retrieved information, called context, in the final prompt
that will be fed to the LLM.
Applicable models:
Titan-Text Premier
24
Amazon Titan Text: Prompt Engineering Guidelines
Question: The Question section is where a user query is passed to the model. The
model should use the context provided along with the question asked to output a
relevant answer.
Context/Results: Context or Search Results are the section where the context or the
supporting reference text is passed to the model. This text is important as this helps
the model find the relevant answer for the provided question. In practice, this is
typically generated by a retriever module in a RAG system. The module retrieves the
relevant information based on the question from the vector store.
By combining the components above into a single prompt, we can get the following
response from Titan:
User Prompt:
In this session, the model has access to search results and a question.
Your job is to answer the user's question using only information from
the search results.
Model Instructions:
- You should provide concise answer to simple questions when the answer
is directly contained in search results, but when comes to yes/no
question, provide some details.
- In case the question requires multi-hop reasoning, you should find
relevant information from search results and summarize the answer based
on relevant information with logical reasoning.
- If the search results do not contain information that can answer the
question, please state that "I could not find an exact answer to the
question."
Search Results:
25
Amazon Titan Text: Prompt Engineering Guidelines
Output:
Ferdinand Magellan was killed in the Battle of Mactan in 1521.
(Model Used: Titan Text Premier)
Prompt Template:
{{ General instructions }}
{ Model instructions }}
{{ Question }}
{{ Context }}
(Source: AWS)
It's also advisable to include citations in the text and refer to them in the generated
answer. This practice supports cross-referencing and validation, ensuring that the
answer aligns faithfully with the context provided.
For adding citation capability, we can add an extra instruction under “Model
Instructions”, instructing the model to cite the answers as shown below. It is also
recommended to have citations in the provided context, which the model should
refer. This generally is marked in [ ] as shown in the example below.
26
Amazon Titan Text: Prompt Engineering Guidelines
User Prompt:
In this session, the model has access to search results and a question.
Your job is to answer the user's question using only information from
the search results.
Model Instructions:
- You should provide concise answer to simple questions when the answer
is directly contained in search results, but when comes to yes/no
question, provide some details.
- In case the question requires multi-hop reasoning, you should find
relevant information from search results and summarize the answer based
on relevant information with logical reasoning.
- If the search results do not contain information that can answer the
question, please state that "I could not find an exact answer to the
question"
- Remember to add a citation to the end of your response using markers
like [1], [2], [3], etc for the corresponding passage supports the
response.
Search Results:
[1] Ferdinand Magellan was a Portuguese explorer best known for having
planned and led the 1519 Spanish expedition to the East Indies across
the Pacific Ocean to open a maritime trade route, during which he
discovered the interoceanic passage thereafter bearing his name and
achieved the first European navigation to Asia via the Pacific.
After his death, this expedition was the first to circumnavigate the
globe in 1519–22 in the service of Spain.
[2] During this voyage, Magellan was killed in the Battle of Mactan,
Mactan Island, now Province of Cebu, Cebu group of islands in 1521 in
the present-day Philippines, after running into resistance from the
indigenous population led by Lapulapu, who consequently became a
Philippine national symbol of resistance to colonialism.
After Magellan's death, Juan Sebastián Elcano took the lead of the
expedition, and with its few other surviving members in one of the two
27
Amazon Titan Text: Prompt Engineering Guidelines
Output:
Ferdinand Magellan was killed in the Battle of Mactan in 1521.[2]
(Model Used: Titan Text Premier)
28