Skip to content
mentoor

Topic 4 of 6 · 4 min read

Moderating prompts and generated images

Goal: Design an input and output moderation flow for a user-facing image feature and state what users see when a request is blocked.

Moderate twice, before and after generation, and tell the user what happened in plain words: check the prompt on the way in, check the image on the way out, and show a specific reason when you block.

Check yourself · 1 of 3

A user's prompt passes input moderation: "a crowd at a rally". Why still check the generated image?

Choose one answer

Why it matters

An image feature lets anyone ask for anything under your brand name. Providers filter some requests, but their filters are broad and change without notice. They do not know your audience, your market or your rules. Generated images can contain real people's likeness, minors in unsafe contexts, trademarks and other content you must not publish.

How to do it

  1. Check input. Run the prompt, and any uploaded image, through a moderation check before generating. OpenAI offers a moderation endpoint for text and images; other vendors and open-weight classifiers exist. Add your own rules for what the product must never make: named real people, a competitor's logo, your own banned topics.
  2. Check output. A clean prompt can still give an unsafe image. Run the generated image through an image classifier before anything is shown or stored for sharing. A model refusal or an empty result from the provider counts as a block too.
  3. Choose actions by severity. Block and log the clear violations. For borderline scores, queue for human review or show a safe alternative. Never auto-publish borderline results.
  4. Handle special categories. Real people's likeness, sexual content involving anything that could be a minor, trademarks and brand marks need explicit rules and, for people, usually a hard block on named individuals.
  5. Tell the user why. Name the category and the next step: "We cannot create images of real people. Describe a fictional character instead." Do not show the raw classifier output or leak the exact rule that would help someone get around it.
  6. Log for review. Keep the user id, the prompt, the decision and the reason. Count blocks per user; repeated attempts need a limit.

Before and after

Before: Prompt goes to the provider. If the provider refuses, the app shows "Something went wrong."

After: Prompt is checked and passes. The provider returns an image. The output check flags it. The app shows: "This image was not shown because it may contain a real person's likeness. Try a different description. Reference: IMG-4821." The reference id lets support find the log.

What goes wrong

  • Only input is checked, and the model still produces an unsafe image from an innocent prompt.
  • Everything depends on the provider's filter, so a policy change at the provider changes your product overnight.
  • Blocked users see a generic error, retry ten times and file support tickets.
  • The block message reveals the exact word that triggered it, so users learn to phrase around it.

Examples

A two-gate flow

1. clean(prompt)                  -> block on policy hit, log
2. moderate_input(prompt, images) -> block / allow
3. generate()                     -> provider refusal = block
4. moderate_output(image)         -> block / review / allow
5. store + show, or show reason + reference id

Block messages

Real person: "We cannot create images of real people. Describe a fictional character instead."

Brand mark: "We cannot include other companies' logos. Remove the brand name and try again."

Both give a category and a next step, plus a reference id.

Key points

  • Moderate the prompt before generation and the image after it; a clean prompt can still give an unsafe image.
  • Provider filters are a first layer, not your policy; add rules for your own market and brand.
  • Choose actions by severity: block, send to human review, or offer a safe alternative.
  • Real people's likeness, minors and trademarks need explicit rules, not only a generic score.
  • Tell the user which category was hit and what to try, with a reference id, without revealing the exact trigger.

Common mistakes

  • Checking only the prompt and trusting the generated image.
  • Treating the provider's built-in filter as the whole moderation policy.
  • Showing a generic error when a request is blocked.
  • Publishing borderline images automatically instead of queueing them for review.

Check yourself · 2 of 3

An image request is blocked. Which message is best?

Choose one answer

Check yourself · 3 of 3

A generated image scores just below your block threshold for a sensitive category. What is the safest policy?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic

Where to go in your country