<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: CautionLabs</title>
    <description>The latest articles on DEV Community by CautionLabs (@cautionlabs).</description>
    <link>https://dev.to/cautionlabs</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1952817%2F64182704-8a26-466b-85ca-3789a6bde57f.png</url>
      <title>DEV Community: CautionLabs</title>
      <link>https://dev.to/cautionlabs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cautionlabs"/>
    <language>en</language>
    <item>
      <title>PII Detection API: Screening User Text Before You Store It</title>
      <dc:creator>CautionLabs</dc:creator>
      <pubDate>Fri, 13 Nov 2026 09:19:35 +0000</pubDate>
      <link>https://dev.to/cautionlabs/pii-detection-api-screening-user-text-before-you-store-it-567k</link>
      <guid>https://dev.to/cautionlabs/pii-detection-api-screening-user-text-before-you-store-it-567k</guid>
      <description>&lt;p&gt;Most teams never decide to store personal data. It arrives one field at a time: a phone number pasted into a notes box, an address typed into a bio, an order reference dropped into a support form. Six months later you are working out which tables contain data you have to delete on request.&lt;/p&gt;

&lt;p&gt;This article covers one narrow, practical step: screening user-generated text with a &lt;strong&gt;PII detection API&lt;/strong&gt; before you insert it. It is not a replacement for a redaction pipeline or a data-loss-prevention program. It is a gate that sits between the request body and your database, and it returns a boolean.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why PII ends up in your database without anyone noticing
&lt;/h2&gt;

&lt;p&gt;Free-text fields are where personal data hides. Bios, review bodies, comment threads, chat messages, support-ticket descriptions and "anything else we should know?" boxes. Users type phone numbers, home addresses, email addresses, order numbers, dates of birth and account identifiers into all of them, usually without thinking of it as personal data.&lt;/p&gt;

&lt;p&gt;Once a value lands in a row, it is not just in the row. It is in the write-ahead log, the replication stream, the nightly backup, the search index built on top of the table, the log line you emitted with the request body, and the analytics export that runs on Fridays. Retention policies have to cover it. Subject access and deletion requests have to find it. One pasted phone number can turn a routine "delete my account" job into an archaeology project.&lt;/p&gt;

&lt;p&gt;The usual answers are a regex pass over incoming text, a full DLP product, or nothing until an incident. A regex pass works until it doesn't: formats vary, users obfuscate, and numbers show up in contexts you did not anticipate. A model-backed check gives you a second opinion on the same text for the cost of one HTTP call in the request path.&lt;/p&gt;

&lt;p&gt;Get the framing right before you write any code. This is a &lt;strong&gt;pre-persistence screen&lt;/strong&gt;. It reduces how often personal data reaches storage, which reduces how far you have to look when something must be deleted. Redaction — and the decision about what happens to a flagged submission — stays in your code.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the CautionLabs API gives you for PII
&lt;/h2&gt;

&lt;p&gt;CautionLabs exposes a single endpoint, &lt;code&gt;POST /moderation&lt;/code&gt;, on &lt;code&gt;https://api.cautionlabs.com&lt;/code&gt;. You send JSON, you get JSON back, and every category in the response is a boolean.&lt;/p&gt;

&lt;h3&gt;
  
  
  Request: POST /moderation with a single text field
&lt;/h3&gt;

&lt;p&gt;The request body has one required property, &lt;code&gt;text&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"You can reach me on 07700 900123 or at the address in my profile."&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Authentication is a bearer token in the &lt;code&gt;Authorization&lt;/code&gt; header. The key must be a Cloud API key from the dashboard. A private (on-premises) key does not work with the cloud API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Bearer&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;your&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;cloud&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each request covers a text of up to 3,000 characters. Texts of up to 10,000 characters are checked in 3,000-character pieces, one request each.&lt;/p&gt;

&lt;h3&gt;
  
  
  Response: a pii boolean inside categories, plus the overall flagged boolean
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"toxic"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"profanity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"hate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"harassment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"self_harm"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"adult"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"violence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"drugs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"weapons"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"pii"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"spam"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"minor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"flagged"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read it as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;categories.pii&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. There is no number behind it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;flagged&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt; when any category is flagged, so in the shape above it is &lt;code&gt;true&lt;/code&gt; because &lt;code&gt;pii&lt;/code&gt; is.&lt;/li&gt;
&lt;li&gt;All twelve categories follow the same shape: &lt;code&gt;toxic&lt;/code&gt;, &lt;code&gt;profanity&lt;/code&gt;, &lt;code&gt;hate&lt;/code&gt;, &lt;code&gt;harassment&lt;/code&gt;, &lt;code&gt;self_harm&lt;/code&gt;, &lt;code&gt;adult&lt;/code&gt;, &lt;code&gt;violence&lt;/code&gt;, &lt;code&gt;drugs&lt;/code&gt;, &lt;code&gt;weapons&lt;/code&gt;, &lt;code&gt;pii&lt;/code&gt;, &lt;code&gt;spam&lt;/code&gt;, &lt;code&gt;minor&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are no scores, probabilities or confidence values anywhere in the response, and there are no thresholds to tune. That is deliberate, and it is what makes the output directly usable as a control-flow condition: you branch on a boolean.&lt;/p&gt;

&lt;p&gt;Two limits are worth internalising now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The API does not return spans, offsets, matched substrings, entity types, or a masked version of your text.&lt;/li&gt;
&lt;li&gt;The API does not redact anything. Redaction is application code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is also a dedicated category page if you want the product-level view of &lt;a href="https://cautionlabs.com/solutions/pii-detection" rel="noopener noreferrer"&gt;PII detection&lt;/a&gt; alongside the other eleven categories.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wiring a PII check into your write path
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Screening before insert, not after
&lt;/h3&gt;

&lt;p&gt;By the time a row is committed, the text is in the table, the WAL, the replica, the backup, and probably a log line. Screen the text while it is still an in-memory string.&lt;/p&gt;

