Guide to Handling Not Safe for Work Image Generation (NSFW)

Choosing a Finetuned Model

Leonardo.Ai continuously improves safeguards against NSFW generations. Newer Platform Models will tend to be less susceptive to NSFW generation.

Stable Diffusion v1.5 (SD1.5) and Platform Models based on SD1.5 are known to be prone to generate NSFW. As such, we use a more conservative detection and flagging mechanism for these family of models. The best practice is to use newer models such as those based on Stable Diffusion SDXL.0_9, Stable Diffusion SDXL.1_0, and SDXL.LIGHTNING (SDXL).

To check the base model of a Platform Model, navigate to Finetuned Models and switch to platform Platform Models tab. Click on the model and then click on View More.

Checking the base model of a Platform Model

Checking the base model of a Platform Model

You can also refer to the table here to check the base model of a particular finetuned model.

πŸ“˜

Note on PhotoReal

PhotoReal v1 is a workflow based on SD1.5 thus prone to generate NSFW. The best practice is to use the latest version, PhotoReal v2, which uses SDXL.

Blocking at the Prompt Level

Like the Leonardo web app, the Leonardo API will block NSFW image generation by default. Any prompts flagged as NSFW will return a 400 Bad Request error.

For example, generating with a prompt β€œnude” will be blocked with the following error:

{  
  "error": "content moderation filter: nude",  
  "path": "$",  
  "code": "unexpected"  
}

Flagging at the Response Level

The Production API returns a NSFW attribute that flags if the image generated contains NSFW material. Depending on your use case, you can opt to filter out the flagged images and not return them to your end users.

...
"generated_images": \[  
      {  
        "url": "<https://cdn.leonardo.ai/users/ef8b8386-94f7-48d1-b10e-e87fd4dee6e6/generations/88b381ea-7baf-457d-a5b4-8068cb6bac21/Leonardo_Creative_An_oil_painting_of_a_cat_0.jpg">,  
        "nsfw": true,  
        "id": "5b710f5f-22de-4d27-8b5c-4eadc98bfc85",  
        "likeCount": 0,  
        "generated_image_variation_generics": \[]  
      },
      ...
]
...

If you’d like more rigid NSFW controls, please contact us for assistance, letting us know about your use case and requirements.

πŸ“˜

Note

Stable Diffusion v1.5 (SD1.5) and Platform Models based on SD1.5 are more prone to generate NSFW images. We recommend using SDXL based models for lower risk of NSFW images. Find out more about which Finetuned models use SDXL as base here.

Adding your own Image Moderation Layer

For use cases that require more control over the images generated, we recommend adding your own image moderation layer. You can implement your own system, leverage a more specialised third-party detection system, and/or keep a human in the loop to check against your guidelines.