Ruby on Rails Profanity Filter

Moderate content in a Rails controller or model callback using Net::HTTP.

Quick start in Ruby on Rails

require "net/http"

def moderate(text)
  uri = URI("https://api.theprofanityapi.com/v1/check")
  res = Net::HTTP.post(uri,
    { text: text, context: "comment", mode: "balanced" }.to_json,
    "Authorization" => "Bearer #{ENV['PROFANITY_API_KEY']}",
    "Content-Type"  => "application/json")
  JSON.parse(res.body)["flagged"]
end

# before_action or model validation can call moderate(...)

Why context-aware matters

A plain word list flags "this game is sick" or medical text full of anatomical terms. The Profanity API runs a five-layer pipeline that scores intent, so "die" in a gaming taunt and "die" in a real threat are handled differently. Pick a context and the engine adjusts strictness automatically.


Other integrations

Ready to ship moderation?

Get an API key and 300 free requests a month. No credit card required.

Get started free →