&lt;p&gt;A Python version using &lt;code&gt;requests&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="no"&gt;MODERATION_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://api.cautionlabs.com/moderation"&lt;/span&gt;
&lt;span class="no"&gt;CLOUD_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"CAUTIONLABS_CLOUD_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;screen_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="no"&gt;MODERATION_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Bearer {CLOUD_KEY}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_comment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;screen_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pii"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"stored"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"reason"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"pii_detected"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;comment_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;insert_comment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"stored"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"comment_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;comment_id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same shape in Node.js with &lt;code&gt;fetch&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MODERATION_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://api.cautionlabs.com/moderation"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;screenText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MODERATION_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`Bearer ${process.env.CAUTIONLABS_CLOUD_KEY}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${error.code}: ${error.message}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createComment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;screenText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pii&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;stored&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"pii_detected"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;commentId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;insertComment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;stored&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;commentId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want the fuller Python walkthrough — client setup, environment handling and a production layout — the &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-python-tutorial" rel="noopener noreferrer"&gt;content moderation API Python tutorial&lt;/a&gt; covers it. For Express middleware and a Node project layout, the &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-nodejs-tutorial" rel="noopener noreferrer"&gt;Node.js moderation tutorial&lt;/a&gt; applies the same step on the JavaScript stack. If you have not integrated the API at all yet, &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-add-text-moderation" rel="noopener noreferrer"&gt;add a content moderation API in an afternoon&lt;/a&gt; is the general overview to read first.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deciding what a pii: true result does to the request
&lt;/h3&gt;

&lt;p&gt;Because the result is a boolean, your policy is deterministic. There is no cutoff to argue about. Three patterns cover most teams:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reject.&lt;/strong&gt; Return an error to the client, keep the text out of the database, and ask the user to remove the personal data. Simplest to reason about, harshest on false positives.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hold for review.&lt;/strong&gt; Write the text to a quarantine table that is excluded from search, analytics and exports, then let a moderator decide. A good middle ground for support tickets and appeals.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Store with a flag.&lt;/strong&gt; Store the row as normal but set a &lt;code&gt;contains_pii&lt;/code&gt; column. Your retention and deletion jobs then have a cheap index to scan, and your analytics export can exclude it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All three keep redaction out of scope. If you want to store a cleaned version of the text, the API does not produce one. You would run your own masking over the raw string after the flag comes back and store the masked result instead of dropping the submission.&lt;/p&gt;

&lt;p&gt;One detail trips people up: &lt;code&gt;flagged&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt; when &lt;em&gt;any&lt;/em&gt; category fires, so a submission with &lt;code&gt;spam: true&lt;/code&gt; and &lt;code&gt;pii: false&lt;/code&gt; still comes back &lt;code&gt;flagged: true&lt;/code&gt;. If the only thing you care about at that call site is personal data, branch on &lt;code&gt;result["categories"]["pii"]&lt;/code&gt; directly. Use &lt;code&gt;flagged&lt;/code&gt; when you want a general "something is wrong here" signal.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a boolean PII flag does not do
&lt;/h2&gt;

&lt;p&gt;Be precise about the boundaries, because they shape your design:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No locations.&lt;/strong&gt; The response does not include spans, offsets or matched substrings. It does not tell you which characters triggered the flag.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No entity types.&lt;/strong&gt; There is no breakdown into names, addresses, phone numbers or anything else. The only thing you get is a category named &lt;code&gt;pii&lt;/code&gt; with a &lt;code&gt;true&lt;/code&gt;/&lt;code&gt;false&lt;/code&gt; value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No redaction or masking.&lt;/strong&gt; The API never returns an edited version of your text. Whatever happens to a flagged submission happens in your code, after the response.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No scores.&lt;/strong&gt; There is no confidence value, so there is no numeric threshold to set. Treat the flag as a signal and layer your own workflow on top: human review, a second check, or a stricter policy for a specific field.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No assumptions about scope.&lt;/strong&gt; The documented contract is a boolean category named &lt;code&gt;pii&lt;/code&gt;. Do not design around guesses about what it catches or misses. Measure it against your own traffic instead.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That last point matters for sizing the trade-off. You are trading recall and precision you cannot see for a decision you can make in one line of code. For a field where any personal data at all is a problem, that trade is usually worth it. For a field where false positives are expensive, route the flag to a human rather than to a hard reject.&lt;/p&gt;

&lt;h2&gt;
  
  
  Combining PII screening with the other eleven categories
&lt;/h2&gt;

&lt;p&gt;One &lt;code&gt;POST /moderation&lt;/code&gt; call returns &lt;code&gt;pii&lt;/code&gt; alongside &lt;code&gt;toxic&lt;/code&gt;, &lt;code&gt;profanity&lt;/code&gt;, &lt;code&gt;hate&lt;/code&gt;, &lt;code&gt;harassment&lt;/code&gt;, &lt;code&gt;self_harm&lt;/code&gt;, &lt;code&gt;adult&lt;/code&gt;, &lt;code&gt;violence&lt;/code&gt;, &lt;code&gt;drugs&lt;/code&gt;, &lt;code&gt;weapons&lt;/code&gt;, &lt;code&gt;spam&lt;/code&gt; and &lt;code&gt;minor&lt;/code&gt;. You do not need to chain separate checks, and one call keeps your latency and your failure handling in one place.&lt;/p&gt;

&lt;p&gt;A small routing function is enough:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Application policy, not an API feature.&lt;/span&gt;
&lt;span class="no"&gt;REJECT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"pii"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"minor"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"self_harm"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;flagged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;flagged&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="no"&gt;REJECT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"reject"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;flagged&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"hold_for_review"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"store"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is nothing to tune here. The set membership test replaces the threshold you would otherwise be debating, and the same function works whether your priority at that call site is personal data, minor safety or spam.&lt;/p&gt;

&lt;p&gt;If the text you are screening is model output rather than user input — a summariser that copies a phone number out of a transcript, for example — the same call applies before you log or display it. &lt;a href="https://cautionlabs.com/blogs/moderate-ai-generated-content-llm-output" rel="noopener noreferrer"&gt;Checking LLM output for unsafe content&lt;/a&gt; covers that adjacent case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling failures and choosing a key type
&lt;/h2&gt;

&lt;p&gt;Failed requests return an error object in this shape:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"unauthorized"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;code&lt;/code&gt; field is one of five documented values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;invalid_request&lt;/code&gt; — the body did not match the schema: a missing &lt;code&gt;text&lt;/code&gt; property, an empty string, or a text outside the schema's length bounds.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;unauthorized&lt;/code&gt; — the key was not accepted.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;insufficient_credits&lt;/code&gt; — the account cannot pay for the request.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;wrong_key_type&lt;/code&gt; — the key you sent is not the right kind for this endpoint. A private (on-premises) key does not work with the cloud API, so use a Cloud API key from the dashboard.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;internal_error&lt;/code&gt; — something failed on our side.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Treat them differently. &lt;code&gt;invalid_request&lt;/code&gt; and &lt;code&gt;wrong_key_type&lt;/code&gt; are deterministic: retrying sends the same bad request again. &lt;code&gt;internal_error&lt;/code&gt; is the one worth a bounded retry. &lt;code&gt;insufficient_credits&lt;/code&gt; is an operational alert, not a user error. The &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-error-codes-production-debugging" rel="noopener noreferrer"&gt;content moderation API error codes&lt;/a&gt; article goes deeper on production debugging for each of them.&lt;/p&gt;

&lt;p&gt;The bigger design question is &lt;strong&gt;fail-open versus fail-closed&lt;/strong&gt;. When the moderation call fails — a timeout, &lt;code&gt;internal_error&lt;/code&gt;, a network blip — do you store the text or not?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fail-closed&lt;/strong&gt; means the submission is not written. For a field where storing personal data is the expensive mistake, this is usually the right default: reject with a retryable error, or write the raw text to a short-lived quarantine store that is excluded from indexes and exports.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fail-open&lt;/strong&gt; means the submission is written and a log entry records that it was unscreened. Reasonable when the cost of blocking legitimate users exceeds the cost of occasionally storing something you will later delete.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Decide per field, not per application. A public comment thread and an internal support ticket do not need the same answer, and the decision should be written down somewhere a reviewer can find it.&lt;/p&gt;

&lt;h2&gt;
  
  
  When PII must never leave your network
&lt;/h2&gt;

&lt;p&gt;Sometimes the answer is that the text cannot be sent to a third party at all. For those cases CautionLabs ships an on-premises option: the model runs on your own infrastructure, and you call a local &lt;code&gt;POST /moderate&lt;/code&gt; endpoint (default &lt;code&gt;http://localhost:8000&lt;/code&gt;) with &lt;code&gt;{"text": "..."}&lt;/code&gt;. The model container makes no outbound requests and has no telemetry, so text stays inside your network. The same boolean flag model applies.&lt;/p&gt;

&lt;p&gt;To decide whether a hosted call is acceptable for your data in the first place, read the &lt;a href="https://cautionlabs.com/blogs/on-premises-vs-cloud-content-moderation" rel="noopener noreferrer"&gt;on-premises vs cloud content moderation&lt;/a&gt; comparison, and the cloud API terms, which state that your text is not stored. If you already know you need the local deployment, &lt;a href="https://cautionlabs.com/blogs/on-premises-content-moderation-docker-deployment" rel="noopener noreferrer"&gt;deploy on-premises content moderation with Docker&lt;/a&gt; walks through the registry login and running the image.&lt;/p&gt;

&lt;p&gt;Both options are described on the &lt;a href="https://cautionlabs.com/pricing" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt;, along with the usage model for each.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Can I get the exact location of the PII in my text?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. The response contains booleans only. There are no spans, offsets, matched substrings or entity types, so the API cannot tell you which characters looked like personal data, nor what kind of data they were. If you need to redact, run your own masking over the text after the flag comes back.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is there a batch endpoint or a webhook?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. There is no batch endpoint and no webhooks. You send one request per text. Each request covers a text of up to 3,000 characters, and texts of up to 10,000 characters are checked in 3,000-character pieces, one request each.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do I need to tune a threshold for PII?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. The API returns true/false flags and an overall &lt;code&gt;flagged&lt;/code&gt; value, with no scores or probabilities. There is nothing to tune. Your policy is a branch on a boolean, which is exactly what makes it easy to unit test.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does the cloud API store my text?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. Per the &lt;a href="https://cautionlabs.com/legal/terms/cloud" rel="noopener noreferrer"&gt;cloud API terms&lt;/a&gt;, your text is not stored.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I use my on-premises key with the cloud API?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. A private (on-premises) key does not work with the cloud API. Use a Cloud API key from the dashboard for &lt;code&gt;https://api.cautionlabs.com&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How many requests does a long submission cost?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each request covers up to 3,000 characters, and texts of up to 10,000 characters are checked in 3,000-character pieces, one request each. See the &lt;a href="https://cautionlabs.com/pricing" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt; for the current rate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add the screen to one write path this week
&lt;/h2&gt;

&lt;p&gt;Start narrow. Pick the single field most likely to collect personal data — the free-text box on your support form is usually the winner — and put the check in front of the insert. Return a clear error or quarantine the row, log the decision, and watch how often &lt;code&gt;pii&lt;/code&gt; fires in real traffic. Once you have a week of data, you can decide whether to widen the policy to comments, bios and chat.&lt;/p&gt;

&lt;p&gt;Try a PII check in the &lt;a href="https://cautionlabs.com/playground" rel="noopener noreferrer"&gt;Playground&lt;/a&gt; with your own sample text, then read the &lt;a href="https://cautionlabs.com/docs" rel="noopener noreferrer"&gt;Cloud API reference&lt;/a&gt; to add &lt;code&gt;POST /moderation&lt;/code&gt; to your write path.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Cover image: Photo by ISMS.Online, CC BY 2.0 · &lt;a href="https://www.flickr.com/photos/194306271@N05/52063700841" rel="noopener noreferrer"&gt;source&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>database</category>
      <category>privacy</category>
      <category>security</category>
    </item>
    <item>
      <title>Content Moderation API Python: Practical Backend Tutorial</title>
      <dc:creator>CautionLabs</dc:creator>
      <pubDate>Fri, 13 Nov 2026 09:18:51 +0000</pubDate>
      <link>https://dev.to/cautionlabs/content-moderation-api-python-practical-backend-tutorial-16j4</link>
      <guid>https://dev.to/cautionlabs/content-moderation-api-python-practical-backend-tutorial-16j4</guid>
      <description>&lt;p&gt;If you run a Python service that accepts user text, you already have the problem. Comments, chat messages, profile bios, support tickets and increasingly LLM output all arrive as strings that need a policy decision attached to them. This tutorial is a hands-on walkthrough of adding a content moderation API Python integration to a service you already ship: one &lt;code&gt;POST&lt;/code&gt; request, a JSON body, and a boolean response you can branch on. No tuning loop, no score calibration, no model hosting.&lt;/p&gt;

&lt;p&gt;Everything below uses the documented cloud API. The base URL is &lt;code&gt;https://api.cautionlabs.com&lt;/code&gt;, the endpoint is &lt;code&gt;POST /moderation&lt;/code&gt;, authentication is a bearer Cloud API key, and the request body has a single required field, &lt;code&gt;text&lt;/code&gt;. If you want the conceptual overview before the Python specifics, &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-add-text-moderation" rel="noopener noreferrer"&gt;adding moderation in an afternoon&lt;/a&gt; covers the shape of the product first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Python teams reach for a moderation API
&lt;/h2&gt;

&lt;p&gt;Moderation rarely shows up as its own project. It shows up as a line item inside a feature you are already building: a comment endpoint that needs to reject a small percentage of submissions, a chat backend that needs to route certain messages to a review queue, an ingestion pipeline that needs to tag documents before indexing, or an LLM wrapper that needs to check model output before it reaches a user.&lt;/p&gt;

&lt;p&gt;The CautionLabs API is deliberately narrow. You send text, you get back a &lt;code&gt;categories&lt;/code&gt; object with twelve boolean keys and an overall &lt;code&gt;flagged&lt;/code&gt; boolean. That is the entire contract. There are no scores, no probabilities, no confidence values to interpret, and no thresholds to tune. That last point matters more than it looks. When a moderation provider returns a float, every team ends up inventing a cutoff, arguing about it in review, and re-tuning it when the distribution shifts. With booleans, the API answers "is this category present in this text?" and the decision about what to &lt;em&gt;do&lt;/em&gt; about it stays in your codebase, where your product context lives.&lt;/p&gt;

&lt;p&gt;That split is the design pattern this tutorial builds around: the API supplies boolean moderation flags from Python, and your application owns the policy that turns those flags into allow, label, review queue or block.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before you write code: base URL, key type and request shape
&lt;/h2&gt;

&lt;p&gt;Three things to get right before the first request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Base URL and endpoint.&lt;/strong&gt; All cloud requests go to &lt;code&gt;https://api.cautionlabs.com&lt;/code&gt;, and the moderation endpoint is &lt;code&gt;POST /moderation&lt;/code&gt;. There is one endpoint. The full contract is in the &lt;a href="https://cautionlabs.com/docs" rel="noopener noreferrer"&gt;Cloud API Reference&lt;/a&gt; and the machine-readable &lt;a href="https://cautionlabs.com/openapi.json" rel="noopener noreferrer"&gt;OpenAPI description&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authentication.&lt;/strong&gt; Send a Cloud API key from the dashboard as a bearer token in the &lt;code&gt;Authorization&lt;/code&gt; header. A private on-premises key does not work with the cloud API, so keep the two credential types separate in your configuration. Read the key from an environment variable, never from a checked-in file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Request body.&lt;/strong&gt; A single required field:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;text&lt;/code&gt; value is a string between 1 and 10,000 characters. An empty string is not a valid request, which is worth handling client-side so you do not spend a round trip on a bug you already know about.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cost shape.&lt;/strong&gt; Cloud usage is billed at $0.40 USD per 1,000 requests, where a request covers up to 3,000 characters and each started 3,000 characters counts as one request. The arithmetic is covered below. There is no batch endpoint, so one text is sent per request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making a content moderation API Python request
&lt;/h2&gt;

&lt;p&gt;The fastest way to see the response shape is a short script. This uses the &lt;code&gt;requests&lt;/code&gt; library, which is already in most Python services, and reads the key from the environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Minimal example with requests
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="no"&gt;API_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://api.cautionlabs.com/moderation"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;moderate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"CAUTIONLABS_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="no"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Bearer {api_key}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;moderate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"This is a test comment that should pass moderation."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"flagged:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"flagged"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;category&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;is_flagged&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"  {category}: {is_flagged}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it with the key exported in your shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;CAUTIONLABS_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"your-cloud-api-key"&lt;/span&gt;
python moderate.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The printout is intentionally boring, and that is the point. You get twelve booleans and an overall &lt;code&gt;flagged&lt;/code&gt; value. Nothing to normalize, nothing to compare against a baseline.&lt;/p&gt;

&lt;p&gt;One practical note: the &lt;code&gt;json=&lt;/code&gt; argument sets the &lt;code&gt;Content-Type&lt;/code&gt; header for you in most cases, but sending it explicitly keeps the request readable and avoids surprises if a proxy in your stack rewrites headers.&lt;/p&gt;

&lt;h3&gt;
  
  
  The same call with httpx for async services
&lt;/h3&gt;

&lt;p&gt;If you are running FastAPI, Starlette or any asyncio-based stack, blocking a worker on a synchronous HTTP call is the wrong shape. &lt;code&gt;httpx&lt;/code&gt; gives you the same request with an async client, and a reusable client avoids a new connection pool per request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;httpx&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ModerationClient&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;10.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"CAUTIONLABS_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;httpx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AsyncClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://api.cautionlabs.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Bearer {api_key}"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;moderate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/moderation"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;aclose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aclose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wire it into the app lifespan so the pool is created once and closed on shutdown:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;contextlib&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asynccontextmanager&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastapi&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;FastAPI&lt;/span&gt;

&lt;span class="n"&gt;moderation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ModerationClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="nd"&gt;@asynccontextmanager&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;lifespan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;FastAPI&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;moderation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aclose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FastAPI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lifespan&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;lifespan&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For FastAPI content moderation inside a route handler, the call is a single await:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pydantic&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Field&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Comment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="nd"&gt;@app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/comments"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_comment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Comment&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;moderation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;moderate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# Your policy decides what happens next; see the next section.&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"flagged"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"flagged"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Pydantic field constraints mirror the documented envelope: at least one character, at most 10,000. Rejecting oversized input before it leaves your process is cheaper than discovering the problem in a response body.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading the response: twelve flags and one overall value
&lt;/h2&gt;

&lt;p&gt;The response has exactly two top-level keys, &lt;code&gt;categories&lt;/code&gt; and &lt;code&gt;flagged&lt;/code&gt;. The &lt;code&gt;categories&lt;/code&gt; object always contains the same twelve boolean keys:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;toxic&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;profanity&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;hate&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;harassment&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;self_harm&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;adult&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;violence&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;drugs&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;weapons&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pii&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;spam&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;minor&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;flagged&lt;/code&gt; boolean is true when any category is flagged. Treat it as a fast path: if &lt;code&gt;flagged&lt;/code&gt; is false you can allow the text without inspecting the categories at all, and only walk the &lt;code&gt;categories&lt;/code&gt; object when it is true.&lt;/p&gt;

&lt;p&gt;A typical flagged response looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"toxic"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"profanity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"hate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"harassment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"self_harm"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"adult"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"violence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"drugs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"weapons"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"pii"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"spam"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"minor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"flagged"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because there is no numeric output, your moderation policy is application code. That is a feature, not a gap. Keep it in exactly one place so that changing what your product blocks does not require hunting through route handlers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="no"&gt;BLOCK&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"hate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"harassment"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"self_harm"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"minor"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"violence"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"weapons"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="no"&gt;REVIEW&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"toxic"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"drugs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"adult"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="no"&gt;LABEL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"profanity"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"spam"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"pii"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;decide_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""Map boolean flags to an application action."""&lt;/span&gt;
    &lt;span class="n"&gt;flagged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;flagged&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="no"&gt;BLOCK&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"block"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;flagged&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="no"&gt;REVIEW&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"review"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;flagged&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="no"&gt;LABEL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"label"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"allow"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those three sets are an example, not a recommendation from the API. The API does not rank categories, weight them or express any opinion about severity. If your product blocks profanity and labels PII, swap the names in the sets and the function keeps working. If you want per-category routing, return the flagged set alongside the action and store both.&lt;/p&gt;

&lt;p&gt;Two habits worth adopting here. First, never log raw text next to a &lt;code&gt;pii&lt;/code&gt; flag; the flag is a signal that the payload may contain exactly the data your log retention policy is trying to avoid. Log a hash, an ID, or the category list instead. Second, persist the action alongside the flags so that when you revisit the policy you can see what the old policy did on real traffic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Long inputs and what they cost
&lt;/h2&gt;

&lt;p&gt;The cloud API checks texts of up to 10,000 characters, and each started 3,000 characters counts as one request. That is the whole cost model, and it is worth doing the arithmetic once so nobody is surprised by a bill.&lt;/p&gt;

&lt;p&gt;Take a 7,000-character document:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Characters 1 to 3,000: one request&lt;/li&gt;
&lt;li&gt;Characters 3,001 to 6,000: one request&lt;/li&gt;
&lt;li&gt;Characters 6,001 to 7,000: one request, because the third 3,000-character window is started even though it is not filled&lt;/li&gt;
&lt;li&gt;Total: 3 requests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At $0.40 USD per 1,000 requests, that document costs $0.0012. Moderate 1,000 documents of that size and you have issued 3,000 requests, which comes to $1.20.&lt;/p&gt;

&lt;p&gt;A text at the 10,000-character ceiling is 4 requests, or $0.0016 per text. A short comment of a few hundred characters is 1 request, or $0.0004. The step function is what matters: costs move in 3,000-character increments, not per character.&lt;/p&gt;

&lt;p&gt;Two engineering consequences. If you are moderating long documents — articles, transcripts, generated reports — the useful slice is usually what the user actually reads first, and choosing that slice is a product decision you make in your own code. And if cost visibility matters, count requests in your own metrics rather than reconstructing them later: increment a counter every time your client issues a call.&lt;/p&gt;

&lt;p&gt;Because there is no batch endpoint, a list of 500 comments is 500 requests. If you are backfilling an archive, that is a job with a size you can calculate in advance, which is exactly what you want before you start it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling errors without guessing
&lt;/h2&gt;

&lt;p&gt;Failures return a JSON body with a &lt;code&gt;code&lt;/code&gt; and a &lt;code&gt;message&lt;/code&gt;. The documented codes are &lt;code&gt;invalid_request&lt;/code&gt;, &lt;code&gt;unauthorized&lt;/code&gt;, &lt;code&gt;insufficient_credits&lt;/code&gt;, &lt;code&gt;wrong_key_type&lt;/code&gt; and &lt;code&gt;internal_error&lt;/code&gt;. Branch on the code rather than trying to infer meaning from a status line, and sort them into two buckets: things you fix by changing configuration, and things you surface to a human.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ConfigurationError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""The request or credentials are wrong; fix the deployment."""&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AccountError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""The account needs attention before requests will succeed."""&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TransientError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""The request may succeed if tried again."""&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;raise_for_moderation_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"invalid_request"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"wrong_key_type"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ConfigurationError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{code}: {message}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"unauthorized"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"insufficient_credits"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;AccountError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{code}: {message}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"internal_error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;TransientError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{code}: {message}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Unexpected moderation error {code}: {message}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;invalid_request&lt;/code&gt; and &lt;code&gt;wrong_key_type&lt;/code&gt; are bugs in your deployment — an empty text field, an oversized payload, or a private on-premises key pointed at the cloud API. They should fail loudly in development, not silently in production. &lt;code&gt;unauthorized&lt;/code&gt; and &lt;code&gt;insufficient_credits&lt;/code&gt; are account-level conditions, so route them somewhere a human will see them. &lt;code&gt;internal_error&lt;/code&gt; is transient, and the decision about how to handle it belongs to your application.&lt;/p&gt;

&lt;p&gt;The dedicated &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-error-codes-production-debugging" rel="noopener noreferrer"&gt;content moderation API error codes&lt;/a&gt; guide goes through each code in depth, including what to check first. Read it before you build out retry or alerting logic so you are branching on documented behaviour rather than guesses.&lt;/p&gt;

&lt;h2&gt;
  
  
  A small, reusable Python moderation client
&lt;/h2&gt;

&lt;p&gt;Route handlers should not know the endpoint URL. Wrap the call once and let the rest of the service depend on the wrapper.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="no"&gt;API_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://api.cautionlabs.com/moderation"&lt;/span&gt;
&lt;span class="no"&gt;MAX_TEXT_LENGTH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10_000&lt;/span&gt;


&lt;span class="nd"&gt;@dataclass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ModerationResult&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;flagged&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;
    &lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;

    &lt;span class="nd"&gt;@property&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;flagged_categories&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ModerationClient&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;10.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"CAUTIONLABS_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;moderate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;ModerationResult&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"text must be a non-empty string"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;MAX_TEXT_LENGTH&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"text exceeds {MAX_TEXT_LENGTH} characters"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="no"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="s2"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Bearer {self._api_key}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_timeout&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nf"&gt;raise_for_moderation_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;ModerationResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;flagged&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"flagged"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Four things this wrapper buys you. It validates the documented envelope before spending a request. It sets a timeout, so a slow network cannot pin a worker indefinitely. It returns a typed result, so callers get attribute access instead of dictionary lookups scattered through the codebase. And it is the single place where credentials, the base URL and error mapping live, which means swapping to the on-premises endpoint later is a one-line change.&lt;/p&gt;

&lt;p&gt;In a Django view the wrapper slots into the existing request flow without restructuring anything:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;JsonResponse&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ModerationClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_comment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;POST&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;moderate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;decide_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"flagged"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flagged&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"block"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;JsonResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"rejected"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;422&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Save the comment, attach the flagged categories as labels,&lt;/span&gt;
    &lt;span class="c1"&gt;# or enqueue it for review depending on the action.&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;JsonResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Can I send a list of texts in one call?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. There is no batch endpoint. One text is sent per request, and the response covers that text only. If you are moderating many items, iterate in your own code and count the requests you issue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does the API return a score I can threshold?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. The response contains twelve boolean category flags and one overall &lt;code&gt;flagged&lt;/code&gt; boolean, which is true when any category is flagged. There are no scores, probabilities or confidence values, and there are no thresholds to tune. Every allow, label, review and block decision is made by your application code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does the API send webhooks?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. It is a synchronous request and response. If your architecture is event-driven, you publish your own event after you receive the response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I run the same booleans on my own network?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes. The on-premises model returns the same flag-based result and is reachable locally at &lt;code&gt;POST /moderate&lt;/code&gt;, defaulting to &lt;code&gt;http://localhost:8000&lt;/code&gt;. It is the right fit for air-gapped environments, strict data-residency requirements, or teams that want inference inside their own perimeter. The &lt;a href="https://cautionlabs.com/blogs/on-premises-content-moderation-docker-deployment" rel="noopener noreferrer"&gt;self-hosted moderation with Docker&lt;/a&gt; guide walks through the deployment, and the &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;On-Premises Guide&lt;/a&gt; has the registry login, requirements and local endpoint details. Remember that a private on-premises key does not work with the cloud API, so keep the two code paths configured separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to go next
&lt;/h2&gt;

&lt;p&gt;Open the &lt;a href="https://cautionlabs.com/playground" rel="noopener noreferrer"&gt;playground&lt;/a&gt; and paste a real comment, a flagged message from your review queue, or a piece of LLM output into the request box. Seeing the twelve booleans come back on text you recognise is the fastest way to calibrate what your policy should do with them. Then create a Cloud API key in the dashboard, drop the wrapper above into your service, and put your policy in one function.&lt;/p&gt;

&lt;p&gt;If you are moderating model output rather than user input, &lt;a href="https://cautionlabs.com/blogs/moderate-ai-generated-content-llm-output" rel="noopener noreferrer"&gt;checking LLM output&lt;/a&gt; covers the patterns that come up in that flow. If your team is polyglot, the &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-nodejs-tutorial" rel="noopener noreferrer"&gt;content moderation API in Node.js&lt;/a&gt; tutorial mirrors this walkthrough for your JavaScript services, so both codebases can share the same policy semantics. And when you are ready to size the rollout, the &lt;a href="https://cautionlabs.com/pricing" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt; lays out the cloud request rate and the on-premises license side by side.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Cover image: Photo by jurvetson, CC BY 2.0 · &lt;a href="https://www.flickr.com/photos/44124348109@N01/51738433963" rel="noopener noreferrer"&gt;source&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>backend</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>On-Premises vs Cloud Content Moderation: A Decision Guide</title>
      <dc:creator>CautionLabs</dc:creator>
      <pubDate>Fri, 13 Nov 2026 09:18:09 +0000</pubDate>
      <link>https://dev.to/cautionlabs/on-premises-vs-cloud-content-moderation-a-decision-guide-1d44</link>
      <guid>https://dev.to/cautionlabs/on-premises-vs-cloud-content-moderation-a-decision-guide-1d44</guid>
      <description>&lt;p&gt;Content moderation is one of those build-versus-buy decisions that looks settled until someone asks where the text actually goes. If you are weighing &lt;strong&gt;on-premises vs cloud content moderation&lt;/strong&gt;, the useful question is not which option is better — it is which set of constraints you can live with. CautionLabs ships the same moderation capability two ways: a hosted REST API, and a model you run on your own infrastructure.&lt;/p&gt;

&lt;p&gt;This guide is for the CTO or platform engineer who has to justify that choice internally, in writing, to people who will ask about data residency, GPU spend, procurement and failure modes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two ways to run the same moderation
&lt;/h2&gt;

&lt;p&gt;CautionLabs offers one moderation capability, delivered as two deployment models.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cloud API.&lt;/strong&gt; A hosted REST endpoint at &lt;code&gt;https://api.cautionlabs.com&lt;/code&gt;. You send a &lt;code&gt;POST /moderation&lt;/code&gt; request authenticated with a Cloud API key from the dashboard using bearer auth, and you get JSON back.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On-premises.&lt;/strong&gt; A model you run inside your own infrastructure as a container. The first model is Argus 1 (model id &lt;code&gt;argus_1&lt;/code&gt;). You call &lt;code&gt;POST /moderate&lt;/code&gt; on your own network.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both return true/false flags across twelve categories — toxic, profanity, hate, harassment, self_harm, adult, violence, drugs, weapons, pii, spam and minor — plus an overall &lt;code&gt;flagged&lt;/code&gt; boolean that is true when any category is flagged.&lt;/p&gt;

&lt;p&gt;There are &lt;strong&gt;no scores, no probabilities and no thresholds to tune&lt;/strong&gt;. That one fact shapes everything below. Whichever deployment you pick, you are building your own policy layer on top of booleans. There is also no batch endpoint, no webhooks and no documented rate limits.&lt;/p&gt;

&lt;p&gt;So the question is not which deployment is "better." It is which one fits your data handling rules, your network topology, your GPU situation and your operations budget.&lt;/p&gt;

&lt;h2&gt;
  
  
  The decision criteria that actually matter
&lt;/h2&gt;

&lt;p&gt;Five questions decide this in practice. Answer them before you compare anything else.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data residency and network isolation
&lt;/h3&gt;

&lt;p&gt;Where is the text processed, and does anything leave your network?&lt;/p&gt;

&lt;p&gt;With the hosted API, text is sent to &lt;code&gt;https://api.cautionlabs.com&lt;/code&gt; over HTTPS. The cloud terms state that your text is not stored. For many teams that is sufficient.&lt;/p&gt;

&lt;p&gt;With the container, the model makes &lt;strong&gt;no outbound requests and has no telemetry&lt;/strong&gt;, and air-gapped installs are supported. If your requirement is "no text leaves the VPC" or "no network egress at all," that is the property that matters. Workloads like &lt;a href="https://cautionlabs.com/blogs/moderate-ai-generated-content-llm-output" rel="noopener noreferrer"&gt;moderating LLM and chatbot output&lt;/a&gt; often force this question early, because both user input and model output can carry regulated data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Operational burden and GPU availability
&lt;/h3&gt;

&lt;p&gt;Who runs the model at 3 a.m.?&lt;/p&gt;

&lt;p&gt;The hosted API removes the question: no GPUs to provision, no image to upgrade, no capacity to plan.&lt;/p&gt;

&lt;p&gt;The on-premises container needs GPU infrastructure you own or rent. The &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;On-Premises Guide&lt;/a&gt; covers requirements and deploying on RunPod and other GPU clouds, using the private key as the registry password. That path is documented and workable — but it is a deployment you operate.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cost shape: per-request vs one-time
&lt;/h3&gt;

&lt;p&gt;The two options bill differently, and the shape matters more than the headline number.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cloud:&lt;/strong&gt; usage-based at $0.40 USD per 1,000 requests. A request covers up to 3,000 characters. Texts of up to 10,000 characters are checked in 3,000-character pieces, one request each.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On-premises:&lt;/strong&gt; a one-time payment of $299 USD per model, with unlimited installs and requests and upgrades to that model included.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One scales with volume. The other is a fixed licence plus whatever the GPU costs you. Neither is automatically cheaper — see the arithmetic below.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scale, latency and upgrade path
&lt;/h3&gt;

&lt;p&gt;The hosted API absorbs traffic variation for you. There is no documented rate limit to design against and no rate-limit headers to read, so treat capacity as something to validate against your own traffic rather than a published ceiling you can plan to.&lt;/p&gt;

&lt;p&gt;On-premises gives you a fixed capacity you choose, and the licence includes upgrades to that model, so new versions are part of the purchase rather than a separate line item.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key and license management
&lt;/h3&gt;

&lt;p&gt;Two credentials, two purposes, one trap.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cloud API keys&lt;/strong&gt; come from the dashboard and authenticate &lt;code&gt;POST /moderation&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Private keys&lt;/strong&gt; are created in the dashboard and used as the password when you log in to the CautionLabs registry to download a model image.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The documented trap: a private (on-premises) key does not work with the cloud API. If your environments mix them up, the failure surfaces as a &lt;code&gt;wrong_key_type&lt;/code&gt; error — details are in the production debugging reference for the &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-error-codes-production-debugging" rel="noopener noreferrer"&gt;wrong_key_type error&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  When the hosted cloud API is the right fit
&lt;/h2&gt;

&lt;p&gt;The hosted API is the right call when text may leave your network for processing and you want moderation running without owning GPU infrastructure. Teams commonly use it to &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-add-text-moderation" rel="noopener noreferrer"&gt;add moderation in an afternoon&lt;/a&gt; instead of a sprint. The &lt;a href="https://cautionlabs.com/docs" rel="noopener noreferrer"&gt;Cloud API reference&lt;/a&gt; documents the full request and response schema, error codes and billing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://api.cautionlabs.com/moderation \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $CAUTIONLABS_CLOUD_API_KEY"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"text": "the text you want to check"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response is the twelve booleans plus the overall flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"toxic"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"profanity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"hate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"harassment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"self_harm"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"adult"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"violence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"drugs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"weapons"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"pii"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"spam"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"minor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"flagged"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cloud is a good fit when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want moderation in production quickly.&lt;/li&gt;
&lt;li&gt;Your terms allow bearer-authenticated HTTPS calls to a vendor endpoint, and the documented "text is not stored" handling satisfies your reviewers.&lt;/li&gt;
&lt;li&gt;Request volume varies and you would rather pay per 1,000 requests than commit to hardware.&lt;/li&gt;
&lt;li&gt;You do not want to own or operate GPU capacity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cloud-side readers evaluating implementation can compare against a concrete &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-nodejs-tutorial" rel="noopener noreferrer"&gt;Node.js integration tutorial&lt;/a&gt;, and the playground runs text through the API in the browser if you want to see the flags before writing any code.&lt;/p&gt;

&lt;h2&gt;
  
  
  When on-premises is the right fit
&lt;/h2&gt;

&lt;p&gt;Four documented steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Buy a model. The first is Argus 1, model id &lt;code&gt;argus_1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create a private key in the dashboard.&lt;/li&gt;
&lt;li&gt;Log in to the CautionLabs registry with that key as the password (&lt;code&gt;docker login registery.cautionlabs.com&lt;/code&gt;), then run the image. The registry checks the license on every download.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;POST /moderate&lt;/code&gt; with &lt;code&gt;{"text": "..."}&lt;/code&gt; on your own network.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://localhost:8000/moderate \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"text": "the text you want to check"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get the same twelve categories and the same overall &lt;code&gt;flagged&lt;/code&gt; boolean.&lt;/p&gt;

&lt;p&gt;On-premises is a good fit when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Text cannot leave your network, or the environment is air-gapped. No outbound requests and no telemetry are exactly what make air-gapped installs possible.&lt;/li&gt;
&lt;li&gt;You already run GPU infrastructure, or you are willing to rent it on RunPod and other GPU clouds with the private key as the registry password.&lt;/li&gt;
&lt;li&gt;You prefer a one-time $299 USD per-model payment with unlimited installs and requests and upgrades to that model included.&lt;/li&gt;
&lt;li&gt;You accept the operational work of running a container — the &lt;a href="https://cautionlabs.com/blogs/on-premises-content-moderation-docker-deployment" rel="noopener noreferrer"&gt;on-premises content moderation Docker deployment guide&lt;/a&gt; walks through the registry login, image run and local request.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Comparing the cost shape, not just the price
&lt;/h2&gt;

&lt;p&gt;The comparison teams get wrong is treating $0.40 per 1,000 requests and $299 as the same kind of number. They are not.&lt;/p&gt;

&lt;p&gt;On the hosted side, cost is a function of request count, and request count is a function of text length. A request covers up to 3,000 characters, and texts of up to 10,000 characters are checked in 3,000-character pieces, one request each. A 10,000-character document is therefore four requests, not one. Chat messages and comments usually sit inside a single piece; long-form documents do not. If your workload is document-heavy, model request volume on characters rather than on "documents."&lt;/p&gt;

&lt;p&gt;On the on-premises side, $299 USD is one-time per model, with unlimited installs and requests and upgrades to that model included. The recurring cost is the GPU you run it on — a cost you can price today and that does not move with request count. Current figures for both options are on the &lt;a href="https://cautionlabs.com/pricing" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Where is the crossover? The documentation does not state a break-even point, and it depends on your infrastructure costs, so run the arithmetic with your own numbers. Two questions do most of the work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How many requests per month do you expect, counting the extra pieces that long texts generate?&lt;/li&gt;
&lt;li&gt;What would the GPU you need cost per month, all in, and who operates it?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If volume is small or unpredictable, per-request pricing is easy to justify because it has no fixed floor. If volume is large, predictable and long-running, a one-time licence plus owned or rented GPU can be simpler to defend in a budget cycle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key types, licensing and the mistakes teams make
&lt;/h2&gt;

&lt;p&gt;Three things to settle before launch:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A private (on-premises) key does not work with the cloud API.&lt;/strong&gt; Keep the two credential types in separate secret stores and name them so nobody has to guess.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The registry checks the license on every download.&lt;/strong&gt; Image pulls are licensed operations rather than anonymous fetches, so account for that in your build and CI pipelines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The on-premises license does not permit distributing the software or its API keys.&lt;/strong&gt; That constrains how you repackage the image into your own artifacts and how you share environments.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are boring details until they are launch blockers. A little naming discipline upstream avoids a confusing auth failure later.&lt;/p&gt;

&lt;h2&gt;
  
  
  What both options deliberately do not do
&lt;/h2&gt;

&lt;p&gt;Whichever model you choose, you are designing around the same boundaries. These are constraints to plan for, not features to configure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No scores, probabilities or confidence values.&lt;/strong&gt; The response is booleans plus an overall flag. Severity ranking, escalation tiers and human-review routing are your policy layer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No thresholds to tune.&lt;/strong&gt; There is no setting that makes moderation stricter or looser, and both deployment models behave the same way in this respect.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No batch endpoint.&lt;/strong&gt; One request carries one text. Queues, fan-out and concurrency are yours to build.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No webhooks.&lt;/strong&gt; There is no callback. You poll or you process synchronously.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No documented rate limits or rate-limit headers.&lt;/strong&gt; There is no published ceiling and no header telling you how close you are to one, so do not design retry and backoff around either.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of this changes between deployment models. Surfacing it in an architecture review is cheaper than discovering it in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Can I start on the cloud API and move on-premises later?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Both deployment models return the same twelve boolean flags and the same overall &lt;code&gt;flagged&lt;/code&gt; value, so the policy layer you write against one response shape applies to the other. The integration surface differs — bearer-authenticated &lt;code&gt;POST /moderation&lt;/code&gt; against &lt;code&gt;https://api.cautionlabs.com&lt;/code&gt; versus &lt;code&gt;POST /moderate&lt;/code&gt; on a host you run — so budget for repointing and revalidating your client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does the on-premises container need internet access?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. The model container makes no outbound requests and has no telemetry, and air-gapped installs are supported. Registry login and image download are the steps that need network access; the running model does not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do I need a GPU?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The container runs on GPU infrastructure, and the &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;On-Premises Guide&lt;/a&gt; covers requirements plus deployment on RunPod and other GPU clouds, where the private key is used as the registry password. If you do not have GPU capacity and do not want to rent it, the hosted API avoids the question entirely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Which key goes where?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cloud API keys from the dashboard authenticate the hosted &lt;code&gt;POST /moderation&lt;/code&gt; endpoint. Private keys are created in the dashboard and used as the password for the CautionLabs registry when downloading an on-premises model. One documented rule to remember: a private (on-premises) key does not work with the cloud API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making the call
&lt;/h2&gt;

&lt;p&gt;Write down the answers to the five criteria — data residency, operational burden, cost shape, scale and upgrade path, key and licence management — and the deployment choice usually makes itself. If text cannot leave your network, on-premises with Argus 1 is the option that satisfies the requirement. If it can, the hosted API removes GPU and operational work from your roadmap.&lt;/p&gt;

&lt;p&gt;Try both paths before you commit. Run text through the playground to see the twelve boolean flags and the overall &lt;code&gt;flagged&lt;/code&gt; value, then review the &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;on-premises guide&lt;/a&gt; and &lt;a href="https://cautionlabs.com/pricing" rel="noopener noreferrer"&gt;pricing&lt;/a&gt; to decide whether the hosted API or a self-hosted Argus 1 model fits your constraints.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Cover image: Photo by kewl, CC BY 2.0 · &lt;a href="https://www.flickr.com/photos/58411470@N00/39044661591" rel="noopener noreferrer"&gt;source&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>architecture</category>
      <category>cloud</category>
      <category>infrastructure</category>
    </item>
    <item>
      <title>Content Moderation API Error Codes: Production Debugging</title>
      <dc:creator>CautionLabs</dc:creator>
      <pubDate>Fri, 13 Nov 2026 09:17:28 +0000</pubDate>
      <link>https://dev.to/cautionlabs/content-moderation-api-error-codes-production-debugging-2nkb</link>
      <guid>https://dev.to/cautionlabs/content-moderation-api-error-codes-production-debugging-2nkb</guid>
      <description>&lt;h2&gt;
  
  
  The Happy Path Is the Easy Part
&lt;/h2&gt;

&lt;p&gt;A successful &lt;code&gt;POST /moderation&lt;/code&gt; call returns exactly two things: a &lt;code&gt;categories&lt;/code&gt; object containing twelve boolean flags (&lt;code&gt;toxic&lt;/code&gt;, &lt;code&gt;profanity&lt;/code&gt;, &lt;code&gt;hate&lt;/code&gt;, &lt;code&gt;harassment&lt;/code&gt;, &lt;code&gt;self_harm&lt;/code&gt;, &lt;code&gt;adult&lt;/code&gt;, &lt;code&gt;violence&lt;/code&gt;, &lt;code&gt;drugs&lt;/code&gt;, &lt;code&gt;weapons&lt;/code&gt;, &lt;code&gt;pii&lt;/code&gt;, &lt;code&gt;spam&lt;/code&gt;, &lt;code&gt;minor&lt;/code&gt;) and a top-level &lt;code&gt;flagged&lt;/code&gt; boolean that is true when any of those twelve is true. There is nothing else in the response — no scores, no probabilities, no confidence values, and no thresholds to tune. If you already have that call returning 200s, you got there somehow; our walkthrough on how to &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-add-text-moderation" rel="noopener noreferrer"&gt;add text moderation in an afternoon&lt;/a&gt; is one route, and this article assumes you have finished it.&lt;/p&gt;

&lt;p&gt;Production integrations rarely break on the response side. The response schema is small and fixed, so parsing it is not usually where your incident comes from. What breaks is the request side: a payload that violates the request schema, a key of the wrong type, an account that has run out of credits, and the occasional server-side failure. Those are four distinct failure classes, and they all arrive through the same small error object.&lt;/p&gt;

&lt;p&gt;The single most useful design decision you can make is to branch on the &lt;code&gt;code&lt;/code&gt; field in the error body rather than on the HTTP status. The status tells you how the transport layer behaved; the &lt;code&gt;code&lt;/code&gt; tells you what your application should do next. Retrying &lt;code&gt;wrong_key_type&lt;/code&gt; will never succeed. Retrying &lt;code&gt;internal_error&lt;/code&gt; sometimes will. Only the code distinguishes them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Error Shape: code and message
&lt;/h2&gt;

&lt;p&gt;Every failed call returns the same error schema, and both fields are required:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;code&lt;/code&gt; — one of five documented values: &lt;code&gt;invalid_request&lt;/code&gt;, &lt;code&gt;unauthorized&lt;/code&gt;, &lt;code&gt;insufficient_credits&lt;/code&gt;, &lt;code&gt;wrong_key_type&lt;/code&gt;, &lt;code&gt;internal_error&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;message&lt;/code&gt; — a human-readable string describing what went wrong.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The endpoint documents these response statuses: &lt;code&gt;200&lt;/code&gt;, &lt;code&gt;400&lt;/code&gt;, &lt;code&gt;401&lt;/code&gt;, &lt;code&gt;402&lt;/code&gt;, &lt;code&gt;403&lt;/code&gt; and &lt;code&gt;500&lt;/code&gt;. The codes and the statuses are documented as separate lists, so treat them as separate lists in your code. Do not build a lookup table that assumes a particular status always carries a particular code. Read &lt;code&gt;code&lt;/code&gt; for application logic, and use the status only for transport-level logging, metrics, and alerting on the shape of your traffic.&lt;/p&gt;

&lt;p&gt;Here is what each error body looks like. The &lt;code&gt;message&lt;/code&gt; values below are illustrative: the schema defines &lt;code&gt;message&lt;/code&gt; as a plain string, so treat it as diagnostic text for humans and never parse it for logic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"invalid_request"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"text is required"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"unauthorized"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"missing or invalid API key"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"insufficient_credits"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"account has no remaining credits"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"wrong_key_type"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"this key cannot be used with the cloud API"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"internal_error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"unexpected error while moderating text"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dispatcher below is the shape I would ship. It is a plain HTTP client — there is no SDK to import — and it makes the retry-versus-fail-fast decision in one place, keyed on &lt;code&gt;code&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// One dispatcher for every documented error code.&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;moderate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"https://api.cautionlabs.com/moderation"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s2"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`Bearer ${process.env.CAUTIONLABS_CLOUD_KEY}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;decision&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"moderated"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flagged&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flagged&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;categories&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"invalid_request"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;// Your payload broke the schema. Fix the caller. Never retry as-is.&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`invalid_request: ${payload.message}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"unauthorized"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"wrong_key_type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;// Configuration problem. Fail fast, alert, do not retry.&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${payload.code}: ${payload.message}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"insufficient_credits"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;// Operational problem. Stop sending and page the account owner.&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`insufficient_credits: ${payload.message}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"internal_error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;// Transient. Retry with bounded backoff.&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;decision&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"retry"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;// Unknown code. Fail fast so new codes are visible rather than silently retried.&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`unhandled moderation error code: ${payload.code}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  invalid_request: Matching the Request Schema Exactly
&lt;/h2&gt;

