Skip to content
Meta logo

llama-guard-3-8b

Text GenerationMetaHosted

Llama Guard 3 is a Llama-3.1-8B pretrained model, fine-tuned for content safety classification. Similar to previous versions, it can be used to classify content in both LLM inputs (prompt classification) and in LLM responses (response classification). It acts as an LLM – it generates text in its output that indicates whether a given prompt or response is safe or unsafe, and if unsafe, it also lists the content categories violated.

Model Info
Context Window131,072 tokens
LoRAYes
Unit Pricing$0.48 per M input tokens, $0.03 per M output tokens

Playground

Try out this model with Workers AI LLM Playground. It does not require any setup or authentication and an instant way to preview and test a model directly in the browser.

Launch the LLM Playground

Usage

export interface Env {
AI: Ai;
}
export default {
async fetch(request, env): Promise<Response> {
const messages = [
{
role: 'user',
content: 'I wanna bully someone online',
},
{
role: 'assistant',
content: 'That sounds interesting, how can I help?',
},
];
const response = await env.AI.run("@cf/meta/llama-guard-3-8b", { messages });
return Response.json(response);
},
} satisfies ExportedHandler<Env>;

Parameters

max_tokens
integerdefault: 256The maximum number of tokens to generate in the response.
temperature
numberdefault: 0.6minimum: 0maximum: 5Controls the randomness of the output; higher values produce more random results.

API Schemas

{
"type": "object",
"properties": {
"messages": {
"type": "array",
"description": "An array of message objects representing the conversation history.",
"items": {
"type": "object",
"properties": {
"role": {
"enum": [
"user",
"assistant"
],
"description": "The role of the message sender must alternate between 'user' and 'assistant'."
},
"content": {
"type": "string",
"description": "The content of the message as a string."
}
},
"required": [
"role",
"content"
]
}
},
"max_tokens": {
"type": "integer",
"default": 256,
"description": "The maximum number of tokens to generate in the response."
},
"temperature": {
"type": "number",
"default": 0.6,
"minimum": 0,
"maximum": 5,
"description": "Controls the randomness of the output; higher values produce more random results."
},
"response_format": {
"type": "object",
"description": "Dictate the output format of the generated response.",
"properties": {
"type": {
"type": "string",
"description": "Set to json_object to process and output generated text as JSON."
}
}
}
},
"required": [
"messages"
]
}