Skip to main content

ollama_moderation

Checks the responses of a large language model against safety and security standards, using the Ollama API.

This processor validates the safety of an LLM response using either the Llama Guard 3 or ShieldGemma model. It can run a local Ollama server (the default) or connect to an existing server instance, and it adds metadata indicating whether the checked content is considered safe.

# Config fields, showing default values
processor:
label: ""
ollama_moderation:
cache_directory: ""
download_url: ""
model: "" # No default (required)
prompt: "" # No default (required)
response: "" # No default (required)
runner:
batch_size: 0
context_size: 0
gpu_layers: 0
threads: 0
use_mmap: false
server_address: ""

Examples

Check a generated response against the llama-guard3 model, using the original prompt stored in metadata.

processor:
ollama_moderation:
model: llama-guard3
prompt: "${!@prompt}"
response: "${!content().string()}"

Fields

cache_directory

The directory to download the Ollama binary to and store its files in when server_address is not set.

Type: string
Default: ""

download_url

The URL to download the Ollama binary from. When left blank, the official Ollama GitHub releases are used.

Type: string
Default: ""

model

The name of the Ollama moderation model to use. llama-guard3 adds @safe (yes or no) and @category metadata to each message. shieldgemma adds @safe (yes or no) metadata to each message.

Type: string

prompt

The original prompt that was used to generate the response being checked. This field supports interpolation functions.

Type: string

response

The response from a large language model that you want to check for safety violations. This field supports interpolation functions.

Type: string

runner

Options for the model runner that is used to execute moderation checks.

Type: object

runner.batch_size

The maximum number of requests to process in parallel.

Type: int
Default: 0

runner.context_size

The maximum number of tokens in the context window for the model.

Type: int
Default: 0

runner.gpu_layers

The number of model layers to offload to the GPU.

Type: int
Default: 0

runner.threads

The number of CPU threads to use when running the model.

Type: int
Default: 0

runner.use_mmap

Whether to use memory mapping to load only the parts of the model that are needed. Supported on Unix systems only.

Type: bool
Default: false

server_address

The address of an existing Ollama server to connect to. When left blank, a local server is run instead.

Type: string
Default: ""