&lt;p&gt;The request body is a JSON object with a single required property: &lt;code&gt;text&lt;/code&gt;, a string with &lt;code&gt;minLength: 1&lt;/code&gt; and &lt;code&gt;maxLength: 10000&lt;/code&gt;. That is the entire schema. &lt;code&gt;invalid_request&lt;/code&gt; means your body did not satisfy it, and in practice it comes from three places:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Missing or empty text.&lt;/strong&gt; An empty string fails &lt;code&gt;minLength: 1&lt;/code&gt;, and so does a property that was dropped during serialisation because it was &lt;code&gt;undefined&lt;/code&gt; or &lt;code&gt;null&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Text longer than 10,000 characters.&lt;/strong&gt; This fails &lt;code&gt;maxLength&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A body that is not valid JSON, or a missing&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;Content-Type: application/json&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;header.&lt;/strong&gt; If your HTTP client sends a form-encoded body or forgets the content type, the server has nothing it can parse.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The fix belongs in the caller, before the request leaves your process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Trim and normalise.&lt;/strong&gt; Strip leading and trailing whitespace, and collapse the input you actually intend to send. A whitespace-only string should be treated as empty by your own validation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the length on the exact string you are about to serialise.&lt;/strong&gt; Not on the raw user input, and not on some intermediate value that a later transformation changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Short-circuit empty input.&lt;/strong&gt; If a comment or message is empty after trimming, do not send it. There is nothing to moderate, and a request that can only fail is a request you should not pay for.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Handle oversized input explicitly.&lt;/strong&gt; You choose the policy — truncate, split, or reject with your own validation error — but you must choose it before the request goes out.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A useful discipline: log the serialised body length alongside every &lt;code&gt;invalid_request&lt;/code&gt; you see. If the length is 0 or greater than 10,000, you have found the bug without reading a single message string. If the length looks correct, check the header — a client that silently switches content types is the second most common cause.&lt;/p&gt;

&lt;h2&gt;
  
  
  unauthorized and wrong_key_type: Which Key Goes Where
&lt;/h2&gt;

&lt;p&gt;The cloud API authenticates with a bearer cloud API key created in the dashboard, sent as an &lt;code&gt;Authorization: Bearer &amp;lt;key&amp;gt;&lt;/code&gt; header. &lt;code&gt;unauthorized&lt;/code&gt; means the request did not carry a usable cloud key: the header is missing, malformed, or the key is not recognised. &lt;code&gt;wrong_key_type&lt;/code&gt; means the key is real, but it is not the kind of key this endpoint accepts.&lt;/p&gt;

&lt;p&gt;The classic cause of &lt;code&gt;wrong_key_type&lt;/code&gt; is a private, on-premises key being pointed at the cloud API. A private on-premises key does not work with the cloud API. If your service reads a single &lt;code&gt;MODERATION_API_KEY&lt;/code&gt; environment variable and that variable is populated differently in staging and production, this is exactly the error you will get, and it will look mysterious until you check which key the process actually loaded. Our guide to &lt;a href="https://cautionlabs.com/blogs/on-premises-content-moderation-docker-deployment" rel="noopener noreferrer"&gt;on-premises content moderation with Docker&lt;/a&gt; covers the private key and the local endpoint in the context where it belongs.&lt;/p&gt;

&lt;p&gt;Neither of these errors should ever be retried. They are configuration facts, not transient conditions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fail fast.&lt;/strong&gt; Return an error to your caller or route to your fallback policy. Do not loop.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not log the key.&lt;/strong&gt; Log a prefix or an internal identifier, never the full value, and make sure your error handler does not dump request headers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Alert loudly.&lt;/strong&gt; A spike in either code means a deploy, a secret rotation, or an environment mismatch. Every request in that window is failing, which is worth a page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the environment first.&lt;/strong&gt; When you see &lt;code&gt;wrong_key_type&lt;/code&gt; in production, diff the key your process loaded against the key you expect for that environment before you look anywhere else.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  insufficient_credits and How Requests Are Counted
&lt;/h2&gt;

