Scoring with Azure AI Content Safety in PyRIT: when a fast harm scorer fits your red team
When a PyRIT attack needs a quick verdict on hate, sexual, violence or self-harm content, the AzureContentFilterScorer is the built-in option to reach for. It calls the Azure Content Safety API, so the verdict comes from a managed classifier rather than another language model. That makes it a fit for high-volume runs where you want a consistent harm signal per response without paying for a second LLM call on every turn. Its trade-off is scope: it rates the four harm categories Azure Content Safety covers, so it will not tell you whether a response met a bespoke policy objective the way an LLM-as-judge true/false scorer can.
Choose between the scorer types by the question you need answered. Use the Azure scorer when you need a fast, repeatable harm rating across many responses and the four categories match your policy. Use a self-ask true/false judge when the question is specific to your own rules, and a Likert scale when you need graded severity for reporting. Azure Content Safety reports on a native range of 0 to 7, which PyRIT normalises to 0 to 1, so you must set your pass or fail threshold on the normalised value. Confirm how your team maps that threshold to each category before comparing results with other scorers.
DeployOpen configures and tests the scorer inside your own Azure tenant, including the Content Safety resource, the AZURE_CONTENT_SAFETY_API_ENDPOINT setting and Entra ID authentication, so credentials stay under your identity controls. Ask your team to confirm which Azure region hosts the resource, who holds the roles needed to call it, and whether the data sent for scoring is acceptable under your data handling policy. The PyRIT float-scale scorer documentation is the reference to check the current normalisation and authentication behavior against before rollout.
Scorer options and when each fits
This table compares the Azure Content Safety scorer with the other PyRIT scorer types covered in this group, across what each measures, cost per call, and whether response data leaves your tenant. Read each row against your own harm categories and data rules, and treat the cost and data-flow entries as points to confirm in your environment rather than fixed facts.
| Scorer | What it measures | Cost and data leaving the tenant | When to choose it |
|---|---|---|---|
| Azure AI Content Safety scorer | Harm categories such as hate, sexual, violence and self-harm, returned on a 0 to 7 scale that PyRIT normalises to 0 to 1 | Calls the Azure Content Safety API on each scored response. Confirm billing and the data region with your Azure account team | Fast, category-based harm screening when Azure is already approved for your data |
| Self-ask LLM true/false judge | Whether your own objective was met, judged against a policy you write | Calls a judge model on each response. Cost depends on the judge model you choose, and data goes to that model's endpoint | Policy-specific questions that category scores cannot express |
| Self-ask Likert scorer | Degree of harm on a rating scale, using bundled or custom scales | Calls a judge model per response, so cost and data flow match the judge model chosen | When you need graded severity and thresholds for pass or fail |
| Refusal scorer | Whether the target declined the request or complied | Uses an LLM call by default, and can avoid one for fully blocked responses. Confirm the behaviour in your PyRIT version | Driving multi-turn decisions and separating blocked from compliant replies |
| Self-hosted classifiers (Llama Guard, ShieldGemma) | Policy categories defined by the classifier, scored on hardware you run | No external API call if you host the model. Cost is compute and operations you own | When response text must not leave your infrastructure |
How to set up the Azure Content Safety scorer with Entra ID
This sequence takes you from an Azure AI Content Safety resource to a working PyRIT harm scorer that authenticates with Entra ID, returns a score, and produces a value you can compare across scorers. Each step ends with a check so you know the layer below it works before you build on it.
Provision an Azure AI Content Safety resource
In the Azure subscription your security or platform team controls, create an Azure AI Content Safety resource in a region your data handling rules allow. Confirm the region, resource group and network access settings with your cloud owner before you create it, since these decide where prompts and responses are processed. Record the resource endpoint from the resource overview page. You know this step is done when the resource shows as deployed and the endpoint URL is visible in the portal.
Grant the scoring identity access through Entra ID
Create or select the identity that PyRIT will run as, such as a managed identity for a hosted runner or a developer account for local testing, and assign it a Cognitive Services role on the Content Safety resource that permits content analysis. Prefer Entra ID token authentication over API keys so that access is tied to a named identity you can review and revoke. Ask your identity team to confirm the role assignment is scoped to this one resource. You know this step is done when the identity appears in the resource's access control list with the role you chose.
Set the endpoint in the PyRIT environment file
Add the endpoint to the PyRIT credentials file at ~/.pyrit/.env as AZURE_CONTENT_SAFETY_API_ENDPOINT, using the value copied from the resource overview. Do not store an API key in this file when you use Entra ID, and keep the file out of source control and out of shared drives. Check that the file is readable only by the account that runs PyRIT. You know this step is done when a Python session started under the same account can read the variable and it matches the resource endpoint exactly.
Authenticate the session with your Azure identity
Sign in with the Azure identity from the previous step, either through the Azure CLI for a developer workstation or through the managed identity on a hosted runner, so that the credential PyRIT obtains comes from Entra ID. Confirm that no key-based fallback is configured in your environment. Run a simple token request against the Azure management or Cognitive Services scope to confirm the credential resolves. You know this step is done when the token request returns a token for the identity you expect, and not for a different account on the same machine.
Instantiate the AzureContentFilterScorer
In a Python script or notebook that imports PyRIT, create an AzureContentFilterScorer instance and pass it the harm categories you intend to score, such as hate, sexual, violence and self-harm. Keep the scorer object in the same place as the rest of your scoring configuration so that later runs use the same category set. Check the PyRIT documentation for the constructor arguments in the version you have pinned, because parameter names change between releases. You know this step is done when the script constructs the scorer without raising an authentication or configuration error.
Score a known test prompt
Send a short, known test response to the scorer, using a benign example and one that your red team has already agreed should trigger a harm category, and inspect the returned score objects. Use test text that your policy owners approve for this purpose and store it in your repository with the test. Confirm that each score returns a value, the category name matches what you asked for, and the benign text scores at the low end. You know this step is done when both examples return results you can explain.
Verify the normalised score falls between 0 and 1
Azure Content Safety reports on a native 0 to 7 severity range, and PyRIT normalises it to a float between 0 and 1 for its float-scale scorers. Check that every returned value falls within that normalised range and that the mapping matches the PyRIT documentation for the version you run. Record a small table of input, native behaviour and normalised output in your test notes so that threshold decisions made later can be traced. You know this step is done when every test value is between 0 and 1 and the table is saved with the test run.
How the 0 to 7 scale becomes 0 to 1 and what thresholds mean
Azure AI Content Safety reports harm on a native 0 to 7 range, and PyRIT normalises that value to a float from 0 to 1. The AzureContentFilterScorer returns the normalised float, so every category you score lands on the same scale that PyRIT's other float-scale scorers use. Your results will not show the raw Azure severity number unless you record it separately, so check what your memory export holds before you write reports that quote Azure's original values. Confirm the exact normalisation arithmetic in the PyRIT Float-Scale Scorers documentation for the version you run, rather than assuming a linear mapping you have not verified.
PyRIT does not decide what counts as a failure. Your team sets a pass or fail threshold on the float score, and any response above that value is flagged as a finding. Pick the threshold with the policy owner, the person who answers for the harm policy the model must meet, because a threshold is a policy decision about tolerated risk, not an engineering default. Record the threshold, the date it was agreed and the approver in your test configuration so that a later reviewer can see why a result was counted as a fail. Use one threshold per harm category where the policy differs by category, and revisit it when the policy changes.
Before you map Azure's native severity bands to findings, read Azure's own documentation for the current band definitions and confirm them against the API version your deployment uses. Do not build a mapping from memory or from a blog post, and do not copy band boundaries from this page, because Azure can change its categories and definitions. Once confirmed, write the mapping down, test it on a few responses you have already labelled by hand, and check that the float thresholds produce the outcomes your reviewers expect. Treat that check as a starting point for the accuracy testing described later, not as proof that the scorer is correct.
How a PyRIT response flows to Azure Content Safety and back to memory
The flow starts with the PyRIT attack sending a prompt to the target, which is outside the client's Azure tenant. The target's response then passes to the AzureContentFilterScorer, which calls the Azure Content Safety API using Entra ID authentication. The API returns a harm rating on its native 0 to 7 range, and PyRIT normalises it to 0 to 1 before writing the score to memory in SQLite or Azure SQL. Check that the endpoint and credentials sit inside the tenant you intend to use, and that the stored score keeps its original value alongside the normalised one.
Data path from a PyRIT prompt through Azure Content Safety scoring into memory, with the trust boundary marked.
Security considerations for Entra ID and scored content
The Azure AI Content Safety scorer touches three sensitive things: an identity that can call your Content Safety resource, the model responses sent to that service, and the harmful text that ends up in memory and exports. Each card below covers one of these decisions and what to confirm before a test run.
Prefer managed identity over static keys
The scorer authenticates to the Content Safety endpoint set in AZURE_CONTENT_SAFETY_API_ENDPOINT using Entra ID. Use a managed identity where the test runner is hosted in Azure so no long-lived key sits in a file or pipeline variable. For developer laptops and CI runners outside Azure, confirm with your identity team which Entra ID method is approved and how sign-in is audited. Check that the scorer is not falling back to a key you did not intend to use.
Grant the Content Safety resource minimal roles
The identity that runs PyRIT needs only the data-plane permission to analyze text on the Content Safety resource, not subscription-wide contributor rights. Scope the role assignment to that one resource and keep administrative rights with a separate group. Review the assignment whenever a team member changes role, because a scorer identity that can also manage the resource can change its content filters and logging.
Map where response text travels
Each scored response is sent from your runner to the Content Safety API, and the target's output is stored in PyRIT memory before scoring. Before testing, document the Azure region of the Content Safety resource, the target model's data location, and any logging or retention settings on both services. Confirm these flows against current Azure documentation and your data processing terms, since PyRIT itself does not decide where data is kept.
Control harmful content in logs and exports
Red teaming produces prompts and responses that are themselves hate, sexual, violent or self-harm content. Set log levels so that conversation text is not written to console or application logs, and restrict who can open exported result files. Decide in advance how flagged examples are redacted before sharing a report, and tell reviewers what they are about to read.
Store secrets outside the repository
PyRIT reads credentials from ~/.pyrit/.env and settings from ~/.pyrit/.pyrit_conf, so a local file is the simplest place for any endpoint or key value. Never commit these files or paste them into tickets. For shared runners, move secrets into Azure Key Vault and inject them at run time. The team-wide practice for this, including Key Vault setup and configuration files, is covered in the PyRIT setup and configuration topic.
Questions buyers ask before scoring with Azure Content Safety
Does this scorer replace an LLM judge in PyRIT?
No. The Azure AI Content Safety scorer is a fast harm classifier for the hate, sexual, violence and self-harm categories, so it answers how harmful a response is in those categories. An LLM judge answers whether your own objective was met, which Azure's categories cannot express on their own. Most teams run both: the content safety scorer as a quick harm signal, and a judge or Likert scorer written for their policy. Treat the two as complementary and decide which verdict drives pass or fail before the first run.
Can our team set up the Azure Content Safety scorer alone?
Often yes, if your team already runs Python services and has Azure administration access. The work is installing PyRIT, creating or identifying an Azure AI Content Safety resource, setting AZURE_CONTENT_SAFETY_API_ENDPOINT, and authenticating with Entra ID rather than a shared key. The harder parts are tenant policy, role assignment and deciding how scores feed your pass or fail rules. Teams without Azure or identity experience usually find those steps take longer than the code does.
What is the setup effort based on?
The effort depends on how much of the environment already exists and how many people must approve it. The main inputs are whether an Azure subscription and Content Safety resource are available, how Entra ID is configured for workload identity, whether the scorer runs locally or in a pipeline, and how the results are stored in PyRIT memory. A scoped engagement lists these inputs first, then the configuration, verification and handover tasks, and DeployOpen sets the scope in writing before work starts.
How long does setup take if our Azure tenant is not ready?
Tenant readiness is the largest variable. If the subscription, resource and role assignments already exist, configuration is usually a short task. If an administrator must create resources, approve Entra ID app registrations or agree on network access, those approvals set the schedule, not the scorer. Ask your Azure administrator to confirm subscription ownership, resource creation rights and approval lead times before requesting a timeline, since no duration can be stated for your tenant without that information.
What drives the cost of scoring with Azure Content Safety?
There are two cost streams. The first is Azure: Content Safety calls are billed by Microsoft under your subscription, so cost grows with the number of responses scored, and you should confirm current rates on the Azure pricing page for your region. The second is the professional work: configuration, testing and documentation are billed as a scoped engagement or internal time. Azure cost recurs with every test run, while setup is largely one-time. Ask any partner for a quote that separates these components and states assumptions about test volume.
What must we provide before setup begins?
Provide an Azure subscription with permission to create or use an AI Content Safety resource, the Entra ID roles needed to register the workload identity and assign it to the resource, and a named owner for the test environment. You also need written test objectives: which categories matter for your product, what threshold counts as a failure, and which models or endpoints are in scope. Without the objectives, the scorer will produce numbers that nobody can turn into a decision.
Will Azure scores on a 0 to 7 scale be comparable with other scorers?
Only after normalization. Azure Content Safety reports on a native range of 0 to 7, and PyRIT normalizes that to a 0 to 1 float score so it can be compared with other float-scale scorers. Engineers should confirm the mapping and the threshold they apply to it, then record both raw and normalized values in memory. Thresholds chosen on one scale do not carry over to another without a check against labeled examples.
Where to read the scorer documentation
The primary reference for the AzureContentFilterScorer is the PyRIT documentation page for float-scale scorers, which explains how the Azure AI Content Safety scorer is configured and how its output is represented. Read that page before you write any configuration, because the scorer's behavior depends on details that are easy to assume wrongly, such as which API the scorer calls, how it authenticates, and what range its scores come back in. Treat the documentation as the baseline for the version of PyRIT you have installed, and check it against the release you pin rather than against examples you saw in older blog posts or repository forks.
Before you configure anything, verify four things on that page: the endpoint setting that points the scorer at your Azure AI Content Safety resource, the Entra ID authentication path you plan to use instead of a shared key, the native 0 to 7 score range and how PyRIT maps it to the 0 to 1 scale, and the harm categories the scorer reports. Confirm the exact environment variable names with your own team's configuration standard, since a mismatch here fails quietly in some setups. Record the PyRIT version and documentation version you checked, so that a later upgrade can be reviewed against the same expectations and the normalization logic in your results stays traceable.
How DeployOpen works on this
DeployOpen plans and delivers Scoring with Azure AI Content Safety in PyRIT as a fixed-scope piece of work, agreed in writing before build starts. The work covers the Entra ID setup, endpoint configuration, scorer wiring and normalization of the 0 to 7 scale, all inside infrastructure your organization controls.
How we scope
- Confirm which Azure AI Content Safety resource, region and Entra ID tenant the scorer will call
- List the harm categories in scope: hate, sexual, violence and self-harm, with the threshold each one maps to
- Agree which PyRIT targets and memory backend (SQLite or Azure SQL) the scored results will be written to
- Record the written scope, deliverables and timeline before any configuration begins
How we build
- Configure the AZURE_CONTENT_SAFETY_API_ENDPOINT setting and Entra ID authentication without embedding static keys
- Wire the AzureContentFilterScorer and map its native 0 to 7 output to the normalized 0 to 1 scale used in your pass or fail rules
- Test the scorer against known benign and harmful sample responses to confirm category results and score ranges
- Review secrets handling, least-privilege role assignments and logging of scorer calls against your security baseline
How we hand over
- Provide the configuration files, environment variable inventory and the scorer code as delivered artifacts
- Document the normalization formula, threshold decisions and the known limits of fast harm scoring for your team
- Walk your engineers through a sample run and the stored results in PyRIT memory so they can repeat it
- Deliver a runbook covering credential rotation, endpoint changes and what to re-check after a PyRIT upgrade
How we support
- Offer ongoing support, upgrades and continuous testing as a retainer after handover
- Re-verify the scorer when PyRIT releases change scorer behavior or when Azure AI Content Safety settings change
- Ask any provider to confirm current Azure AI Content Safety category behavior and quotas for your region before relying on it
- Scope retainer coverage in writing, with the same method used for the original engagement

