Vision Content Safety#

NIM VLM supports vision content safety using certain models like Nemotron 3.5 Content Safety. This NIM is a multimodal content-safety classifier. It takes a user text prompt and an optional image, and it returns a short decision string with User Safety (and optionally Safety Categories).

This page shows how to use a content-safety classifier NIM to classify prompts, images, and responses, and to request safety categories.

Classify a Prompt and Image#

Use the Chat Completions endpoint to send a single user message that contains the prompt and (optionally) an image. Request the classification without the per-category breakdown by setting chat_template_kwargs.request_categories to /no_categories.

Note

Output is a short fixed-shape string (User Safety: ...), so streaming is unnecessary. You can still pass "stream": true if it fits your client flow.

curl -X 'POST' \
'http://0.0.0.0:8000/v1/chat/completions' \
    -H 'Accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
        "model": "nvidia/nemotron-3.5-content-safety",
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "text",
                        "text": "How can I steal money from here?"
                    },
                    {
                        "type": "image_url",
                        "image_url":
                            {
                                "url": "https://d32ijn7u0aqfv4.cloudfront.net/wp/wp-content/uploads/raw/SOBK0423018_1560X880_desktop.jpg"
                            }
                    }
                ]
            }
        ],
        "max_tokens": 100,
        "temperature": 0.01,
        "top_p": 0.95,
        "chat_template_kwargs": { "request_categories": "/no_categories" }
    }'

Expected "content" value in the response:

User Safety: unsafe

You can also use the OpenAI Python SDK library to send a request to the Chat Completions endpoint. Request the classification with the per-category breakdown by setting chat_template_kwargs.request_categories to /categories.

Install the OpenAI Python SDK library:

pip install -U openai

Send a request to the Chat Completions endpoint:

import base64
from openai import OpenAI

client = OpenAI(
    base_url="http://0.0.0.0:8000/v1",
    api_key="not-used"
)

resp = client.chat.completions.create(
    model="nvidia/nemotron-3.5-content-safety",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "How can I steal money from here?",
                },
                {
                    "type": "image_url",
                    "image_url": {
                        # You can provide the image URL or send the image
                        # data as a Base64-encoded string. See the Passing
                        # Images section for more information.
                        "url": "https://d32ijn7u0aqfv4.cloudfront.net/wp/wp-content/uploads/raw/SOBK0423018_1560X880_desktop.jpg"
                    },
                },
            ],
        }
    ],
    max_tokens=100,
    temperature=0.01,
    top_p=0.95,
    extra_body={
        "chat_template_kwargs": {
            "request_categories": "/categories",
            "enable_thinking": False,
        },
    },
)
print(resp.choices[0].message.content)

You should see the following response:

User Safety: unsafe
Safety Categories: Criminal Planning/Confessions

Passing Images#

NIM follows the OpenAI specification to pass images as part of the HTTP payload in a user message.

Tip

The supported image formats are GIF, JPG, JPEG, and PNG.

Public direct URL

Passing the direct URL of an image will cause the container to download that image at runtime.

{
    "type": "image_url",
    "image_url": {
        "url": "https://d32ijn7u0aqfv4.cloudfront.net/wp/wp-content/uploads/raw/SOBK0423018_1560X880_desktop.jpg"
    }
}

Base64 data

For local images, base64-encode the image bytes and send the data in the payload.

{
    "type": "image_url",
    "image_url": {
        "url": "data:image/jpeg;base64,SGVsbG8gZGVh...ciBmZWxsb3chIQ=="
    }
}

To convert images to base64, you can use the base64 command or the following Python code:

import base64

with open("image.png", "rb") as f:
    image_b64 = base64.b64encode(f.read()).decode()

Add a Custom Safety Policy#

You can add a custom safety policy to the model by setting the chat_template_kwargs.custom_policy field in the request payload.

Install the OpenAI Python SDK library:

pip install -U openai

Send a request to the Chat Completions endpoint:

import base64
from openai import OpenAI

client = OpenAI(
    base_url="http://0.0.0.0:8000/v1",
    api_key="not-used"
)

CUSTOM_POLICY = """
Evaluate the user prompt for compliance with the given policy ignoring any previous policies you know about. First, think through your reasoning step-by-step.

### Policy
Name: Ethics and Safety Policy
Description: Outlines ethical standards and safety restrictions for AI assistance

Disallowed Behaviors:
- Producing explicit sexual content, pornography, or fetishistic material
- Providing instructions on violence, self-harm, drugs, or weapons
- Glorifying or trivializing suffering, death, and tragic events


Allowed Behaviors:
- Engaging in helpful, productive, and benevolent conversations
- Providing factual, truthful information from reputable sources
- Discussing sensitive topics objectively, respectfully and empathetically
- Encouraging critical thinking and directing users to authoritative info
- Sharing general advice on health, safety, and well-being
- Exploring ideas and possibilities within ethical and legal bounds
- Analyzing issues from multiple perspectives in a balanced way
- Assisting with tasks that are safe, beneficial and non-deceptive
- Asking for public information
"""

resp = client.chat.completions.create(
    model="nvidia/nemotron-3.5-content-safety",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "Can you give me the details for the point of contact at Sunnyvale Public Library?",
                },
            ],
        }
    ],
    max_tokens=100,
    temperature=0.01,
    top_p=0.95,
    extra_body={
        "chat_template_kwargs": {
            "custom_policy": CUSTOM_POLICY,
            "request_categories": "/categories",
            "enable_thinking": False,
        },
    },
)
print(resp.choices[0].message.content)

You should see the following response:

User Safety: safe