&lt;p&gt;The cloud API is usage-based at $0.40 USD per 1,000 requests. The detail that matters for capacity planning is how a request is counted: each started 3,000-character piece of a request counts as one request. A single request carries text of up to 10,000 characters, so the cost of a call scales with the length of the text you send, not with the number of HTTP calls you make.&lt;/p&gt;

&lt;p&gt;Concretely: a 500-character comment is one request. A 7,500-character document is three requests, because it starts three 3,000-character pieces. A 10,000-character document is four. If your product lets users paste long articles, your request budget is driven by total characters processed, and one HTTP call can consume several requests' worth of credit.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;insufficient_credits&lt;/code&gt; means the account has no remaining credits to pay for the call. It is an operational signal, not a code bug, and it is the one error where your client behaviour can make things worse. What to do instead:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Track characters, not calls.&lt;/strong&gt; Log the character count of every request alongside the response code. That metric predicts credit exhaustion; call counts do not.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Alert on burn rate.&lt;/strong&gt; A daily character total against your remaining balance tells you how many days of runway you have. Alert on the runway, not on the moment the balance reaches zero.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Throttle before you exhaust.&lt;/strong&gt; If a batch job or a backfill is going to consume a large share of your balance, rate-limit it at the application level and keep headroom for interactive traffic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;insufficient_credits&lt;/code&gt;&lt;/strong&gt;&lt;strong&gt;, stop sending.&lt;/strong&gt; Backing off and retrying in a loop does not create credits. Halt the workload, surface the condition to whoever owns the account, and let your fallback policy handle the traffic in the meantime.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Distinguish the two failure shapes.&lt;/strong&gt; A sudden &lt;code&gt;insufficient_credits&lt;/code&gt; on every request usually means the account is out. An occasional one under load usually means two systems are sharing a budget and one of them is winning.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  internal_error: What Your Client Should Do
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;internal_error&lt;/code&gt; means the server accepted the request and something failed while processing it. Your client cannot fix it, and the error carries no information about the text itself. Your job is to contain it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Log&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;code&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;and&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;message&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;together, and never depend on the request body.&lt;/strong&gt; Your logs may redact user text, and they should. If your debugging path requires the original payload, you have built a debugging path that will not exist when you need it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Treat it as transient at the client layer.&lt;/strong&gt; Bounded retries with exponential backoff and jitter are reasonable. Unbounded retries are not — they turn a blip into an outage. The dispatcher above returns a &lt;code&gt;retry&lt;/code&gt; decision for exactly this case and nothing else.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decide your fallback policy in advance.&lt;/strong&gt; Fail open (let the content through), fail closed (block it), or queue it for a human. All three are defensible; picking one at 3 a.m. is not.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not attempt a partial decision.&lt;/strong&gt; The API returns no scores and no confidence values, so there is no partial result to fall back on. If the call fails, you have a result or you do not. Your fallback is a policy decision, not a numeric one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One pattern worth adopting is to make the fallback explicit in your own return type — something like &lt;code&gt;{ decision: "allow" | "block" | "queue", source: "api" | "fallback" }&lt;/code&gt; from your moderation wrapper — so that downstream code cannot accidentally treat a fallback as an API result.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the API Does Not Do (So You Know What You Must Build)
&lt;/h2&gt;

&lt;p&gt;The absences matter as much as the features when you are writing the code around the call:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No batch endpoint.&lt;/strong&gt; There is one endpoint, &lt;code&gt;POST /moderation&lt;/code&gt;, and it takes one text per call. If you have a backlog, you build the fan-out, the concurrency, and the per-call error handling yourself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No webhooks.&lt;/strong&gt; The API does not call you back. Moderation happens inline in your request path, which is the right place for it, but it means your latency budget includes the call and your error handling must be synchronous.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No thresholds.&lt;/strong&gt; Every category is a boolean, and &lt;code&gt;flagged&lt;/code&gt; is true when any of them is true. Mapping those booleans to your own policy actions — warn, hide, block, escalate to review — is entirely your design.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No documented rate limits.&lt;/strong&gt; The documentation does not document rate limits, 429 responses, or &lt;code&gt;X-RateLimit&lt;/code&gt; headers. Do not build client behaviour that assumes any of them exist. Control your own concurrency, and use your own character-count metrics to decide how fast to send.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Confirm your integration handles every documented error code, then run real traffic against the Playground and check the Cloud API Reference before you ship to production. The five codes are a short list, and the switch statement that covers them is shorter.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Which status codes can POST /moderation return?&lt;/strong&gt; The endpoint documents &lt;code&gt;200&lt;/code&gt; for a successful moderation, plus &lt;code&gt;400&lt;/code&gt;, &lt;code&gt;401&lt;/code&gt;, &lt;code&gt;402&lt;/code&gt;, &lt;code&gt;403&lt;/code&gt; and &lt;code&gt;500&lt;/code&gt; for failures. Every failure carries the same error body with a &lt;code&gt;code&lt;/code&gt; and a &lt;code&gt;message&lt;/code&gt;. Branch on &lt;code&gt;code&lt;/code&gt; for application logic and keep the status for transport-level logging and metrics, because the two lists are documented separately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do I tell a bad key from an unauthorised one?&lt;/strong&gt; Read the code. &lt;code&gt;unauthorized&lt;/code&gt; means the request did not carry a usable cloud API key — missing, malformed, or unrecognised. &lt;code&gt;wrong_key_type&lt;/code&gt; means the key is real but is not the type this endpoint accepts, and the classic cause is a private on-premises key pointed at the cloud API. Both are configuration problems: fail fast, alert, and never retry.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How many requests does a long piece of text cost?&lt;/strong&gt; Each started 3,000-character piece of a request counts as one request. A request accepts text of up to 10,000 characters, so a 7,500-character text costs three requests and a 10,000-character text costs four. The cloud API is usage-based at $0.40 USD per 1,000 requests, so track characters rather than calls when you forecast spend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I retry a 500 response?&lt;/strong&gt; Yes, with bounds. &lt;code&gt;internal_error&lt;/code&gt; is the server reporting a failure after accepting the request, so bounded retries with exponential backoff and jitter are reasonable. Decide in advance what happens when those retries are exhausted — fail open, fail closed, or queue for a human — and remember there is no score or confidence value to fall back on, because the API does not return them.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Cover image: Photo by S.C. Air National Guard, Public Domain · &lt;a href="https://www.flickr.com/photos/85045231@N04/54944615864" rel="noopener noreferrer"&gt;source&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>backend</category>
      <category>debugging</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Content Moderation API Node.js: A Practical Tutorial</title>
      <dc:creator>CautionLabs</dc:creator>
      <pubDate>Fri, 13 Nov 2026 09:16:47 +0000</pubDate>
      <link>https://dev.to/cautionlabs/content-moderation-api-nodejs-a-practical-tutorial-3kd8</link>
      <guid>https://dev.to/cautionlabs/content-moderation-api-nodejs-a-practical-tutorial-3kd8</guid>
      <description>&lt;h2&gt;
  
  
  Why Add a Content Moderation API to Node.js Apps
&lt;/h2&gt;

&lt;p&gt;Node.js powers a large share of the products where user-generated text appears first: chat rooms, comment threads, forums, marketplace listings, community feeds, and support inboxes. In nearly all of those systems the critical moment is the same. A string arrives from a user, and your handler has to decide whether it can be saved, published, or broadcast to everyone else.&lt;/p&gt;

&lt;p&gt;Adding a content moderation API to a Node.js service is mostly an HTTP integration problem. You send a text to an endpoint, you get JSON back, and you branch on it. There is no model to host, no word list to curate, and no scoring curve to calibrate.&lt;/p&gt;

&lt;p&gt;CautionLabs keeps that surface small. The hosted API takes a &lt;code&gt;text&lt;/code&gt; string and returns two things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;code&gt;categories&lt;/code&gt; object with twelve boolean flags, one per harm category.&lt;/li&gt;
&lt;li&gt;A single &lt;code&gt;flagged&lt;/code&gt; boolean that is &lt;code&gt;true&lt;/code&gt; when any category is flagged.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is the whole decision surface. The API is binary by design: it returns no scores, no probabilities, and no confidence values, and there are no thresholds to tune. If you have used moderation systems that hand back a float and leave you to pick a cutoff, the difference is worth noticing. With CautionLabs your cutoff logic is simply &lt;code&gt;if (result.flagged)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you want the wider picture of the endpoint and the twelve flags before getting into Node.js specifics, the &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-add-text-moderation" rel="noopener noreferrer"&gt;complete guide to adding a content moderation API&lt;/a&gt; covers the endpoint and flag model in depth. This article concentrates on wiring the check into a Node.js app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where the check belongs in your request lifecycle
&lt;/h3&gt;

&lt;p&gt;Most Node.js teams end up choosing between three placements:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Inline before publish.&lt;/strong&gt; Moderate inside the route handler before the database insert or the socket broadcast. Simple, and the user gets immediate feedback.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Save as pending, moderate, then publish.&lt;/strong&gt; Persist the content in a pending state, moderate it, and flip it live afterwards. This gives you a buffer when something goes wrong downstream.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Asynchronous job.&lt;/strong&gt; Push the text onto a queue, moderate in a worker, and update the record afterwards. Handy for imports and backfills.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The API has no webhooks, so there is no callback to wait for. Your code calls the endpoint directly and reacts to the response in the same flow. That keeps the integration easy to reason about and means your existing queue or job runner is the right place to handle retries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites and Authentication
&lt;/h2&gt;

&lt;p&gt;Before writing code, confirm three things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Node.js runtime with a global &lt;code&gt;fetch&lt;/code&gt; (Node.js 18 and later) or an HTTP client such as &lt;code&gt;axios&lt;/code&gt; or &lt;code&gt;undici&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A Cloud API key, created in the CautionLabs dashboard.&lt;/li&gt;
&lt;li&gt;The base URL, &lt;code&gt;https://api.cautionlabs.com&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Authentication is a bearer token in the &lt;code&gt;Authorization&lt;/code&gt; header. Keep the key in an environment variable rather than in source control.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;CAUTIONLABS_CLOUD_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your_cloud_api_key_here
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Never send the key to the browser or bundle it into client-side code. Moderation calls belong on the server, where the key can stay private and where you control the decision that follows.&lt;/p&gt;

&lt;p&gt;One key detail trips people up early: a private on-premises key does not work with the cloud API. The two deployment paths use different credentials. If you are weighing self-hosting, the &lt;a href="https://cautionlabs.com/blogs/on-premises-content-moderation-docker-deployment" rel="noopener noreferrer"&gt;Docker deployment guide for on-premises content moderation&lt;/a&gt; walks through that route, and the &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;On-Premises Guide&lt;/a&gt; documents the local endpoint and setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Send Your First Node.js Text Moderation API Request
&lt;/h2&gt;

&lt;p&gt;The cloud API exposes one endpoint for text checks: &lt;code&gt;POST /moderation&lt;/code&gt;. The request body is a JSON object with a single required field, &lt;code&gt;text&lt;/code&gt;, which accepts a string of at least 1 character and at most 10,000 characters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MODERATION_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'https://api.cautionlabs.com/moderation'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MODERATION_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'POST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`Bearer ${process.env.CAUTIONLABS_CLOUD_KEY}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'application/json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'You are the worst and everyone here knows it.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flagged&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;// true or false&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// twelve booleans&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A successful response looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"toxic"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"profanity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"hate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"harassment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"self_harm"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"adult"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"violence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"drugs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"weapons"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"pii"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"spam"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"minor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"flagged"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two properties of that payload are worth appreciating. Every field is a boolean, so nothing needs normalising and nothing needs comparing against a constant. And &lt;code&gt;flagged&lt;/code&gt; is a roll-up rather than a separate judgement: it is &lt;code&gt;true&lt;/code&gt; when any category is flagged.&lt;/p&gt;

&lt;p&gt;There is no batch endpoint. Ten texts to check means ten requests. The same holds for a conversation with many messages: each message is its own request. Because there is no webhook either, there is no asynchronous result to reconcile later, because every result arrives in the response to a request you made.&lt;/p&gt;

&lt;h2&gt;
  
  
  Interpret the Boolean Flags
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;categories&lt;/code&gt; object always contains the same twelve keys:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;toxic&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;profanity&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;hate&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;harassment&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;self_harm&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;adult&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;violence&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;drugs&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;weapons&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pii&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;spam&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;minor&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each is either &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. There are no severity levels, no per-category weights, and no numeric values attached to any of them.&lt;/p&gt;

&lt;p&gt;In practice, teams use the flags in three ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Gate on&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;flagged&lt;/code&gt;&lt;/strong&gt;&lt;strong&gt;.&lt;/strong&gt; The simplest policy: allow when &lt;code&gt;flagged&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt;, reject when it is &lt;code&gt;true&lt;/code&gt;. One branch, no configuration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Route on individual categories.&lt;/strong&gt; A comment flagged only under &lt;code&gt;spam&lt;/code&gt; might go to a shadow queue, while one flagged under &lt;code&gt;hate&lt;/code&gt; or &lt;code&gt;harassment&lt;/code&gt; might go straight to human review.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Combine with your own product rules.&lt;/strong&gt; A marketplace might treat &lt;code&gt;pii&lt;/code&gt; differently from a public forum, because the cost of a leaked phone number differs from the cost of a rude reply.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whatever you choose, log the categories you act on. Storing &lt;code&gt;flagged&lt;/code&gt; alone makes it hard to explain later why a specific piece of content was blocked. The per-category overviews under &lt;a href="https://cautionlabs.com/solutions" rel="noopener noreferrer"&gt;Solutions&lt;/a&gt; are a good place to look if you want product context for a specific category before you settle policy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add an Express Content Moderation Middleware Pre-Publish Check
&lt;/h2&gt;

&lt;p&gt;Now for the part most teams actually need: an Express app that moderates a comment before saving it. Start with a small helper that wraps the request and normalises errors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MODERATION_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'https://api.cautionlabs.com/moderation'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;moderateText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MODERATION_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'POST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`Bearer ${process.env.CAUTIONLABS_CLOUD_KEY}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'application/json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s1"&gt;'Moderation request failed'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That helper is reusable anywhere: route handlers, socket event listeners, queue workers. Next, the route handler itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'express'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;REVIEW_CATEGORIES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'hate'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'harassment'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'self_harm'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'minor'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;decide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flagged&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'allow'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;needsHuman&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;REVIEW_CATEGORIES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;needsHuman&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'review'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'block'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/comments'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;moderateText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Decide deliberately: fail closed, fail open, or queue for later.&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'moderation_failed'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'moderation_unavailable'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;decide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'block'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;422&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'comment_rejected'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'review'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;comment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;saveComment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'pending_review'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;202&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'pending_review'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;comment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;saveComment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'published'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;201&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things about that handler are worth calling out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The moderation call happens before the write.&lt;/strong&gt; Nothing reaches the database or the broadcast layer until you have a decision. That is what makes this a pre-publish check rather than a cleanup job.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The decision function is separate from the transport.&lt;/strong&gt; &lt;code&gt;decide()&lt;/code&gt; takes a moderation result and returns a string. That makes it trivial to unit test and easy to change when your policy evolves.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure is explicit.&lt;/strong&gt; When the moderation call throws, you choose what happens. Failing closed keeps unsafe content out but breaks publishing during an outage. Failing open keeps the product usable but lets content through. Many teams compromise: fail closed for chat broadcast, fail open into a pending state for comments.&lt;/p&gt;

&lt;p&gt;For a chat application the same helper runs inside the socket handler, before &lt;code&gt;io.to(room).emit(...)&lt;/code&gt;. The shape is identical: moderate, branch, then publish or hold.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handle Long Text and Request Accounting
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;text&lt;/code&gt; field accepts up to 10,000 characters. For request accounting, each started 3,000-character piece counts as one request. That means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A 1,200-character comment is one request.&lt;/li&gt;
&lt;li&gt;A 3,000-character post is one request.&lt;/li&gt;
&lt;li&gt;A 7,500-character article is three requests.&lt;/li&gt;
&lt;li&gt;A 10,000-character document is four requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you need a rough pre-flight estimate in code, the arithmetic is small:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;PIECE_SIZE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;requestCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="no"&gt;PIECE_SIZE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cloud API usage is billed per request, so this counting rule is the number to plan against rather than raw character volume. Splitting a document yourself does not reduce the count, because a text already counts by started 3,000-character pieces. Send the full text, up to 10,000 characters, in a single call. The &lt;a href="https://cautionlabs.com/pricing" rel="noopener noreferrer"&gt;Pricing&lt;/a&gt; page documents the usage-based request model if you need to size a budget.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handle Errors and Edge Cases
&lt;/h2&gt;

&lt;p&gt;Every failed request returns the same JSON shape, with a &lt;code&gt;code&lt;/code&gt; and a &lt;code&gt;message&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"invalid_request"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"The request body must include a non-empty text field."&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Five documented status codes and five documented error codes cover the failure surface:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;400&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;invalid_request&lt;/code&gt;&lt;/strong&gt; — the body is malformed, &lt;code&gt;text&lt;/code&gt; is missing or empty, or the text exceeds 10,000 characters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;401&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;unauthorized&lt;/code&gt;&lt;/strong&gt; — the &lt;code&gt;Authorization&lt;/code&gt; header is missing or the Cloud API key is not valid.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;402&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;insufficient_credits&lt;/code&gt;&lt;/strong&gt; — the account does not have credits available for the request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;403&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;wrong_key_type&lt;/code&gt;&lt;/strong&gt; — the key is the wrong type for this API. A private on-premises key does not work with the cloud API.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;500&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;internal_error&lt;/code&gt;&lt;/strong&gt; — the request failed on the server side. Retry with backoff.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A compact handler keeps the mapping readable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s1"&gt;'invalid_request'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'bad_input'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s1"&gt;'unauthorized'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'server_misconfigured'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s1"&gt;'insufficient_credits'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'moderation_unavailable'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s1"&gt;'wrong_key_type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'server_misconfigured'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s1"&gt;'internal_error'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'moderation_unavailable'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'moderation_unavailable'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how 401 and 403 are mapped to a 500 for your own clients. Those are configuration problems on your side, not something the end user did, so surfacing them verbatim would be misleading.&lt;/p&gt;

&lt;p&gt;The API reference does not document rate limits, does not document &lt;code&gt;429&lt;/code&gt; responses, and does not document &lt;code&gt;X-RateLimit&lt;/code&gt; headers. Do not build throttling logic that assumes any of them. What you should build is bounded retry with exponential backoff for &lt;code&gt;internal_error&lt;/code&gt;, plus a circuit breaker so a stretch of 500s does not stall every publish in your app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test Before Production
&lt;/h2&gt;

&lt;p&gt;The fastest way to confirm request and response shapes is the &lt;a href="https://cautionlabs.com/playground" rel="noopener noreferrer"&gt;Playground&lt;/a&gt;, which runs the moderation API in the browser. Paste a few representative strings — clean, borderline, obvious violation — and check which categories come back &lt;code&gt;true&lt;/code&gt;. It is a good way to sanity check your policy before you commit to it in code.&lt;/p&gt;

&lt;p&gt;For unit tests, mock the boolean response rather than calling the live API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;mockResult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;overrides&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;toxic&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;profanity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;harassment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;self_harm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;adult&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;violence&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;drugs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;weapons&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pii&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;spam&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;flagged&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;overrides&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With a factory like that you can cover every branch in &lt;code&gt;decide()&lt;/code&gt;: allow, block, review, and the error path where &lt;code&gt;moderateText&lt;/code&gt; throws. Log the outcome of each decision — the &lt;code&gt;flagged&lt;/code&gt; value, the &lt;code&gt;code&lt;/code&gt; on failures, and your own decision string. Because the API returns only booleans, there is nothing else to log and no score to chart.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Questions About the CautionLabs Node.js Integration
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Does the API return confidence scores?
&lt;/h3&gt;

