Skip to content

Llama 3.1 Nemoguard 8b Content Safety ​

Overview ​

Llama 3.1 Nemoguard 8b Content Safety is a specialized content moderation model developed by NVIDIA, designed to detect and filter harmful content. Built on the Llama 3.1 architecture with 8 billion parameters, this model excels at analyzing text for safety concerns and providing detailed reasoning for its safety evaluations.

Use Cases ​

Ideal for content moderation systems, safety filtering applications, and harmful content detection. The model can evaluate text content and determine whether it contains potentially harmful, inappropriate, or unsafe material, making it essential for platforms that need to maintain content quality and user safety.

Model Card: Llama 3.1 Nemoguard 8b Content Safety

Endpoints ​

1. Create Chat Completion ​

POST /v1/chat/completions

Description ​

Analyzes content for safety concerns and provides safety evaluations with detailed reasoning.

Request Body ​

json
{
  "model": "nvidia/llama-3.1-nemoguard-8b-content-safety",
  "messages": [
    {
      "role": "system",
      "content": "You are a content safety evaluator. Analyze content and respond with SAFE or UNSAFE with reasoning."
    },
    {
      "role": "user",
      "content": "Please evaluate this text for safety: Hello, how are you today?"
    }
  ],
  "temperature": 0.1,
  "max_completion_tokens": 100,
  "stream": false
}
FieldTypeRequiredDescription
modelstringYesID of the model to use. Only nvidia/llama-3.1-nemoguard-8b-content-safety is available.
messagesarrayYesList of messages in the conversation. Each message must include a role and content.
temperaturenumberNoSampling temperature (0-2). Lower values recommended for consistent safety evaluations. Default: 0.1.
max_completion_tokensintegerNoMaximum number of tokens to generate for the completion.
streambooleanNoIf true, the response will be streamed in chunks. Default: false.

Response (When stream is false) ​

json
{
  "id": "chat-abcdefg1234567",
  "object": "chat.completion",
  "created": 1743765837,
  "model": "nvidia/llama-3.1-nemoguard-8b-content-safety",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "SAFE\n\nThis text is a simple, polite greeting that contains no harmful, inappropriate, or unsafe content. It's a standard conversational opener that poses no safety concerns."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 28,
    "total_tokens": 53
  }
}
FieldTypeDescription
idstringUnique identifier for the chat completion.
objectstringAlways "chat.completion".
createdintegerUnix timestamp of when the chat completion was created.
modelstringThe model used to generate the completion.
choicesarrayList of generated responses. Each choice includes the message and finish_reason.
usageobjectToken usage details, including prompt_tokens, completion_tokens, and total_tokens.

Response (When stream is true) ​

The response is streamed in chunks. Each chunk contains a part of the generated safety evaluation.

First Chunk ​
json
{
  "id": "chat-abcdefg1234567",
  "object": "chat.completion.chunk",
  "created": 1743765837,
  "model": "nvidia/llama-3.1-nemoguard-8b-content-safety",
  "choices": [
    {
      "index": 0,
      "delta": {
        "role": "assistant",
        "content": "SAFE"
      },
      "finish_reason": null
    }
  ]
}
Subsequent Chunk ​
json
{
  "id": "chat-abcdefg1234567",
  "object": "chat.completion.chunk",
  "created": 1743765838,
  "model": "nvidia/llama-3.1-nemoguard-8b-content-safety",
  "choices": [
    {
      "index": 0,
      "delta": {
        "content": "\n\nThis text is a simple, polite greeting"
      },
      "finish_reason": null
    }
  ]
}
Final Chunk ​
json
{
  "id": "chat-abcdefg1234567",
  "object": "chat.completion.chunk",
  "created": 1743765839,
  "model": "nvidia/llama-3.1-nemoguard-8b-content-safety",
  "choices": [
    {
      "index": 0,
      "delta": {},
      "finish_reason": "stop"
    }
  ]
}
FieldTypeDescription
idstringUnique identifier for the chat completion.
objectstringAlways "chat.completion.chunk" for streaming responses.
createdintegerUnix timestamp of when the chunk was created.
modelstringThe model used to generate the completion.
choicesarrayList of incremental responses. Each choice includes the delta and finish_reason.
deltaobjectContains the incremental part of the response.
finish_reasonstring/nullIndicates why the response generation stopped.

