Skip to main content
This guide explains how to use TrueFoundry’s built-in Content Moderation guardrail to detect and block harmful content in LLM interactions.
Implementation: This guardrail is powered by the OpenAI Moderation API (omni-moderation-latest) and is fully managed by TrueFoundry — no third-party API keys or setup required. For vendor-hosted moderation using your own credentials (OpenAI, Azure, AWS Bedrock, Google, and others), see TrueFoundry Guardrails and External Providers.Where to add it: attach this guardrail to the LLM Input hook so harmful prompts are blocked before they reach the model.The underlying provider is subject to change without prior notice. TrueFoundry-managed guardrails are currently backed by Azure and OpenAI services.

What is Content Moderation?

Content Moderation is a built-in TrueFoundry guardrail that analyzes text content for harmful material across four safety categories — hate, self-harm, sexual content, and violence. It is powered by the OpenAI Moderation API under the hood: every OpenAI moderation category is grouped under one of the four, and each category is scored between 0 and 1. A category is flagged when its score reaches a threshold: one common threshold for all categories, which you can override per category. The guardrail is fully managed by TrueFoundry — no external credentials or setup required.

Key Features

  1. Four Safety Categories: Detects harmful content across:
    • Hate — Hate speech and discrimination based on identity characteristics, and harassing, bullying, or threatening language aimed at a person
    • SelfHarm — Self-injury, suicide, and instructions or intent to self-harm
    • Sexual — Sexually explicit content, including any involving minors
    • Violence — Violent content, threats, and graphic descriptions, and instructions or advice for wrongdoing
  2. Selective Category Detection: Choose which categories to monitor. Enable all four or only the ones relevant to your application.
  3. Configurable Threshold: Set the score (0–1) at which content is flagged, for all selected categories at once. Defaults to 0.5.
  4. Per-Category Overrides (Advanced): Optionally give individual categories their own threshold, overriding the common one.

Adding Content Moderation Guardrail

1

Navigate to Guardrails

Go to the AI Gateway dashboard and navigate to the Guardrails section.
2

Create or Select a Guardrails Group

Create a new guardrails group or select an existing one where you want to add the Content Moderation guardrail.
3

Add Content Moderation Integration

Click on Add Guardrail and select Content Moderation from the TrueFoundry Guardrails section.
TrueFoundry guardrail selection interface showing Content Moderation option

Select Content Moderation from TrueFoundry Guardrails

4

Configure the Guardrail

Fill in the configuration form:
  • Name: Enter a unique name for this guardrail configuration (e.g., content-moderation)
  • Categories: Select which content categories to check (default: all four)
  • Threshold (optional): Set the score at which a selected category is flagged (default: 0.5)
  • Category Thresholds (Advanced, optional): Override the threshold for individual categories
  • Enforcing Strategy: Choose how violations are handled
5

Save the Configuration

Click Save to add the guardrail to your group.

Configuration Options

Example configuration (Violence is only flagged at 0.8, Hate already at 0.3, every other category at 0.5):
Content Moderation only supports validate mode — it detects and blocks harmful content but does not modify it. See Guardrails Overview for details on Enforcing Strategy.

Categories and Thresholds

Content Categories

Each category groups one or more OpenAI moderation categories, and every OpenAI moderation category belongs to one of them. A category’s score is the highest score among its OpenAI categories.

Thresholds

Each category is scored between 0 (no harmful content) and 1 (clearly harmful). Content is flagged when the score of any selected category meets or exceeds that category’s threshold: its entry in Category Thresholds if there is one, otherwise Threshold.
Start with the default (0.5) and Audit enforcing strategy. Review the scores reported for flagged requests, then adjust Threshold, or override it for the categories that need it.

Migrating from Severity Threshold

Earlier versions of this guardrail used a Severity Threshold on a 0–6 scale. Existing configurations were converted automatically to the equivalent Threshold: A value between two levels converts like the next level up (for example, 3 becomes 0.8). Configurations you apply with tfy apply or the API that still set severity_threshold keep working and are converted the same way, as long as they do not also set threshold. Prefer threshold going forward; severity_threshold is deprecated.

How It Works

The guardrail sends the scanned text (see What Gets Scanned) to the OpenAI Moderation API and receives a score for each category. If the score of any selected category meets or exceeds its threshold, the content is flagged. Example:
When a request is blocked, the error names the flagged categories and their scores, for example Content moderation violation (categories: Violence; scores: Violence: 0.932).

Use Cases

Add Content Moderation on LLM Input.

What Gets Scanned

Content Moderation scans a fixed window, so its cost and latency stay the same however long a conversation gets: Text longer than 2,000 characters is split into pieces of at most 2,000 characters, and every piece is scanned, so the whole text is scored. The highest score per category across all the scanned text decides the verdict.
The x-tfy-guardrails-scope header does not apply to Content Moderation: it always scans the window above. Other guardrails still honour the header.
Rate-limited (429) and unavailable (503) responses are retried up to twice with exponential backoff and jitter.
Content Moderation checks text only. Images and other non-text content are not moderated.

Best Practices

Start with Audit enforcing strategy to monitor what gets flagged before switching to Enforce. This helps you fine-tune category thresholds for your specific content.