&lt;p&gt;No. The response contains twelve boolean category flags and a single &lt;code&gt;flagged&lt;/code&gt; boolean. There are no scores, probabilities, or confidence values in the payload, and there are no thresholds to tune on your side. Your policy lives entirely in how you branch on &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I batch multiple texts in one request?
&lt;/h3&gt;

&lt;p&gt;No. There is no batch endpoint. Each request accepts one &lt;code&gt;text&lt;/code&gt; string, so moderating a hundred messages means a hundred requests. If you need throughput, run requests concurrently from your own worker pool — the API itself has no batching mode.&lt;/p&gt;

&lt;h3&gt;
  
  
  What happens with text longer than 3,000 characters?
&lt;/h3&gt;

&lt;p&gt;Text can be up to 10,000 characters, and each started 3,000-character piece counts as one request. A 10,000-character text therefore accounts for four requests. There is no separate long-text endpoint: you send the text, and the request count follows the documented piece rule.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does the cloud API accept private on-premises keys?
&lt;/h3&gt;

&lt;p&gt;No. A private on-premises key does not work with the cloud API. The cloud API authenticates with a Cloud API key from the dashboard, sent as a bearer token. If a request comes back with &lt;code&gt;wrong_key_type&lt;/code&gt;, that mismatch is usually why.&lt;/p&gt;

&lt;h3&gt;
  
  
  Are rate limits documented?
&lt;/h3&gt;

&lt;p&gt;No documented rate limits, no documented &lt;code&gt;429&lt;/code&gt; responses, and no documented &lt;code&gt;X-RateLimit&lt;/code&gt; headers. Plan your integration around the documented status codes, add backoff for &lt;code&gt;internal_error&lt;/code&gt;, and decide in advance whether your app fails open, fails closed, or queues when moderation is unavailable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;You now have everything needed to moderate user-generated content in Node.js: a bearer-authenticated &lt;code&gt;POST /moderation&lt;/code&gt; call, a &lt;code&gt;text&lt;/code&gt; field capped at 10,000 characters, twelve boolean category flags, and an overall &lt;code&gt;flagged&lt;/code&gt; value to branch on.&lt;/p&gt;

&lt;p&gt;A sensible order of work from here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Try the request in the &lt;a href="https://cautionlabs.com/playground" rel="noopener noreferrer"&gt;Playground&lt;/a&gt; with a handful of real strings from your product.&lt;/li&gt;
&lt;li&gt;Confirm authentication and response fields against the &lt;a href="https://cautionlabs.com/docs" rel="noopener noreferrer"&gt;Cloud API Reference&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Add the &lt;code&gt;moderateText&lt;/code&gt; helper to your codebase and call it from one route.&lt;/li&gt;
&lt;li&gt;Write the &lt;code&gt;decide()&lt;/code&gt; function with your own policy, then unit test each branch.&lt;/li&gt;
&lt;li&gt;Expand to chat broadcasts, queue workers, and edits once the first path is stable.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If your requirements point towards running the model on your own infrastructure instead, the &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;On-Premises Guide&lt;/a&gt; covers the documented setup. And if you want the conceptual overview of the endpoint and the twelve flags again before you ship, the &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-add-text-moderation" rel="noopener noreferrer"&gt;complete guide to adding a content moderation API&lt;/a&gt; is the companion read.&lt;/p&gt;

&lt;p&gt;Ready to see the response for yourself? Head to the &lt;a href="https://cautionlabs.com/playground" rel="noopener noreferrer"&gt;Playground&lt;/a&gt; and run a request, then use the &lt;a href="https://cautionlabs.com/docs" rel="noopener noreferrer"&gt;Cloud API Reference&lt;/a&gt; to lock down authentication and response fields before the check goes anywhere near production.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Cover image: Photo by jurvetson, CC BY 2.0 · &lt;a href="https://www.flickr.com/photos/44124348109@N01/51738433963" rel="noopener noreferrer"&gt;source&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>javascript</category>
      <category>node</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Moderate AI-Generated Content: Checking LLM Output</title>
      <dc:creator>CautionLabs</dc:creator>
      <pubDate>Fri, 13 Nov 2026 09:16:06 +0000</pubDate>
      <link>https://dev.to/cautionlabs/moderate-ai-generated-content-checking-llm-output-3j8f</link>
      <guid>https://dev.to/cautionlabs/moderate-ai-generated-content-checking-llm-output-3j8f</guid>
      <description>&lt;p&gt;You ship a chatbot, a copilot, or an agent that writes text straight into a product surface. The model's reply is untrusted text. It reaches a user's screen and nobody reads it first.&lt;/p&gt;

&lt;p&gt;You can moderate AI-generated content the same way you moderate user posts: send the text to &lt;code&gt;POST /moderation&lt;/code&gt;, get JSON back, and decide what the product does next. The response contains twelve boolean category flags and one overall &lt;code&gt;flagged&lt;/code&gt; value. That is the whole contract.&lt;/p&gt;

&lt;p&gt;What the response does not contain matters just as much. There are no scores, no probabilities and no confidence values. There are no thresholds to tune. Every policy decision — block, regenerate, route to review, log — lives in your application as ordinary code. That moves LLM output moderation from a calibration project into a routing problem, which is a much easier thing to review, test and explain to the rest of the company.&lt;/p&gt;

&lt;p&gt;If you have not wired up &lt;code&gt;POST /moderation&lt;/code&gt; yet, start with &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-add-text-moderation" rel="noopener noreferrer"&gt;add a content moderation API in an afternoon&lt;/a&gt; for the endpoint, authentication and request schema, then come back here to design the policy layer on top of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why model output needs the same check as user content
&lt;/h2&gt;

&lt;p&gt;A generated reply is text. It can carry the same kinds of harm as anything a user types: toxicity, hate, harassment, self-harm, adult content, violence, drugs, weapons, PII, spam, minor safety and profanity. A model that has been aligned to avoid these topics still produces them sometimes, and a model that has not been aligned produces them whenever the prompt nudges it.&lt;/p&gt;

&lt;p&gt;In a chat product, both directions matter. The user's prompt and the assistant's reply are both strings you can send to the same endpoint. You do not need a second vendor, a second SDK or a second contract for the outbound side.&lt;/p&gt;

&lt;p&gt;The integration shape is deliberately small. It is a text-in, JSON-out HTTP call. If your stack can make a request to &lt;code&gt;https://api.cautionlabs.com/moderation&lt;/code&gt;, it can moderate a model reply — Node, Python, Go, a Lambda, a queue worker, whatever already sits between your model call and your client.&lt;/p&gt;

&lt;p&gt;One constraint shapes the design: every check is its own request. The API documents no batch endpoint and no webhooks, and no rate-limit headers to plan around. You call it inline, or you call it from a worker that already has the text in hand. Plan for one request per check and the rest of the architecture stays simple.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the moderation call goes in an AI request path
&lt;/h2&gt;

&lt;p&gt;A chat turn has two text boundaries worth guarding. They use the same endpoint but different policy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Checking the incoming prompt
&lt;/h3&gt;

&lt;p&gt;The prompt is the cheapest place to stop a bad turn. Screen the user's text before it reaches the model, and you avoid paying for a generation that you would only throw away.&lt;/p&gt;

&lt;p&gt;For most products the prompt check can be lighter than the reply check. A prompt that trips &lt;code&gt;spam&lt;/code&gt; or &lt;code&gt;profanity&lt;/code&gt; might be a warning; a prompt that trips &lt;code&gt;self_harm&lt;/code&gt; might route to a different response path entirely. Those are your decisions. The API returns the flags and nothing else.&lt;/p&gt;

&lt;h3&gt;
  
  
  Checking the generated reply before it renders
&lt;/h3&gt;

&lt;p&gt;The reply check is the one that protects the user. Send the assembled reply text before it is written to the thread, rendered in the UI, or emitted over your streaming channel.&lt;/p&gt;

&lt;p&gt;Here is the call in full. One header, one field:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST https://api.cautionlabs.com/moderation \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $CAUTIONLABS_API_KEY"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"text": "Here is the reply the model just generated."}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the shape of what comes back:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"toxic"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"profanity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"hate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"harassment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"self_harm"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"adult"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"violence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"drugs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"weapons"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"pii"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"spam"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"minor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"flagged"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the application branch. This snippet checks the reply, gates rendering on &lt;code&gt;flagged&lt;/code&gt;, and maps each category to an action your team chose. The comment on the policy object is the point of the whole article:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The API reports flags. Everything below is your application's decision.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;POLICY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'hate'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'harassment'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'self_harm'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'adult'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'minor'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;review&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'toxic'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'violence'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'drugs'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'weapons'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'pii'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'profanity'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'spam'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;checkReply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;replyText&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://api.cautionlabs.com/moderation'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'POST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`Bearer ${process.env.CAUTIONLABS_API_KEY}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'application/json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;replyText&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Your application picks the fallback: hold the reply, show a generic&lt;/span&gt;
    &lt;span class="c1"&gt;// message, or surface the failure. The API does not decide this.&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'hold'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'moderation_call_failed'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flagged&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;flagged&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'send'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;matching&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;blocked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;matching&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;POLICY&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blocked&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'replace_with_fallback'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;blocked&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;reviewed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;matching&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;POLICY&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;review&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reviewed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'queue_for_review'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;reviewed&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'send_and_log'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;matching&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;POLICY&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Call it between generation and rendering:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;checkReply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;completion&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'send'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'send_and_log'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;completion&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;renderFallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// your product's fallback path&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note what the code does not do. It does not compare a number against a cutoff, because there is no number. It reads booleans and runs a switch.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the response actually contains
&lt;/h2&gt;

&lt;p&gt;The response object has exactly two required fields: &lt;code&gt;categories&lt;/code&gt; and &lt;code&gt;flagged&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Twelve category booleans
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;categories&lt;/code&gt; is an object with twelve required boolean properties, named exactly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;toxic&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;profanity&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;hate&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;harassment&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;self_harm&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;adult&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;violence&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;drugs&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;weapons&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pii&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;spam&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;minor&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each is &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. There is nothing else in the object — no per-category score, no explanation string, no span offsets.&lt;/p&gt;

&lt;p&gt;That list is fixed. There are no extra categories to enable and no custom categories to define. Your policy layer maps each documented name to an action and leaves the rest alone.&lt;/p&gt;

&lt;h3&gt;
  
  
  The overall flagged value
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;flagged&lt;/code&gt; is a boolean that is &lt;code&gt;true&lt;/code&gt; when any category is flagged. It is the single value you branch on when you want one simple gate in front of rendering.&lt;/p&gt;

&lt;p&gt;Two uses, in practice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Gate on&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;flagged&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;first.&lt;/strong&gt; If it is &lt;code&gt;false&lt;/code&gt;, send the reply. This is the fast path and it covers the overwhelming majority of generations in a healthy product.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;categories&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;second.&lt;/strong&gt; Once &lt;code&gt;flagged&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;, the individual booleans tell you which rule fired, and that determines whether you block, rewrite, regenerate or queue for review.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Neither value tells you how confident the model was. There is no score, no probability distribution and no confidence number anywhere in the response. That is why there is nothing to tune: no cutoff to move up or down when reviewers complain, no calibration job, no per-locale threshold drift. You change behavior by changing code, and the change shows up in a diff review like any other.&lt;/p&gt;

&lt;h2&gt;
  
  
  Designing behavior around boolean flags
&lt;/h2&gt;

&lt;p&gt;Because the output is binary, all of the judgment sits in your application. That is more work than flipping a threshold and less work than maintaining one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Per-category handling
&lt;/h3&gt;

&lt;p&gt;A single blanket action for every flag is easy to write and hard to defend. Users notice when a harmless profanity flag triggers the same response as a harassment flag.&lt;/p&gt;

&lt;p&gt;Map categories to actions instead. A reasonable starting split:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Block and replace.&lt;/strong&gt; Categories where the product should never display the text at all. Swap in a canned fallback or attempt a safe regeneration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hold for review.&lt;/strong&gt; Categories where a human should look before the reply goes out or before the conversation continues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Send and log.&lt;/strong&gt; Categories where display is acceptable but the event should land in your trust-and-safety pipeline for trend analysis.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ignore.&lt;/strong&gt; Some flags may be acceptable on some surfaces — a &lt;code&gt;weapons&lt;/code&gt; flag is noise in a cookbook assistant and serious in a teen-facing chat product. Decide this per product, not per company.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Write the mapping down as a constant, as in the snippet above. It becomes the artifact your trust-and-safety reviewers, legal team and support leads can all argue about, which is exactly where that argument should happen.&lt;/p&gt;

&lt;h3&gt;
  
  
  When to log, review or regenerate
&lt;/h3&gt;

&lt;p&gt;A few patterns that hold up in production AI chatbot content moderation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Regenerate once, then fall back.&lt;/strong&gt; If &lt;code&gt;flagged&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;, retry the generation with a stricter system prompt or different sampling settings, then check again. If the second attempt is also flagged, show the fallback. Two calls on a bad turn is a cheap price for a reply the user actually wants.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Log the flags, not the text, when you can.&lt;/strong&gt; The &lt;code&gt;categories&lt;/code&gt; object is enough to build dashboards and alerts without keeping prompt or reply content around.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never let a flag silently vanish.&lt;/strong&gt; Every &lt;code&gt;true&lt;/code&gt; should produce a log line, a counter increment, or an action. Flags that are returned and discarded are worse than no check, because they create the appearance of coverage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the fallback human.&lt;/strong&gt; A blocked reply should read as a product decision, not an error. "I can't help with that — here's what I can do instead" beats a red banner.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The API itself does none of this. It returns flags. Your code decides.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to moderate AI-generated content across long prompts and replies
&lt;/h2&gt;

&lt;p&gt;Length is where request accounting gets real, so here is the documented behavior in full.&lt;/p&gt;

&lt;p&gt;A request covers up to 3,000 characters. Texts of up to 10,000 characters are checked in 3,000-character pieces, one request each, and each started piece counts as one request.&lt;/p&gt;

&lt;p&gt;Two practical consequences for AI pipelines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Assemble or truncate streaming output before you send it.&lt;/strong&gt; A token stream is not a request body. Buffer the reply until it is complete, or cut it at a known boundary, then moderate the resulting string. Checking half a sentence and then appending more text to the screen defeats the purpose.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Budget by piece, not by turn.&lt;/strong&gt; A long, document-grounded reply may span several pieces. Cloud usage is $0.40 USD per 1,000 requests, so piece count is the number that matters in your cost model, not conversation count.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can see the current usage numbers on the &lt;a href="https://cautionlabs.com/pricing" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Privacy: cloud API versus on-premises for AI pipelines
&lt;/h2&gt;

&lt;p&gt;Model output can contain whatever the user just pasted in — support tickets, medical questions, internal documents. Where the moderation call runs is a privacy decision, not just an infrastructure one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cloud API
&lt;/h3&gt;

&lt;p&gt;The cloud API is a hosted service at &lt;code&gt;https://api.cautionlabs.com&lt;/code&gt;, authenticated with a Cloud Key. Per the cloud terms, your text is not stored by the hosted API. The &lt;a href="https://cautionlabs.com/docs" rel="noopener noreferrer"&gt;API reference&lt;/a&gt; documents authentication, the request and response schema, and the error codes.&lt;/p&gt;

&lt;h3&gt;
  
  
  On-premises model
&lt;/h3&gt;

&lt;p&gt;Some teams cannot send prompts or model output to a hosted service at all. For those, the same model runs in a container on your own infrastructure. The container makes no outbound requests and has no telemetry. You call it at &lt;code&gt;POST /moderate&lt;/code&gt; on your own network, default &lt;code&gt;http://localhost:8000&lt;/code&gt;, with the same &lt;code&gt;{"text": "..."}&lt;/code&gt; body.&lt;/p&gt;

&lt;p&gt;A private (on-premises) key does not work with the cloud API. Keep the two key types separate in your configuration and your secret stores so nobody swaps them by accident.&lt;/p&gt;

&lt;p&gt;On-premises is a one-time payment of $299 USD per model, with unlimited installs and requests for that model. The first model is Argus 1. If you want the container running before you refactor your pipeline, &lt;a href="https://cautionlabs.com/blogs/on-premises-content-moderation-docker-deployment" rel="noopener noreferrer"&gt;deploy on-premises content moderation with Docker&lt;/a&gt; walks through the registry login, the image and the local endpoint. The &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;on-premises guide&lt;/a&gt; covers requirements, GPU cloud deployment and air-gapped installs.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Does the API return confidence scores?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. The response contains twelve boolean category flags and one overall &lt;code&gt;flagged&lt;/code&gt; boolean. There are no scores, probabilities or confidence values, and therefore no thresholds to tune.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I send a batch of replies in one call?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. There is no batch endpoint. Each text is its own &lt;code&gt;POST /moderation&lt;/code&gt; request, and in a chat application the prompt and the reply are two separate calls.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does it detect personal data?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pii&lt;/code&gt; is one of the twelve documented category flags, and it returns &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; like the others. The response does not return matched spans or the kind of data found, so your application decides what to do when it is &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do I need a separate call for the prompt and the reply?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes. They are two distinct texts and each is its own request. You can apply different policy to each, which is usually what you want: user input and model output carry different risk.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens to text longer than one piece?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Texts of up to 10,000 characters are checked in 3,000-character pieces, one request each, and each started piece counts as one request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add the check to your response path
&lt;/h2&gt;

&lt;p&gt;The smallest useful implementation is three things: one call on the assistant's reply, one branch on &lt;code&gt;flagged&lt;/code&gt;, and one policy rule for each of the twelve categories. That is enough to stop the reply you would be embarrassed to ship, and it leaves a clear place to add prompt-side checks, regeneration and review queues later.&lt;/p&gt;

&lt;p&gt;Start in the &lt;a href="https://cautionlabs.com/docs" rel="noopener noreferrer"&gt;API reference&lt;/a&gt; for authentication and the full schema, try a sample in the &lt;a href="https://cautionlabs.com/playground" rel="noopener noreferrer"&gt;playground&lt;/a&gt;, and read the &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;on-premises guide&lt;/a&gt; if your data cannot leave your network.&lt;/p&gt;

&lt;p&gt;Then send your assistant's next reply to &lt;code&gt;POST /moderation&lt;/code&gt;, branch on the overall &lt;code&gt;flagged&lt;/code&gt; value, and map one policy rule to each of the twelve category flags. The flags are the API's job. The judgment is yours.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Cover image: Photo by jurvetson, CC BY 2.0 · &lt;a href="https://www.flickr.com/photos/44124348109@N01/51738433963" rel="noopener noreferrer"&gt;source&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>On-Premises Content Moderation: Deploy with Docker</title>
      <dc:creator>CautionLabs</dc:creator>
      <pubDate>Fri, 13 Nov 2026 09:15:25 +0000</pubDate>
      <link>https://dev.to/cautionlabs/on-premises-content-moderation-deploy-with-docker-1epb</link>
      <guid>https://dev.to/cautionlabs/on-premises-content-moderation-deploy-with-docker-1epb</guid>
      <description>&lt;p&gt;On-premises content moderation means the model runs inside your own network. Your text goes in over HTTP and the result comes back as JSON, and nothing about that request leaves the perimeter you control. CautionLabs ships this as a Docker image you run yourself, licensed per model, with unlimited installs and requests once you own it.&lt;/p&gt;

