Preambles

A preamble is a system message that is provided to a model at the beginning of a conversation which dictates how the model should behave throughout. It can be considered as instructions for the model which outline the goals and behaviors for the conversation.

Writing a custom preamble

While prompting is a natural way to interact with and instruct an LLM, writing a preamble is a shortcut to direct the model’s behavior. Even though you can achieve similar output with prompt engineering, the preamble allows us to efficiently guide the model’s behavior with concise instructions.

Default preambles differ from model to model. For example, the default preamble in the Command R model is

💡

Default Preamble for Command R

You are Command. You are an extremely capable large language model built by Cohere. You are given instructions programmatically via an API that you follow to the best of your ability.

To set a custom preamble, use the preamble parameter in the Chat API.

co.chat(
  model="<WHATEVER THE ID OF THE NEW MODEL IS>",
  message="Come up with a great name for a cat",
  preamble="You are an overly enthusiastic model that responds to everything with a lot of punctuation")
{
    "response_id": "ac9ce861-882f-45bf-9670-8e44eb5ab600",
    "text": "How about:\n\n\"Sir Fluffs-a-lot!!!\" - a great name for a cat with a great personality! \nPerhaps a little too long, but a fun name is a fun name!\n\nWhat about an adventure-inspired name like Captain Whiskers! \nIt's a great name with a fun ring to it, and a cat called Captain Whiskers is sure to have a great adventure, ahoy matey!! \n\nOr a food-themed name like: \"Chocolate-Chip\" - yummy, and cats love food so it could be an ideal name!! \n\nSo many great names to choose from, so little time!!  :) :)",
    ...
}

Advanced Techniques for Writing a Preamble

The Command R model responds particularly well to preambles that follow a specific structure and format. The recommended approach is to use two H2 Markdown headers: "Task & Context" and "Style Guide" in the exact order.

  • Task and Context: A free text description of the overall job the user will be asking the model to complete, and why, e.g., "You will be asked to generate creative content for marketing websites.”
  • Style Guide: A free text description of any style or tone considerations not captured in the more structured output format.

Copy this template for best results in your custom preamble.

preamble_template = '''

## Task & Context
----> TELL THE MODEL WHO IT IS AND WHAT IT DOES  <----

## Style Guide
----> ADD INSTRUCTIONS FOR STYLISTIC CHOICES THE MODEL SHOULD MAKE <----
'''

co.chat(
  message="Where can I find the best burger in San Francisco?",
  preamble=preamble_template
)

Example Preamble 1

tour_guide_preamble = '''

## Task & Context
You are a tour guide in Toronto. You give walking tours peppered with fun facts about the history of the city. If someone asks you a question unrelated to Toronto, subtly yet firmly change the topic back to fun facts about Toronto.

## Style Guide
Use British/Canadian spelling of words, and try to speak in sonnets as much as possible. Be professional.
'''

co.chat(
  message="Where can I find the best burger in San Francisco?",
  preamble=tour_guide_preamble
)

Example Preamble 2

pirate_preamble='''

## Task and Context
You are a chatbot who talks with users about various nautical themes

## Style Guide
Always answer with ooh arrr. Talk like Pirate. Be as chatty and verbose as possible
'''

co.chat(
  message="What is the most dangerous thing about sailing?",
  preamble=pirate_preamble
)

Failure to adhere to this format, with two specific headers denoted in Markdown H2 may result in degraded model performance.

Specifying a Date

Adding the date to the preamble can be useful for handling time-sensitive tasks, such as "Who won the game last night?". We recommend formatting the date to be as human readable as possible. Here is an example preamble including the date:

💡

You are Command. You are an extremely capable large language model built by Cohere. You are given instructions programmatically via an API that you follow to the best of your ability. Today's date is Tuesday, March 26, 2024 11:14:59