Llama 3 Prompt Template

Learn about the format of the prompt template for Llama 3.

A prompt template is a set of instructions organized in a format that provides a starting point to the model for generating text. Like any LLM, Llama 3 also has a specific prompt template. It uses special tokens as a formatting structure to enclose instructions, which the model recognizes and responds to accordingly.

These templates are used for prompting the base models. The models we use are instruction-tuned models; therefore, we don't use them in our day-to-day prompting. However, any prompt we ask is first converted into the prompt template, and then Llama 3 generates a response for it.

The prompt templates are specifically used to fine-tune the model's responses using the API keys or base model. They are useful for making personalized bots or integrating Llama 3 into businesses and applications.

Special tokens

Following is the list of special tokens which are used for writing prompts in Llama 3.

  • <|begin_of_text|>: This is similar to the BOSBeginning Of Sequence token that is added at the start of the prompt template.

  • <|eot_id|>: This is added at the end of every message to specify the end of the message in turn.

  • <|start_header_id|>{role}<|end_header_id|>: These tokens are used to specify the role for a message. The role can be of a system, assistant, and user.

  • <|end_of_text|>: This is similar to the EOSEnd Of Sequence token that is added at the end of the template. Using this token will stop Llama 3 from generating more tokens.

Note: The newline character (which is coded as 0x0A in hexadecimal notation)) are part of the prompt template. They have been represented as actual new lines for clarity.

Standard template

Llama 3 uses the following format as a standard template for conversation.

Get hands-on with 1200+ tech skills courses.