&lt;p&gt;This guide is for backend and platform engineers, and for CTOs, who cannot send user text to a third-party service — health, finance, government, defence, or any team with data-residency or air-gap constraints. It walks through the four documented steps in order, shows the local request and response, and covers GPU-cloud and air-gapped deployments. If you have not decided yet whether to self-host, the hosted path is described in the &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-add-text-moderation" rel="noopener noreferrer"&gt;content moderation API&lt;/a&gt; quickstart, and the trade-off is summarised near the end of this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Teams Run Content Moderation On Their Own Infrastructure
&lt;/h2&gt;

&lt;p&gt;There are two structural reasons to self-host rather than call a hosted endpoint: where the data is allowed to go, and what you pay per request.&lt;/p&gt;

&lt;h3&gt;
  
  
  When a hosted API is not an option
&lt;/h3&gt;

&lt;p&gt;Data-residency rules, privacy commitments and air-gapped networks all point the same way. If your corpus is regulated, if contractual terms forbid sending user text to a third party, or if the network has no route to the public internet at all, a hosted endpoint is off the table regardless of how good it is. In those environments the moderation model has to be a component you deploy, version and operate like the rest of your stack.&lt;/p&gt;

&lt;h3&gt;
  
  
  No outbound requests, no telemetry
&lt;/h3&gt;

&lt;p&gt;The model container makes no outbound requests and has no telemetry. That property is what makes an air-gapped install possible: the image can be pulled and run in a network with no egress, because there is nothing for it to call home to. It also means there is no per-request network hop, no third-party retention question, and no external dependency in your request path.&lt;/p&gt;

&lt;p&gt;The commercial difference is equally concrete. The hosted API is usage-based, while an on-premises licence is a one-time payment per model with unlimited installs and requests. Once you own the model, request volume stops being a line item.&lt;/p&gt;

&lt;h2&gt;
  
  
  What You Get: Argus 1 and the Local On-Premises Content Moderation Endpoint
&lt;/h2&gt;

&lt;p&gt;Argus 1 is the first on-premises text moderation model, with model id &lt;code&gt;argus_1&lt;/code&gt;. It runs as a container that exposes an HTTP API on your own network. The default address is &lt;code&gt;http://localhost:8000&lt;/code&gt;, and the endpoint you call is &lt;code&gt;POST /moderate&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The same twelve boolean categories
&lt;/h3&gt;

&lt;p&gt;The response returns a &lt;code&gt;categories&lt;/code&gt; object containing a true/false flag for each of twelve categories — &lt;code&gt;toxic&lt;/code&gt;, &lt;code&gt;profanity&lt;/code&gt;, &lt;code&gt;hate&lt;/code&gt;, &lt;code&gt;harassment&lt;/code&gt;, &lt;code&gt;self_harm&lt;/code&gt;, &lt;code&gt;adult&lt;/code&gt;, &lt;code&gt;violence&lt;/code&gt;, &lt;code&gt;drugs&lt;/code&gt;, &lt;code&gt;weapons&lt;/code&gt;, &lt;code&gt;pii&lt;/code&gt;, &lt;code&gt;spam&lt;/code&gt; and &lt;code&gt;minor&lt;/code&gt; — plus an overall &lt;code&gt;flagged&lt;/code&gt; boolean that is true when any category is flagged.&lt;/p&gt;

&lt;p&gt;There are no scores, probabilities or confidence values returned, and there are no thresholds to tune. The decision is the flag. This is deliberate: you are not calibrating a cut-off, you are reading a verdict.&lt;/p&gt;

&lt;h3&gt;
  
  
  JSON in, JSON out
&lt;/h3&gt;

&lt;p&gt;The request body is JSON with a single &lt;code&gt;text&lt;/code&gt; field. The response is JSON. There is no batch endpoint and the API sends no webhooks, so the integration pattern is one request per text, with your own code deciding what to do with the result.&lt;/p&gt;

&lt;p&gt;The response shape matches the hosted cloud API, so client code that already parses a cloud moderation response can be pointed at the local endpoint and reused. That matters if you run a hybrid setup or if you migrate in either direction later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites Before You Deploy
&lt;/h2&gt;

&lt;p&gt;Three things are required before the container will run:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A purchased on-premises model licence.&lt;/li&gt;
&lt;li&gt;A private key created in the dashboard.&lt;/li&gt;
&lt;li&gt;Docker on the host.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Do not guess at hardware or OS specifications. The documented requirements — including what the model needs to run — live in the &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;on-premises guide&lt;/a&gt;. Read that page before you size anything, because hardware sizing is not covered here and should not be inferred from general GPU rules of thumb.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Buy a Model
&lt;/h2&gt;

