Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

1. Float Scale Scoring using Azure Content Safety API

The Azure Content Safety API is one of our most reliable scorers for detecting harms. Although it isn’t very flexible, it’s extremely fast and reliable and can be used to score images or text.

In order to use this API, you need to configure a few environment variables:

  • AZURE_CONTENT_SAFETY_API_ENDPOINT: The endpoint for the Azure Content Safety API

Authentication uses Entra ID (identity-based) via az login. Make sure you have the appropriate role (e.g., Cognitive Services User) on the resource. from pyrit.auth.azure_auth import get_azure_token_provider api_key = get_azure_token_provider(“https://cognitiveservices.azure.com/.default”)

Note that this api returns a value between 0 and 7. This is different from likert scales, which return a value between 1 and 5. Because both are float_scale scores, these values are all normalized to floating point values between 0.0 and 1.0 and can be directly compared. This is sometimes interesting as an operator e.g. if there are scenarios where a SelfAskLikertScorer and AzureContentFilterScorer produce very different values.

Found default environment files: ['./.pyrit/.env', './.pyrit/.env.local']
Loaded environment file: ./.pyrit/.env
Loaded environment file: ./.pyrit/.env.local
AzureContentFilterScorer: Hate: 0.2857142857142857 {'azure_severity': 2}
AzureContentFilterScorer: SelfHarm: 0.0 {'azure_severity': 0}
AzureContentFilterScorer: Sexual: 0.0 {'azure_severity': 0}
AzureContentFilterScorer: Violence: 0.0 {'azure_severity': 0}