Skip to main content
This module is used to review the content input by end users and the content output by LLM in applications. It is divided into two extension point types.

Extension Points

  • app.moderation.input: End user input content review extension point
    • Used to review variable content passed in by end users and conversation input content in conversational applications.
  • app.moderation.output: LLM output content review extension point
    • Used to review content output by LLM.
    • Each request carries only the output added since the previous request. When the LLM output is streaming, Dify sends a request once 300 new characters have built up, and a last request with the rest when the output ends. Otherwise, the output is sent in segments of up to 2,000 characters.

app.moderation.input

When Content Moderation > Review Input Content is enabled in applications such as Chatflow, Agent, or Chatbot, Dify will send the following HTTP POST request to the corresponding custom endpoint:

Request Body

Example:

API Response

Example:
  • action=direct_output
  • action=overridden

app.moderation.output

When Content Moderation > Review Output Content is enabled in applications such as Chatflow, Agent, or Chat Assistant, Dify will send the following HTTP POST request to the corresponding custom endpoint:

Request Body

Example:

API Response

Example:
  • action=direct_output
  • action=overridden

Code Example

Below is a piece of src/index.ts code that can be deployed on Cloudflare. (For complete Cloudflare usage, please refer to this documentation) The code works by performing keyword matching to filter both Input (content entered by users) and Output (content returned by the model). Users can modify the matching logic according to their needs.