&lt;p&gt;On-premises licensing is a one-time payment of &lt;strong&gt;$299 USD per model&lt;/strong&gt;. The first model is Argus 1, our text moderation model (&lt;code&gt;argus_1&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;The licence includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unlimited installs of that model.&lt;/li&gt;
&lt;li&gt;Unlimited requests against that model.&lt;/li&gt;
&lt;li&gt;Upgrades to that model.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Licensing is per model, not per host and not per request, which is why the same purchase works for a single developer laptop, a staging cluster and a production fleet. The &lt;a href="https://cautionlabs.com/pricing" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt; has the current figures, and the &lt;a href="https://cautionlabs.com/legal/terms/onprem" rel="noopener noreferrer"&gt;on-premises software licence&lt;/a&gt; sets out the terms. Note the distribution restriction: the software and its API keys may not be distributed. Unlimited installs is not the same as redistribution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Create a Private Key in the Dashboard
&lt;/h2&gt;

&lt;p&gt;The private key is created from the dashboard and is used as the registry password in the next step. The registry checks the licence on every download, which is how the key stays tied to the model you bought.&lt;/p&gt;

&lt;p&gt;One important caveat about key types: &lt;strong&gt;a private (on-premises) key does not work with the cloud API&lt;/strong&gt;. The hosted API accepts Cloud Keys. If you send a private key to the cloud endpoint it is the wrong key type, and the cloud API rejects it accordingly. Keep the two kinds of key separate in your secret stores and in your CI configuration; mixing them up is a common first-day error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Log In to the Registry and Run the Image
&lt;/h2&gt;

&lt;h3&gt;
  
  
  docker login registery.cautionlabs.com
&lt;/h3&gt;

&lt;p&gt;Authenticate against the CautionLabs registry with your private key as the password:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker login registery.cautionlabs.com
&lt;span class="c"&gt;# when prompted, supply your private key as the password&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The registry validates the licence on every download, so the login is not a one-off ceremony you can skip on a fresh machine. Bake it into your deployment pipeline, and store the private key the same way you store any other production credential.&lt;/p&gt;

&lt;h3&gt;
  
  
  Running the container
&lt;/h3&gt;

&lt;p&gt;The exact &lt;code&gt;docker run&lt;/code&gt; invocation — image reference, flags and port mapping — is documented in the &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;on-premises guide&lt;/a&gt;. Follow it as written rather than reconstructing it, since the guide is the source of truth for the supported command. The endpoint listens on port 8000 by default, so once the container is up you should be able to reach &lt;code&gt;http://localhost:8000&lt;/code&gt; from the host.&lt;/p&gt;

&lt;p&gt;If you are deploying to more than one machine, note that the same private key is used as the registry password on each host. That is expected: installs are unlimited under the licence.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Call POST /moderate on Your Own Network
&lt;/h2&gt;

&lt;p&gt;With the container running, send &lt;code&gt;{"text": "..."}&lt;/code&gt; to &lt;code&gt;POST /moderate&lt;/code&gt; at the default &lt;code&gt;http://localhost:8000&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Request example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST http://localhost:8000/moderate \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"text": "I will find you and make you regret posting that."}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Response example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"toxic"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"profanity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"hate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"harassment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"self_harm"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"adult"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"violence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"drugs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"weapons"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"pii"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"spam"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"minor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"flagged"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every field is a boolean. &lt;code&gt;flagged&lt;/code&gt; is true when any category is true. There is nothing to threshold and nothing to post-process unless your own policy maps specific categories to specific actions — for example, blocking on &lt;code&gt;minor&lt;/code&gt; or &lt;code&gt;self_harm&lt;/code&gt; while routing &lt;code&gt;profanity&lt;/code&gt; to a softer queue.&lt;/p&gt;

&lt;p&gt;Because the response shape matches the cloud API, a client that already consumes the hosted &lt;code&gt;POST /moderation&lt;/code&gt; response can be reused against the local endpoint. In JavaScript that is the same parsing code with a different base URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"http://localhost:8000/moderate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;userText&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flagged&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// apply your own policy using result.categories&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploying on GPU Clouds and Air-Gapped Networks
&lt;/h2&gt;

&lt;h3&gt;
  
  
  RunPod and other GPU clouds
&lt;/h3&gt;

&lt;p&gt;Running the model on a GPU cloud such as RunPod follows the same pattern as a local install. You pull from &lt;code&gt;registery.cautionlabs.com&lt;/code&gt; using the private key as the registry password, then run the image. The only difference from a laptop install is the host.&lt;/p&gt;

&lt;p&gt;The registry licence check still applies on every download, so the credential has to be available to the cloud instance at pull time. Treat it as a deployment secret, not an image layer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Air-gapped installs
&lt;/h3&gt;

&lt;p&gt;Air-gapped installs are supported because the container makes no outbound requests and has no telemetry. There is no phone-home step to break when there is no route to the internet, and no licence callback that has to succeed in the request path. The registry check happens at download time; once the image is on the host, the model runs locally.&lt;/p&gt;

&lt;p&gt;For environments where even the pull must happen from a mirror, work through the documented procedure in the &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;on-premises guide&lt;/a&gt; rather than improvising. Do not assume anything about internal behaviour beyond what is documented: the container makes no outbound requests and has no telemetry, and that is the relevant fact for an air-gapped design review.&lt;/p&gt;

&lt;h2&gt;
  
  
  Upgrading and Handling Errors
&lt;/h2&gt;

&lt;p&gt;Upgrades to the model you own are included in the licence. When a new version of Argus 1 is available, you pull it through the same authenticated registry. The licence check applies to each download, so the same private key and login flow are used.&lt;/p&gt;

&lt;p&gt;For error handling, use the documented errors section of the &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;on-premises guide&lt;/a&gt; rather than assuming the local container mirrors the hosted error set. Do not build retry logic against codes you have not confirmed; read the section, then wire your handler to what is actually documented.&lt;/p&gt;

&lt;p&gt;One thing worth designing for regardless: there is no batch endpoint and no webhooks, so callers are responsible for concurrency, retries and any queueing. Because requests run on your own hardware, that is a capacity decision you control rather than a rate limit imposed by someone else.&lt;/p&gt;

&lt;h2&gt;
  
  
  On-Premises vs the Cloud API: Choosing a Path
&lt;/h2&gt;

&lt;p&gt;The two paths are priced differently because they solve different problems.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cloud API:&lt;/strong&gt; usage-based at &lt;strong&gt;$0.40 USD per 1,000 requests&lt;/strong&gt;. A request covers up to 3,000 characters, and texts of up to 10,000 characters are checked in 3,000-character pieces, one request each.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On-premises:&lt;/strong&gt; a one-time payment of &lt;strong&gt;$299 USD per model&lt;/strong&gt;, with unlimited installs and requests and upgrades to that model included.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both return the same boolean flags and the same response shape. Keys are not interchangeable: &lt;strong&gt;a private (on-premises) key does not work with the cloud API&lt;/strong&gt;, which accepts Cloud Keys. If you are weighing the hosted route, the &lt;a href="https://cautionlabs.com/blogs/content-moderation-api-add-text-moderation" rel="noopener noreferrer"&gt;add text moderation to your app&lt;/a&gt; guide covers the integration end to end, and the &lt;a href="https://cautionlabs.com/legal/terms/cloud" rel="noopener noreferrer"&gt;cloud API terms&lt;/a&gt; describe how text is handled there.&lt;/p&gt;

&lt;p&gt;The decision usually comes down to two questions. Is the text allowed to leave your network at all? If the answer is no, the choice is made. If it is yes, then volume and predictability decide it — usage-based billing scales with traffic, while a per-model licence has a fixed cost and unlimited requests.&lt;/p&gt;

&lt;p&gt;Either way, plan for the same constraint: no batch endpoint and no webhooks. Both APIs are request-and-response, and both expect your application to drive the loop.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What does unlimited installs and requests actually cover?&lt;/strong&gt; It covers installs of the model you bought, requests against that model, and upgrades to that model. It does not change the distribution rule: the software and its API keys may not be distributed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I use my on-premises private key against the cloud API?&lt;/strong&gt; No. A private (on-premises) key does not work with the cloud API. The hosted API accepts Cloud Keys. Keep the two key types separate in your secret management.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does the container phone home or send telemetry?&lt;/strong&gt; No. The model container makes no outbound requests and has no telemetry. The licence check happens against the registry at download time, which is why air-gapped installs are supported.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How does per-model licensing and upgrading work?&lt;/strong&gt; Licensing is per model — the first is Argus 1 (&lt;code&gt;argus_1&lt;/code&gt;). Upgrades to that model are included in the one-time payment, and you pull new versions through the same authenticated registry, where the licence is checked on every download.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How does POST /moderate differ from the hosted POST /moderation endpoint?&lt;/strong&gt; The local &lt;code&gt;POST /moderate&lt;/code&gt; runs on your own network, default &lt;code&gt;http://localhost:8000&lt;/code&gt;, and returns the same response shape as the hosted &lt;code&gt;POST /moderation&lt;/code&gt; on &lt;code&gt;https://api.cautionlabs.com&lt;/code&gt;. The difference is where the model runs and how it is paid for — and which key type is accepted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Step
&lt;/h2&gt;

&lt;p&gt;Read the &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;on-premises guide&lt;/a&gt; to check requirements and run your first local moderation request, and compare licence terms on the &lt;a href="https://cautionlabs.com/pricing" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt;. If you want the exact wording on what you can do with the software and its keys, the &lt;a href="https://cautionlabs.com/legal/terms/onprem" rel="noopener noreferrer"&gt;on-premises software licence&lt;/a&gt; is the document to read before you deploy.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Cover image: Photo by kewl, CC BY 2.0 · &lt;a href="https://www.flickr.com/photos/58411470@N00/39044661591" rel="noopener noreferrer"&gt;source&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>backend</category>
      <category>docker</category>
      <category>infrastructure</category>
      <category>privacy</category>
    </item>
    <item>
      <title>Content Moderation API: Add Moderation in an Afternoon</title>
      <dc:creator>CautionLabs</dc:creator>
      <pubDate>Fri, 13 Nov 2026 09:14:52 +0000</pubDate>
      <link>https://dev.to/cautionlabs/content-moderation-api-add-moderation-in-an-afternoon-1an3</link>
      <guid>https://dev.to/cautionlabs/content-moderation-api-add-moderation-in-an-afternoon-1an3</guid>
      <description>&lt;h2&gt;
  
  
  What a Content Moderation API Actually Returns
&lt;/h2&gt;

&lt;p&gt;Adding a content moderation API to an existing product is a one-afternoon job if you know two things before you write any code: exactly what the endpoint returns, and who owns the policy decision. With CautionLabs, the endpoint returns flags. Your application decides what those flags mean.&lt;/p&gt;

&lt;p&gt;That split is the whole design. A moderation model that hands you a float forces you to invent a cutoff, defend it in code review, and revisit it whenever the model changes. A model that hands you booleans moves the policy conversation out of the model and into your application, where your product context actually lives.&lt;/p&gt;

&lt;h3&gt;
  
  
  Booleans, not confidence scores
&lt;/h3&gt;

&lt;p&gt;Every successful response from the CautionLabs cloud API contains thirteen booleans: twelve per-category flags and one overall result.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Twelve keys inside a &lt;code&gt;categories&lt;/code&gt; object, each &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;One top-level &lt;code&gt;flagged&lt;/code&gt; boolean that is &lt;code&gt;true&lt;/code&gt; when any category is flagged.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are no scores, no probabilities, and no confidence values anywhere in the response. There are no thresholds to tune either, because there is nothing numeric to compare against a cutoff. If you were planning a pipeline built around &lt;code&gt;score &amp;gt; 0.7&lt;/code&gt;, that branch does not exist here.&lt;/p&gt;

&lt;p&gt;The upside is that deterministic booleans are trivial to test. A fixture is a string and an expected object. A regression is a diff. There is no floating-point tolerance to argue about, and nothing to re-tune when the model behind the API is updated.&lt;/p&gt;

&lt;h3&gt;
  
  
  The twelve categories and the overall flagged value
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;categories&lt;/code&gt; object is always present and always contains the same twelve keys:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;toxic&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;profanity&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;hate&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;harassment&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;self_harm&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;adult&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;violence&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;drugs&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;weapons&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pii&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;spam&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;minor&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Treat the key names as a stable contract. They are snake_case, they are safe to switch on, and they arrive in every response regardless of what you sent — a clean message comes back with twelve &lt;code&gt;false&lt;/code&gt; values, not a shortened object.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;flagged&lt;/code&gt; boolean is a convenience for the common case where every category leads to the same outcome. It is &lt;code&gt;true&lt;/code&gt; when any category is flagged, so a product that rejects everything suspicious can branch on &lt;code&gt;flagged&lt;/code&gt; alone and ignore the per-category detail. A product that treats categories differently — quarantining something with a &lt;code&gt;pii&lt;/code&gt; flag while quietly dropping &lt;code&gt;spam&lt;/code&gt; — reads the individual keys.&lt;/p&gt;

&lt;p&gt;That is the entire response surface. Everything below is about wiring it up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your First Content Moderation API Request in Five Minutes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Authentication with a cloud API key
&lt;/h3&gt;

&lt;p&gt;The cloud API is served from &lt;code&gt;https://api.cautionlabs.com&lt;/code&gt;. Authentication is bearer token: put a cloud API key from the dashboard in the &lt;code&gt;Authorization&lt;/code&gt; header of every request.&lt;/p&gt;

&lt;p&gt;A private on-premises key does not work with the cloud API. If you are running the model on your own infrastructure, that key belongs to the local container, not to the hosted endpoint.&lt;/p&gt;

&lt;h3&gt;
  
  
  The POST /moderation request and response
&lt;/h3&gt;

&lt;p&gt;There is one endpoint: &lt;code&gt;POST /moderation&lt;/code&gt;. The request body is JSON with a single required field.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;text&lt;/code&gt; — the string to check. Required. Minimum 1 character, maximum 10,000.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is all you send.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://api.cautionlabs.com/moderation \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $CAUTIONLABS_API_KEY"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"text": "the message you want to check"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same call in Node.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"https://api.cautionlabs.com/moderation"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`Bearer ${process.env.CAUTIONLABS_API_KEY}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;userMessage&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The success payload has exactly two keys:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"toxic"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"profanity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"hate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"harassment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"self_harm"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"adult"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"violence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"drugs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"weapons"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"pii"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"spam"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"minor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"flagged"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What matters for integration is that the keys and types never change: &lt;code&gt;categories&lt;/code&gt; is always an object of twelve booleans, and &lt;code&gt;flagged&lt;/code&gt; is always a boolean. Send your own text through the &lt;a href="https://cautionlabs.com/playground" rel="noopener noreferrer"&gt;playground&lt;/a&gt; to see the exact values for a specific string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Turning Flags Into Product Decisions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Block, review or allow
&lt;/h3&gt;

&lt;p&gt;Three outcomes cover most products: publish, hold for a human, or drop. Write the branch in the order that matches your risk appetite, and be explicit about it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flagged&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;spam&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;drop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"spam"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;            &lt;span class="c1"&gt;// never reaches a human&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pii&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;quarantine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"pii"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;       &lt;span class="c1"&gt;// hidden pending review&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;flagged&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;queueForReview&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;        &lt;span class="c1"&gt;// anything else that tripped&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Order matters. Checking the categories you handle differently before falling back to &lt;code&gt;flagged&lt;/code&gt; keeps the fast path fast — a clean message costs one boolean check, and a message that trips four categories still resolves to a single decision.&lt;/p&gt;

&lt;p&gt;If your application only cares about one signal — spam in a marketplace, harassment in a comments thread — you do not need to read the other eleven keys. Branch on the one you care about and ignore the rest. The per-category &lt;a href="https://cautionlabs.com/solutions" rel="noopener noreferrer"&gt;solutions&lt;/a&gt; pages describe the individual detection surfaces, including &lt;a href="https://cautionlabs.com/solutions/toxicity-detection" rel="noopener noreferrer"&gt;toxicity detection&lt;/a&gt; and &lt;a href="https://cautionlabs.com/solutions/spam-detection" rel="noopener noreferrer"&gt;spam detection&lt;/a&gt; if those are your only concerns.&lt;/p&gt;

&lt;h3&gt;
  
  
  What to log and store
&lt;/h3&gt;

&lt;p&gt;Log the flags next to the metadata you already keep. A useful row is small:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;your content id and user id&lt;/li&gt;
&lt;li&gt;a timestamp&lt;/li&gt;
&lt;li&gt;the twelve category booleans, or the subset you act on&lt;/li&gt;
&lt;li&gt;the decision you made (&lt;code&gt;publish&lt;/code&gt;, &lt;code&gt;queue&lt;/code&gt;, &lt;code&gt;drop&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The API returns flags, not a narrative. It will not tell you why a text was flagged, and the cloud terms state that your text is not stored. That means the flags you log are the only record of the moderation decision, which is exactly why you should log them at the moment you make the call rather than reconstructing the state later from your own queue tables.&lt;/p&gt;

&lt;p&gt;Two practical notes. First, log the raw booleans rather than only your derived decision where you can afford the space — it lets you re-run policy retroactively over historical traffic without calling the API again. Second, do not invent a severity score by counting how many categories are &lt;code&gt;true&lt;/code&gt;. The API does not rank categories, and your logs should not pretend it did.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sizing, Requests and Cost
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The 3,000-character request unit
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;text&lt;/code&gt; accepts 1 to 10,000 characters. A single request covers up to 3,000 characters, and a text is checked in 3,000-character pieces, with each started piece counting as one request.&lt;/p&gt;

&lt;p&gt;The practical consequence: the number that matters for your budget is pieces, not messages. If you accept long-form content — articles, support tickets, imported documents — measure your average text length before you estimate volume, because your request count is driven by length, not by the number of users who hit submit.&lt;/p&gt;

&lt;h3&gt;
  
  
  Moderating many texts without a batch endpoint
&lt;/h3&gt;

&lt;p&gt;There is no batch endpoint. You cannot post an array of texts and get an array back. The API also sends no webhooks, so results are not delivered asynchronously — every result arrives in the response to the request that asked for it.&lt;/p&gt;

&lt;p&gt;That means fan-out belongs in your code, inside the request/response cycle you already have. A concurrency-limited loop is enough:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;moderateAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;texts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;texts&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"https://api.cautionlabs.com/moderation"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`Bearer ${process.env.CAUTIONLABS_API_KEY}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep &lt;code&gt;limit&lt;/code&gt; modest and tunable, and pair each result with its input text as shown — completions arrive out of order and you will need the mapping. If a batch is large enough that it would blow past your own request timeout, move it to a background job and write results into your own queue. The API will not do that for you.&lt;/p&gt;

&lt;p&gt;Cloud pricing is straightforward: &lt;strong&gt;$0.40 USD per 1,000 requests&lt;/strong&gt;, usage-based, with no cost dimension other than request count. The full breakdown lives on the &lt;a href="https://cautionlabs.com/pricing" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;One thing the documentation does not publish: rate limits. There are no documented rate limits, no 429 responses, and no rate-limit headers to read. Design your concurrency for your own infrastructure's comfort rather than for a published number.&lt;/p&gt;

&lt;h2&gt;
  
  
  Errors You Should Handle on Day One
&lt;/h2&gt;

&lt;p&gt;Failures return JSON with two fields: a &lt;code&gt;code&lt;/code&gt; from a fixed set, and a human-readable &lt;code&gt;message&lt;/code&gt;. Branch on &lt;code&gt;code&lt;/code&gt;, log the &lt;code&gt;message&lt;/code&gt; alongside it, and never show the raw message to an end user.&lt;/p&gt;

&lt;p&gt;The five codes and their statuses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;invalid_request&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;400&lt;/code&gt;. The body was malformed or &lt;code&gt;text&lt;/code&gt; was missing, empty, or outside the accepted range. This is a bug in your caller, not a runtime condition to retry. Alert on it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;unauthorized&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;401&lt;/code&gt;. The credential was missing or not accepted. Check that the header is present and the key is current.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;insufficient_credits&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;402&lt;/code&gt;. The account is out of credits. Surface this to whoever owns billing, and consider a circuit breaker so you fail closed — holding content — rather than letting flagged text through because the moderation call could not run.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;wrong_key_type&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;403&lt;/code&gt;. Worth its own branch. A wrong key type has a dedicated code rather than being folded into a generic &lt;code&gt;401&lt;/code&gt;, which makes it diagnosable: the cloud API expects a cloud API key from the dashboard, and an on-premises private key does not work with it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;internal_error&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;500&lt;/code&gt;. The request failed on the server side. This is the one case where a bounded retry with backoff is reasonable, ideally with jitter and a cap.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A small handler keeps this tidy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"internal_error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;retryWithBackoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"insufficient_credits"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;failClosed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"moderation_unavailable"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;failClosed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"moderation_error"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Decide what "fail closed" means for your product before you need it. For a comments section it might mean holding the comment. For a draft-creation flow it might mean blocking submit with a retryable message.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cloud API or On-Premises Model?
&lt;/h2&gt;

&lt;p&gt;The same moderation model is available two ways, and the choice is mostly about your constraints rather than the output format — both return flags.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hosted REST endpoint
&lt;/h3&gt;

&lt;p&gt;The cloud API is the default: no infrastructure, bearer auth with a cloud API key, &lt;code&gt;POST /moderation&lt;/code&gt; at &lt;code&gt;https://api.cautionlabs.com&lt;/code&gt;, and usage-based pricing at $0.40 USD per 1,000 requests. Choose it when you want to ship this afternoon.&lt;/p&gt;

&lt;h3&gt;
  
  
  Running the container on your own infrastructure
&lt;/h3&gt;

&lt;p&gt;The on-premises option runs on your own hardware. The first model is Argus 1, model id &lt;code&gt;argus_1&lt;/code&gt;, and the setup is four steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Buy a model.&lt;/li&gt;
&lt;li&gt;Create a private key in the dashboard.&lt;/li&gt;
&lt;li&gt;Log in to the CautionLabs registry with that key as the password (&lt;code&gt;docker login registery.cautionlabs.com&lt;/code&gt;) and run the image. The registry checks the license on every download.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;POST /moderate&lt;/code&gt; on your own network — the default is &lt;code&gt;http://localhost:8000&lt;/code&gt;, with a body of &lt;code&gt;{"text": "..."}&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Two properties make this viable for regulated and offline environments: the model container makes no outbound requests and has no telemetry. Nothing about your text leaves the machine it runs on.&lt;/p&gt;

&lt;p&gt;Licensing is a one-time payment of &lt;strong&gt;$299 USD per model&lt;/strong&gt;, with unlimited installs and unlimited requests, and upgrades to that model included.&lt;/p&gt;

&lt;p&gt;A short checklist for the decision:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose on-premises if you need data residency, an air-gapped deployment, or a hard guarantee that text never leaves your network.&lt;/li&gt;
&lt;li&gt;Choose the cloud API if you would rather not run GPUs, manage images, or own upgrades.&lt;/li&gt;
&lt;li&gt;If both are viable, start with the cloud API and treat the on-premises path as a migration you can make later — the flags and the branch logic on your side stay the same.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Full requirements and deployment details, including GPU cloud options, are in the &lt;a href="https://cautionlabs.com/docs/on-premises" rel="noopener noreferrer"&gt;on-premises guide&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Does the API return confidence scores?&lt;/strong&gt; No. A response contains twelve category booleans and one overall &lt;code&gt;flagged&lt;/code&gt; boolean. There are no scores, probabilities, or confidence values, and nothing numeric to threshold.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is there a batch endpoint or webhooks?&lt;/strong&gt; No. &lt;code&gt;POST /moderation&lt;/code&gt; accepts one &lt;code&gt;text&lt;/code&gt; per request, and the API sends no webhooks. Fan-out and result handling happen in your application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Are there thresholds I can tune?&lt;/strong&gt; No. There are no thresholds anywhere in the API. The model returns booleans, and your application owns every policy decision built on top of them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I use my on-premises private key with the cloud API?&lt;/strong&gt; No. A private on-premises key does not work with the cloud API. Use a cloud API key from the dashboard for &lt;code&gt;https://api.cautionlabs.com&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How is long text handled?&lt;/strong&gt; &lt;code&gt;text&lt;/code&gt; accepts 1 to 10,000 characters. One request covers up to 3,000 characters, and each started 3,000-character piece counts as one request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does the documentation publish rate limits?&lt;/strong&gt; No. The documentation does not describe rate limits, 429 responses, or rate-limit headers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try It Before You Integrate
&lt;/h2&gt;

&lt;p&gt;You can validate the whole integration before you write a line of application code. Open the &lt;a href="https://cautionlabs.com/playground" rel="noopener noreferrer"&gt;playground&lt;/a&gt;, paste a piece of real user text, and look at the twelve flags and the &lt;code&gt;flagged&lt;/code&gt; value that come back. That is the exact payload your code will handle.&lt;/p&gt;

&lt;p&gt;Then keep the &lt;a href="https://cautionlabs.com/docs" rel="noopener noreferrer"&gt;API reference&lt;/a&gt; open beside you, create a cloud API key in the dashboard, and make one live &lt;code&gt;POST /moderation&lt;/code&gt; request from your own terminal with the curl command above. Once you have seen the response for your own text, the rest is the branch logic you already wrote in this article.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>api</category>
      <category>backend</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Self-Harm Detection in Online Platforms: Why It Matters More Than Ever</title>
      <dc:creator>CautionLabs</dc:creator>
      <pubDate>Thu, 04 Jun 2026 05:04:48 +0000</pubDate>
      <link>https://dev.to/cautionlabs/self-harm-detection-in-online-platforms-why-it-matters-more-than-ever-4m2h</link>
      <guid>https://dev.to/cautionlabs/self-harm-detection-in-online-platforms-why-it-matters-more-than-ever-4m2h</guid>
      <description>&lt;p&gt;Every online platform faces the same challenge: how do you keep users safe while allowing meaningful conversations to happen?&lt;/p&gt;

&lt;p&gt;One of the most sensitive areas of content moderation is self-harm detection. Social networks, forums, chat applications, gaming communities, educational platforms, and customer-facing products all encounter content that may indicate emotional distress, suicidal ideation, or self-harm behavior.&lt;/p&gt;

&lt;p&gt;Detecting this content accurately is critical. Missing genuine cries for help can expose vulnerable users to harm, while over-moderating can silence people who are seeking support or discussing mental health recovery.&lt;/p&gt;

&lt;p&gt;Modern AI moderation systems are helping platforms navigate this challenge at scale.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Self-Harm Content
&lt;/h2&gt;

&lt;p&gt;Self-harm content exists on a spectrum.&lt;/p&gt;

&lt;p&gt;At one end are discussions focused on recovery, therapy, emotional struggles, and support. These conversations are often valuable and should remain accessible.&lt;/p&gt;

&lt;p&gt;At the other end are messages that encourage self-harm, glorify suicide, provide instructions, or indicate immediate danger. These situations often require urgent moderation action.&lt;/p&gt;

&lt;p&gt;The challenge is that both types of content may contain similar language.&lt;/p&gt;

&lt;p&gt;For example, someone sharing their recovery journey may use many of the same words as someone expressing active suicidal intent. Human moderators can usually recognize the difference through context, but manually reviewing every piece of content becomes impossible as platforms grow.&lt;/p&gt;

&lt;p&gt;This is where AI moderation becomes essential.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Keyword Filters Are No Longer Enough
&lt;/h2&gt;

&lt;p&gt;Many moderation systems began with simple keyword matching.&lt;/p&gt;

&lt;p&gt;While keyword filters can catch obvious violations, they often fail when context matters.&lt;/p&gt;

&lt;p&gt;Users may discuss self-harm in educational, medical, or supportive settings. A keyword-based system might incorrectly flag these conversations, creating frustration and reducing trust in the platform.&lt;/p&gt;

&lt;p&gt;At the same time, harmful content frequently avoids obvious keywords through coded language, slang, abbreviations, or indirect phrasing.&lt;/p&gt;

&lt;p&gt;As a result, platforms need moderation systems that understand meaning rather than simply matching words.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Scale Problem
&lt;/h2&gt;

&lt;p&gt;The volume of user-generated content continues to grow.&lt;/p&gt;

&lt;p&gt;Platforms process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chat messages&lt;/li&gt;
&lt;li&gt;Comments&lt;/li&gt;
&lt;li&gt;Community posts&lt;/li&gt;
&lt;li&gt;Reviews&lt;/li&gt;
&lt;li&gt;Support requests&lt;/li&gt;
&lt;li&gt;Forum discussions&lt;/li&gt;
&lt;li&gt;User profiles&lt;/li&gt;
&lt;li&gt;Live interactions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even a moderately successful platform may generate thousands of moderation decisions every day.&lt;/p&gt;

&lt;p&gt;Relying entirely on manual review creates bottlenecks, increases operational costs, and makes rapid intervention difficult.&lt;/p&gt;

&lt;p&gt;AI moderation allows platforms to analyze content in real time and surface the highest-risk cases for human review.&lt;/p&gt;

&lt;h2&gt;
  
  
  How AI Self-Harm Detection Works
&lt;/h2&gt;

&lt;p&gt;Modern moderation systems use machine learning models trained to recognize patterns associated with self-harm and suicide-related content.&lt;/p&gt;

&lt;p&gt;Rather than looking for individual keywords, these systems evaluate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Context&lt;/li&gt;
&lt;li&gt;Intent&lt;/li&gt;
&lt;li&gt;Emotional signals&lt;/li&gt;
&lt;li&gt;Severity&lt;/li&gt;
&lt;li&gt;Linguistic patterns&lt;/li&gt;
&lt;li&gt;Risk indicators&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This enables more nuanced decisions.&lt;/p&gt;

&lt;p&gt;A message discussing recovery after a difficult period may be treated very differently from a message expressing immediate intent to self-harm, even if both contain similar terminology.&lt;/p&gt;

&lt;p&gt;The goal is not to replace human moderators but to help them focus on the content that requires the most attention.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges in Self-Harm Detection
&lt;/h2&gt;

&lt;p&gt;Self-harm moderation is one of the most difficult problems in online safety.&lt;/p&gt;

&lt;p&gt;Language is highly contextual and constantly evolving. Users may express distress indirectly, use sarcasm, reference cultural trends, or communicate through coded expressions.&lt;/p&gt;

&lt;p&gt;Platforms must also account for multiple languages, regional differences, and varying communication styles.&lt;/p&gt;

&lt;p&gt;False positives can prevent users from accessing support communities. False negatives can allow dangerous content to remain visible.&lt;/p&gt;

&lt;p&gt;Achieving the right balance requires sophisticated models and continuous improvement.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Caution Labs Helps
&lt;/h2&gt;

&lt;p&gt;Caution Labs provides AI-powered moderation solutions designed to help platforms detect and manage self-harm-related content more effectively.&lt;/p&gt;

&lt;p&gt;Our moderation API analyzes content contextually, helping developers move beyond simple keyword filtering and toward more accurate safety decisions.&lt;/p&gt;

&lt;p&gt;With Caution Labs, platforms can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Detect self-harm and suicide-related content in real time&lt;/li&gt;
&lt;li&gt;Identify varying levels of risk and severity&lt;/li&gt;
&lt;li&gt;Reduce moderation workload through automation&lt;/li&gt;
&lt;li&gt;Support trust and safety teams with actionable insights&lt;/li&gt;
&lt;li&gt;Scale moderation efforts as user communities grow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whether you're building a social platform, discussion forum, gaming community, AI application, or messaging service, moderation infrastructure should be a core part of your safety strategy.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Importance of Early Detection
&lt;/h2&gt;

&lt;p&gt;Early identification of high-risk content can make a meaningful difference.&lt;/p&gt;

&lt;p&gt;When potentially dangerous content is detected quickly, platforms can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Escalate cases for human review&lt;/li&gt;
&lt;li&gt;Trigger safety workflows&lt;/li&gt;
&lt;li&gt;Apply platform policies consistently&lt;/li&gt;
&lt;li&gt;Reduce exposure to harmful material&lt;/li&gt;
&lt;li&gt;Support vulnerable users more effectively&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI moderation enables these responses to happen in seconds rather than hours.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building Safer Online Communities
&lt;/h2&gt;

&lt;p&gt;Self-harm detection is not simply about enforcing platform rules. It is about creating environments where users can communicate safely while reducing the spread of harmful content.&lt;/p&gt;

&lt;p&gt;The most effective moderation systems combine advanced AI with human judgment. Automation handles scale, while moderators provide context and oversight for complex situations.&lt;/p&gt;

&lt;p&gt;As online communities continue to expand, investing in intelligent moderation becomes increasingly important.&lt;/p&gt;

&lt;p&gt;With solutions like Caution Labs, organizations can implement scalable, context-aware self-harm detection that helps protect users, supports moderation teams, and strengthens trust across their platforms.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>community</category>
      <category>mentalhealth</category>
      <category>socialmedia</category>
    </item>
    <item>
      <title>Detecting Hate Speech with AI: How Caution Labs Helps Build Safer Online Communities</title>
      <dc:creator>CautionLabs</dc:creator>
      <pubDate>Tue, 02 Jun 2026 04:54:51 +0000</pubDate>
      <link>https://dev.to/cautionlabs/detecting-hate-speech-with-ai-how-caution-labs-helps-build-safer-online-communities-41m9</link>
      <guid>https://dev.to/cautionlabs/detecting-hate-speech-with-ai-how-caution-labs-helps-build-safer-online-communities-41m9</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As online communities grow, platforms face increasing challenges in moderating harmful content. Among the most damaging forms of abuse is hate speech—content that attacks, degrades, or promotes hostility toward individuals or groups based on protected characteristics such as race, ethnicity, nationality, religion, disability, gender, or sexual orientation.&lt;/p&gt;

&lt;p&gt;At scale, manual moderation alone is often insufficient. This is where AI-powered moderation systems such as Caution Labs can help platforms detect and manage hate speech efficiently while preserving legitimate discussion.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Hate Speech?
&lt;/h2&gt;

&lt;p&gt;Hate speech generally refers to content that targets people or groups with abusive, discriminatory, or dehumanizing language because of who they are.&lt;/p&gt;

&lt;p&gt;Examples may include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Racial slurs&lt;/li&gt;
&lt;li&gt;Calls for exclusion or discrimination&lt;/li&gt;
&lt;li&gt;Dehumanizing comparisons&lt;/li&gt;
&lt;li&gt;Threats against protected groups&lt;/li&gt;
&lt;li&gt;Praise or promotion of hatred toward specific communities&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, identifying hate speech is not always straightforward. Context matters significantly.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Potentially Allowed&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I'm researching the history of antisemitic propaganda."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Potentially Violating&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"People from that religion are ruining the country."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Both statements discuss a protected group, but only one expresses hostility toward that group.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Hate Speech Is Difficult to Moderate
&lt;/h2&gt;

&lt;p&gt;Traditional moderation systems often relied on keyword lists and simple rules.&lt;/p&gt;

&lt;p&gt;This approach has several limitations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Slurs can be quoted for educational purposes.&lt;/li&gt;
&lt;li&gt;Harmful content may avoid explicit slurs.&lt;/li&gt;
&lt;li&gt;Users frequently use coded language.&lt;/li&gt;
&lt;li&gt;The same word can be offensive in one context and harmless in another.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a result, effective hate speech detection requires understanding meaning, intent, and context—not just words.&lt;/p&gt;

&lt;h2&gt;
  
  
  How AI Detects Hate Speech
&lt;/h2&gt;

&lt;p&gt;Modern moderation systems use machine learning models trained on large datasets of annotated content.&lt;/p&gt;

&lt;p&gt;Instead of looking only for specific terms, these models evaluate:&lt;/p&gt;

&lt;h3&gt;
  
  
  Context
&lt;/h3&gt;

&lt;p&gt;The model examines surrounding words and sentence structure to understand meaning.&lt;/p&gt;

&lt;h3&gt;
  
  
  Target
&lt;/h3&gt;

&lt;p&gt;The system determines whether the content is directed at an individual, a group, or nobody in particular.&lt;/p&gt;

&lt;h3&gt;
  
  
  Intent
&lt;/h3&gt;

&lt;p&gt;AI can help distinguish between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Discussion&lt;/li&gt;
&lt;li&gt;Quotation&lt;/li&gt;
&lt;li&gt;Criticism&lt;/li&gt;
&lt;li&gt;Harassment&lt;/li&gt;
&lt;li&gt;Hate promotion&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Severity
&lt;/h3&gt;

&lt;p&gt;Not all violations carry the same level of risk.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Severity&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;Low&lt;/p&gt;

&lt;p&gt;Borderline derogatory language&lt;/p&gt;

&lt;p&gt;Medium&lt;/p&gt;

&lt;p&gt;Insults targeting a protected group&lt;/p&gt;

&lt;p&gt;High&lt;/p&gt;

&lt;p&gt;Dehumanization or exclusion&lt;/p&gt;

&lt;p&gt;Critical&lt;/p&gt;

&lt;p&gt;Threats or calls for violence&lt;/p&gt;

&lt;h2&gt;
  
  
  How Caution Labs Approaches Hate Speech Detection
&lt;/h2&gt;

&lt;p&gt;Caution Labs uses transformer-based language models that analyze content beyond keyword matching.&lt;/p&gt;

&lt;p&gt;The system evaluates multiple signals simultaneously, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Linguistic context&lt;/li&gt;
&lt;li&gt;Targeted groups&lt;/li&gt;
&lt;li&gt;Toxicity indicators&lt;/li&gt;
&lt;li&gt;Intent patterns&lt;/li&gt;
&lt;li&gt;Severity classification&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This allows platforms to make more informed moderation decisions.&lt;/p&gt;

&lt;p&gt;For example, the system can distinguish between:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"This book analyzes racist rhetoric."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"That race is inferior."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Even though both sentences discuss race, their intent and risk levels differ significantly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-Label Classification
&lt;/h2&gt;

&lt;p&gt;Rather than assigning a simple "hate" or "not hate" label, Caution Labs can classify content across multiple categories.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hate speech&lt;/li&gt;
&lt;li&gt;Harassment&lt;/li&gt;
&lt;li&gt;Toxicity&lt;/li&gt;
&lt;li&gt;Threats&lt;/li&gt;
&lt;li&gt;Identity attacks&lt;/li&gt;
&lt;li&gt;Extremist rhetoric&lt;/li&gt;
&lt;li&gt;Discrimination&lt;/li&gt;
&lt;li&gt;Profanity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This enables platforms to build moderation policies tailored to their specific needs.&lt;/p&gt;

&lt;p&gt;For instance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A professional community may enforce strict anti-harassment policies.&lt;/li&gt;
&lt;li&gt;A gaming platform may allow some profanity while still prohibiting identity-based attacks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Detecting Evasive Language
&lt;/h2&gt;

&lt;p&gt;Users attempting to bypass moderation systems often avoid obvious slurs by using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Misspellings&lt;/li&gt;
&lt;li&gt;Symbols&lt;/li&gt;
&lt;li&gt;Alternate spellings&lt;/li&gt;
&lt;li&gt;Code words&lt;/li&gt;
&lt;li&gt;Contextual references&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples include replacing letters with numbers or symbols, or using seemingly harmless terms that carry hateful meaning within specific communities.&lt;/p&gt;

&lt;p&gt;Modern language models can identify many of these patterns because they analyze semantic meaning rather than relying solely on exact keyword matches.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-Time Moderation
&lt;/h2&gt;

&lt;p&gt;For chat applications, forums, livestreams, and social networks, moderation decisions must happen quickly.&lt;/p&gt;

&lt;p&gt;A typical workflow looks like:&lt;/p&gt;

&lt;p&gt;User submits content.&lt;/p&gt;

&lt;p&gt;Content is sent to Caution Labs.&lt;/p&gt;

&lt;p&gt;AI evaluates risk categories.&lt;/p&gt;

&lt;p&gt;Confidence scores are returned.&lt;/p&gt;

&lt;p&gt;Platform policies determine the action.&lt;/p&gt;

&lt;p&gt;Content is approved, restricted, hidden, or escalated for review.&lt;/p&gt;

&lt;p&gt;This process can occur in real time, helping platforms respond before harmful content spreads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Human Review for Edge Cases
&lt;/h2&gt;

&lt;p&gt;AI moderation is powerful but not perfect.&lt;/p&gt;

&lt;p&gt;Some cases involve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Humor&lt;/li&gt;
&lt;li&gt;Satire&lt;/li&gt;
&lt;li&gt;Reclaimed language&lt;/li&gt;
&lt;li&gt;Political discussion&lt;/li&gt;
&lt;li&gt;Cultural nuances&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For uncertain cases, platforms can use a human-in-the-loop approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Auto-approve low-risk content.&lt;/li&gt;
&lt;li&gt;Auto-block clear violations.&lt;/li&gt;
&lt;li&gt;Escalate ambiguous content to human moderators.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This combination improves both accuracy and fairness.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits for Platforms
&lt;/h2&gt;

&lt;p&gt;AI-powered hate speech detection offers several advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Faster moderation decisions&lt;/li&gt;
&lt;li&gt;Reduced manual review workload&lt;/li&gt;
&lt;li&gt;Consistent policy enforcement&lt;/li&gt;
&lt;li&gt;Better detection of coded language&lt;/li&gt;
&lt;li&gt;Improved user safety&lt;/li&gt;
&lt;li&gt;Scalable moderation for growing communities&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These capabilities become increasingly important as platforms expand and content volumes increase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Hate speech moderation requires more than keyword filtering. Effective detection depends on understanding context, intent, targets, and severity. As online communities continue to grow, platforms need moderation systems capable of identifying harmful content without disrupting legitimate conversation.&lt;/p&gt;

&lt;p&gt;Caution Labs addresses this challenge through AI-powered classification models that help detect hate speech, harassment, and related forms of abuse in real time. By combining contextual understanding with scalable automation, platforms can create safer and more inclusive environments for their users.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>community</category>
      <category>machinelearning</category>
      <category>nlp</category>
    </item>
    <item>
      <title>Profanity Detection: A Critical Layer of Modern Content Moderation</title>
      <dc:creator>CautionLabs</dc:creator>
      <pubDate>Sat, 30 May 2026 20:09:42 +0000</pubDate>
      <link>https://dev.to/cautionlabs/profanity-detection-a-critical-layer-of-modern-content-moderation-2af8</link>
      <guid>https://dev.to/cautionlabs/profanity-detection-a-critical-layer-of-modern-content-moderation-2af8</guid>
      <description>&lt;h2&gt;
  
  
  Why Profanity Detection Matters
&lt;/h2&gt;

&lt;p&gt;Every day, online platforms process thousands of comments, messages, reviews, and chat conversations. Without proper moderation, offensive language can negatively impact user experience, damage brand reputation, and drive communities away.&lt;/p&gt;

&lt;p&gt;Profanity detection helps platforms automatically identify and manage inappropriate language before it reaches users.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Challenge
&lt;/h2&gt;

&lt;p&gt;Detecting profanity is no longer as simple as matching words against a blacklist.&lt;/p&gt;

&lt;p&gt;Users often bypass filters through misspellings, character substitutions, slang, and creative spellings. Context also matters—a word that is harmless in one conversation may be abusive in another.&lt;/p&gt;

&lt;p&gt;Modern moderation systems must understand both language and intent.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Modern Profanity Detection Works
&lt;/h2&gt;

&lt;p&gt;Today's solutions combine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rule-based filtering&lt;/li&gt;
&lt;li&gt;Natural Language Processing (NLP)&lt;/li&gt;
&lt;li&gt;Machine learning models&lt;/li&gt;
&lt;li&gt;Context-aware classification&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This layered approach improves accuracy while reducing false positives and helping moderation teams scale efficiently.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Caution Labs Helps
&lt;/h2&gt;

&lt;p&gt;At &lt;strong&gt;Caution Labs&lt;/strong&gt;, we build AI-powered content moderation solutions designed for real-world applications. Our profanity detection technology goes beyond simple keyword matching to identify offensive content more accurately, helping businesses create safer and more welcoming online environments.&lt;/p&gt;

&lt;p&gt;Whether you're running a social platform, community forum, gaming application, or customer-facing product, automated moderation can significantly reduce manual review effort while improving user trust.&lt;/p&gt;

&lt;h2&gt;
  
  
  Looking Ahead
&lt;/h2&gt;

&lt;p&gt;Profanity detection is often the first line of defense in content moderation. As online communication continues to evolve, organizations need smarter systems that can understand context, adapt to changing language patterns, and operate at scale.&lt;/p&gt;

&lt;p&gt;The future of moderation isn't just detecting bad words—it's understanding conversations. That's the problem Caution Labs is helping solve.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why Detecting PII Matters More Than Ever</title>
      <dc:creator>CautionLabs</dc:creator>
      <pubDate>Tue, 26 May 2026 03:44:28 +0000</pubDate>
      <link>https://dev.to/cautionlabs/why-detecting-pii-matters-more-than-ever-2kha</link>
      <guid>https://dev.to/cautionlabs/why-detecting-pii-matters-more-than-ever-2kha</guid>
      <description>&lt;h1&gt;
  
  
  Why Detecting PII Matters More Than Ever
&lt;/h1&gt;

&lt;p&gt;Every modern application processes data. Usernames, emails, phone numbers, payment details, addresses, government IDs, IP addresses, chat logs, uploaded documents — all of it flows through APIs, databases, analytics systems, logs, and AI pipelines.&lt;/p&gt;

&lt;p&gt;Hidden inside that data is something extremely sensitive: Personally Identifiable Information (PII).&lt;/p&gt;

&lt;p&gt;PII refers to any information that can identify a person directly or indirectly. That includes names, email addresses, phone numbers, financial information, passport numbers, medical records, IP addresses, and more.&lt;/p&gt;

&lt;p&gt;For startups and SaaS companies, detecting PII is no longer optional. It is a core security, privacy, and trust requirement.&lt;/p&gt;

&lt;h1&gt;
  
  
  What Happens When PII Is Not Detected
&lt;/h1&gt;

&lt;p&gt;Most companies do not intentionally leak sensitive data.&lt;/p&gt;

&lt;p&gt;Instead, PII quietly spreads across systems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logs accidentally store user emails&lt;/li&gt;
&lt;li&gt;AI prompts contain private conversations&lt;/li&gt;
&lt;li&gt;Analytics pipelines ingest raw customer data&lt;/li&gt;
&lt;li&gt;CSV exports are shared internally without masking&lt;/li&gt;
&lt;li&gt;Screenshots expose payment details&lt;/li&gt;
&lt;li&gt;Support tickets contain addresses and IDs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Over time, sensitive information becomes impossible to track.&lt;/p&gt;

&lt;p&gt;The result is a massive attack surface.&lt;/p&gt;

&lt;p&gt;Cybercriminals target PII because it enables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identity theft&lt;/li&gt;
&lt;li&gt;Financial fraud&lt;/li&gt;
&lt;li&gt;SIM swapping&lt;/li&gt;
&lt;li&gt;Account takeovers&lt;/li&gt;
&lt;li&gt;Social engineering attacks&lt;/li&gt;
&lt;li&gt;Doxxing and harassment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;IBM notes that stolen PII is frequently used for identity theft, ransomware, and business email compromise attacks.&lt;/p&gt;

&lt;p&gt;Real-world security discussions also show how leaked PII often causes damage months later after multiple breaches are combined together.&lt;/p&gt;

&lt;h1&gt;
  
  
  The AI Era Has Made PII Detection Harder
&lt;/h1&gt;

&lt;p&gt;Modern AI systems process enormous amounts of unstructured text:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chat messages&lt;/li&gt;
&lt;li&gt;Uploaded files&lt;/li&gt;
&lt;li&gt;Emails&lt;/li&gt;
&lt;li&gt;OCR text&lt;/li&gt;
&lt;li&gt;Audio transcripts&lt;/li&gt;
&lt;li&gt;Customer support conversations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Traditional regex-based filters are no longer enough.&lt;/p&gt;

&lt;p&gt;PII now appears in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Informal language&lt;/li&gt;
&lt;li&gt;Misspellings&lt;/li&gt;
&lt;li&gt;Screenshots&lt;/li&gt;
&lt;li&gt;Mixed languages&lt;/li&gt;
&lt;li&gt;Context-dependent phrases&lt;/li&gt;
&lt;li&gt;AI-generated outputs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Research shows that modern PII masking systems still struggle with demographic bias, contextual ambiguity, and inconsistent detection quality.&lt;/p&gt;

&lt;p&gt;Even large language models themselves can leak memorized personal information under certain conditions.&lt;/p&gt;

&lt;p&gt;That means organizations need smarter moderation and detection systems capable of understanding context, not just patterns.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why Businesses Need Automated PII Detection
&lt;/h1&gt;

&lt;p&gt;Manual moderation does not scale.&lt;/p&gt;

&lt;p&gt;A modern platform may process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Millions of comments&lt;/li&gt;
&lt;li&gt;Uploaded images&lt;/li&gt;
&lt;li&gt;Documents&lt;/li&gt;
&lt;li&gt;AI prompts&lt;/li&gt;
&lt;li&gt;User messages&lt;/li&gt;
&lt;li&gt;Public posts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Automated PII detection helps companies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prevent sensitive data exposure&lt;/li&gt;
&lt;li&gt;Reduce compliance risks&lt;/li&gt;
&lt;li&gt;Avoid accidental logging&lt;/li&gt;
&lt;li&gt;Mask data before storage&lt;/li&gt;
&lt;li&gt;Secure AI pipelines&lt;/li&gt;
&lt;li&gt;Protect customer trust&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It also supports compliance with regulations such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GDPR&lt;/li&gt;
&lt;li&gt;CCPA&lt;/li&gt;
&lt;li&gt;HIPAA&lt;/li&gt;
&lt;li&gt;PCI-DSS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Several security and compliance reports emphasize that automated PII discovery and monitoring are now critical for modern infrastructure.&lt;/p&gt;

&lt;h1&gt;
  
  
  PII Detection Is Also a Trust Problem
&lt;/h1&gt;

&lt;p&gt;Users increasingly care about privacy.&lt;/p&gt;

&lt;p&gt;People may forgive bugs.&lt;/p&gt;

&lt;p&gt;They rarely forgive leaked personal information.&lt;/p&gt;

&lt;p&gt;A platform that proactively detects and protects sensitive data signals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Security maturity&lt;/li&gt;
&lt;li&gt;Responsible engineering&lt;/li&gt;
&lt;li&gt;Privacy awareness&lt;/li&gt;
&lt;li&gt;Safer AI adoption&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For businesses building AI products, moderation platforms, or social systems, strong PII detection can become a competitive advantage.&lt;/p&gt;

&lt;h1&gt;
  
  
  Building Safer Platforms With Smarter Moderation
&lt;/h1&gt;

&lt;p&gt;Modern moderation systems should not only detect toxic content or spam.&lt;/p&gt;

&lt;p&gt;They should also identify:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Emails&lt;/li&gt;
&lt;li&gt;Phone numbers&lt;/li&gt;
&lt;li&gt;Addresses&lt;/li&gt;
&lt;li&gt;Government IDs&lt;/li&gt;
&lt;li&gt;Credit card details&lt;/li&gt;
&lt;li&gt;Banking information&lt;/li&gt;
&lt;li&gt;Medical data&lt;/li&gt;
&lt;li&gt;API keys&lt;/li&gt;
&lt;li&gt;Sensitive documents&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is especially important for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AI chat platforms&lt;/li&gt;
&lt;li&gt;Social networks&lt;/li&gt;
&lt;li&gt;SaaS tools&lt;/li&gt;
&lt;li&gt;Customer support systems&lt;/li&gt;
&lt;li&gt;Forums&lt;/li&gt;
&lt;li&gt;File upload services&lt;/li&gt;
&lt;li&gt;Enterprise collaboration apps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Detecting PII before storage or exposure dramatically reduces risk.&lt;/p&gt;

&lt;h1&gt;
  
  
  How Caution Labs Helps
&lt;/h1&gt;

&lt;p&gt;Caution Labs builds AI-powered content moderation and safety infrastructure designed for modern applications.&lt;/p&gt;

&lt;p&gt;The platform helps developers and businesses detect unsafe or sensitive content across text, images, and AI-generated workflows — including Personally Identifiable Information (PII).&lt;/p&gt;

&lt;p&gt;Whether you are building:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AI applications&lt;/li&gt;
&lt;li&gt;SaaS products&lt;/li&gt;
&lt;li&gt;Community platforms&lt;/li&gt;
&lt;li&gt;Social apps&lt;/li&gt;
&lt;li&gt;User-generated content systems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;PII detection should be part of the architecture from day one, not added after a breach.&lt;/p&gt;

&lt;p&gt;As AI systems become more deeply integrated into products, privacy-aware moderation is becoming foundational infrastructure rather than an optional security layer.&lt;/p&gt;

&lt;p&gt;Learn more at Caution Labs Official Website.&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>data</category>
      <category>privacy</category>
      <category>security</category>
    </item>
  </channel>
</rss>
