Skip to main content
The OpenAI Moderation API helps you detect policy-violating, harmful, or unsafe content in user inputs before sending them to a language model. Integrating this check early in your pipeline ensures compliance, protects end users, and maintains the integrity of your application.

How the Moderation Endpoint Works

When you submit a prompt to the Moderation API, it returns a JSON payload with three primary sections:

Example Request

Example Response

Use the confidence values in category_scores to prioritize human review of borderline cases.

Integrating Moderation into Your Application Workflow

Adopt a secure, four-step flow to vet user inputs before content generation:
  1. Receive the user prompt.
  2. Call the Moderation API.
    • If flagged is true, return an error:
      “Your request violates our content policy and cannot be processed.”
    • If flagged is false, continue.
  3. Invoke the Generation API.
  4. Return the generated response to the end user.
Always enforce the moderation step. Skipping it may expose your system to disallowed or harmful content.

Best Practices

  • Batch multiple inputs in a single moderation request to reduce latency.
  • Monitor and log flagged inputs for auditing and continuous policy tuning.
  • Adjust internal thresholds based on category_scores trends to minimize false positives.

Resources and References

Watch Video