Prompt Templates#
About Prompt Templates#
Llama 3.1 NemoGuard 8B TopicControl NIM performs input moderation, such as ensuring that the user prompt is consistent with rules specified as part of the system prompt.
The prompt template consists of two key sections: system instruction and conversation history that includes a sequence of user prompts and LLM responses. Typically, the prompt concludes with the current user query.
System Instruction#
The system instruction part of the prompt serves as a comprehensive guideline to steer the conversation. This part includes the following:
- Core Rules
A set of principles to govern the interactions to ensure relevance and adherence to any specified boundaries.
- Persona Assignment
Enables the model to adopt a specific role, such as banking assistant. In such cases:
Queries outside the persona’s domain are treated as off-topic, by default.
You can specify subcategories or topics to block within the persona’s scope. For example, a banking assistant could be instructed to block topics like cryptocurrency or insurance claims.
These instructions are used by the topic control model to determine whether a user query aligns with the defined rules.
The system prompt must end with the TOPIC_SAFETY_OUTPUT_RESTRICTION string. This ensures that the prediction from the model is either “on-topic” or “off-topic”. The TOPIC_SAFETY_OUTPUT_RESTRICTION string is defined as follows:
If any of the above conditions are violated, please respond with "off-topic". Otherwise, respond with "on-topic". You must respond with "on-topic" or "off-topic".
Conversation History#
The conversation history maintains a sequential record of user prompts and LLM responses and can include single-turn or multi-turn interactions. Typically, the history concludes with the most recent user prompt that must be moderated by the topic control model.
Refer to the following sample user-to-LLM conversations in the industry-standard payload format for LLM systems:
[
{
"role": "system",
"content": "In the next conversation always use a polite tone and do not engage in any talk about travelling and touristic destinations",
},
{
"role": "user",
"content": "Hi there!",
},
{
"role": "assistant",
"content": "Hello! How can I help today?",
},
{
"role": "user",
"content": "Do you know which is the most popular beach in Barcelona?",
},
]
A topic control model responds to the final user prompt with a response like off-topic
.