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?
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
- 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.
- 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.
- 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.
- 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.
- 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.
- 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?
Check yourself · 3 of 3
A generated image scores just below your block threshold for a sensitive category. What is the safest policy?
Practice items, not counted towards your mastery.
Start here
- Image generation guide (OpenAI) (opens in a new tab)DocsFree
Size, quality, edit and mask parameters for the OpenAI image endpoints.
- Image generation with Gemini (Google) (opens in a new tab)DocsFree
Gemini's text-to-image and conversational editing, including reference images and its watermark note.
- FLUX documentation (Black Forest Labs) (opens in a new tab)DocsFree
How the FLUX API submits a job and returns a polling address instead of the image.
More for this topic
- Moderation guide (OpenAI) (opens in a new tab)DocsFree
A free moderation endpoint that scores text and images by category.
Where to go in your country
- Article 50: Transparency obligations (EU AI Act) (opens in a new tab)DocsFreeEU
Marking duty for providers of generated content and disclosure duty for deepfakes.