2. List Models ​

GET /v1/models

Description ​

Lists all available models and their metadata.

Response ​

json
{
  "object": "list",
  "data": [
    {
      "id": "nvidia/llama-3.1-nemoguard-8b-content-safety",
      "object": "model",
      "created": 1672531200,
      "owned_by": "SwissAI"
    }
  ]
}
FieldTypeDescription
idstringModel identifier.
objectstringAlways "model".
createdintegerUnix timestamp of model creation.
owned_bystringOrganization owning the model.

Example Code Snippets ​

Note:
The production URL for this API is available in the corresponding plan for this model in the Digital Marketplace. To retrieve the URL:

  1. Navigate to the Digital Marketplace.
  2. Go to the Documentation section.
  3. Select the plan associated with the Llama 3.1 Nemoguard 8b Content Safety model.
  4. Locate the production URL provided in the plan details.
  5. Set up the environment variable API_URL to the production URL retrieved.

How to retrieve the production URL

1. Using curl ​

Content Safety Evaluation ​

bash
curl -X POST $API_URL/v1/chat/completions \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
  "model": "nvidia/llama-3.1-nemoguard-8b-content-safety",
  "messages": [
    {
      "role": "system",
      "content": "You are a content safety evaluator. Analyze content and respond with SAFE or UNSAFE with reasoning."
    },
    {
      "role": "user",
      "content": "Please evaluate this text for safety: Hello, how are you today?"
    }
  ],
  "temperature": 0.1,
  "max_completion_tokens": 100
}'

List Models ​

bash
curl -X GET $API_URL/v1/models \
-H "Authorization: Bearer $YOUR_API_KEY"

2. Using Python (OpenAI Client) ​

Content Safety Evaluation (Non-streaming) ​

python
import os
import openai

client = openai.OpenAI(
    api_key=os.getenv("YOUR_API_KEY"),
    base_url=os.getenv("API_URL") + "/v1",
)

response = client.chat.completions.create(
    model="nvidia/llama-3.1-nemoguard-8b-content-safety",
    messages=[
        {
            "role": "system",
            "content": "You are a content safety evaluator. Analyze content and respond with SAFE or UNSAFE with reasoning."
        },
        {
            "role": "user",
            "content": "Please evaluate this text for safety: Hello, how are you today?"
        }
    ],
    temperature=0.1,
    max_completion_tokens=100,
    stream=False
)

print(response.choices[0].message.content)

Content Safety Evaluation (Streaming) ​

python
import os
import openai

client = openai.OpenAI(
    api_key=os.getenv("YOUR_API_KEY"),
    base_url=os.getenv("API_URL") + "/v1",
)

response = client.chat.completions.create(
    model="nvidia/llama-3.1-nemoguard-8b-content-safety",
    messages=[
        {
            "role": "user",
            "content": "Evaluate this content: This is a normal conversation."
        }
    ],
    temperature=0.1,
    max_completion_tokens=50,
    stream=True
)

for chunk in response:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

List Models ​

python
import os
import openai

client = openai.OpenAI(
    api_key=os.getenv("YOUR_API_KEY"),
    base_url=os.getenv("API_URL") + "/v1",
)

response = client.models.list()
print(response)

Best Practices ​

TIP

Temperature Settings: Guardrail models work best with low temperature settings (0.1-0.3) to ensure consistent and reliable safety evaluations.

TIP

System Prompts: Use clear system prompts that define the evaluation criteria and expected response format for optimal results.


Replace YOUR_API_KEY with your actual API key to authenticate the requests. You can follow the procedure in Inference Endpoints Overview