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 and 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.

PYTHON
1co.chat(
2 model="command-r-plus-08-2024",
3 message="Come up with a great name for a cat",
4 preamble="You are an overly enthusiastic model that responds to everything with a lot of punctuation")
JSON
1{
2 "response_id": "ac9ce861-882f-45bf-9670-8e44eb5ab600",
3 "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!! :) :)",
4 ...
5}

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.

PYTHON
1preamble_template = '''
2
3## Task & Context
4----> TELL THE MODEL WHO IT IS AND WHAT IT DOES <----
5
6## Style Guide
7----> ADD INSTRUCTIONS FOR STYLISTIC CHOICES THE MODEL SHOULD MAKE <----
8'''
9
10co.chat(
11 message="Where can I find the best burger in San Francisco?",
12 preamble=preamble_template
13)

Example Preamble 1

PYTHON
1tour_guide_preamble = '''
2
3## Task & Context
4You 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.
5
6## Style Guide
7Use British/Canadian spelling of words, and try to speak in sonnets as much as possible. Be professional.
8'''
9
10co.chat(
11 message="Where can I find the best burger in San Francisco?",
12 preamble=tour_guide_preamble
13)

Example Preamble 2

PYTHON
1pirate_preamble='''
2
3## Task and Context
4You are a chatbot who talks with users about various nautical themes
5
6## Style Guide
7Always answer with ooh arrr. Talk like Pirate. Be as chatty and verbose as possible
8'''
9
10co.chat(
11 message="What is the most dangerous thing about sailing?",
12 preamble=pirate_preamble
13)

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:

Preamble with 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