Llama Guard and ShieldGemma scorers in PyRIT

Llama Guard 3 and ShieldGemma let you score PyRIT attack responses with open safety classifiers you host yourself, provided the policy you test against matches what each classifier covers.

On this page

When a self-hosted safety classifier should decide whether a PyRIT attack worked

A self-hosted safety classifier should decide whether a PyRIT attack worked when the responses under test cannot leave your environment and a hosted safety API would send them to a third party. In that situation, PyRIT's LlamaGuardScorer and ShieldGemmaScorer let you classify model output text against safety guidelines on infrastructure you control. Both scorers are true/false classifiers in PyRIT's scoring layer, so each returns a verdict on whether the response violates the guideline it was given. The team still has to decide which classifier fits, where it runs, and whether its verdicts are trustworthy enough to count as findings.

The scorer only means something when its taxonomy matches the policy under test. The bundled LlamaGuardScorer targets meta-llama/Llama-Guard-3-8B and its S1 to S14 hazard taxonomy, so a team that tests against a different category list needs a matching policy or must map its own categories onto that taxonomy before reading results. ShieldGemmaScorer takes one ShieldGemma safety guideline per request, which means the guideline set is a design decision you make, not a default you inherit. Before any run, write down each harm category your policy covers and confirm which guideline or taxonomy entry addresses it, including gaps where no entry exists.

Plan the hosting before the test plan is final. Confirm with your model team which Llama Guard variant and which ShieldGemma release you can serve, what endpoint PyRIT will call, and who owns uptime and patching for that endpoint, since a classifier that is down during a run produces no verdicts. Keep a small labeled set of responses from your own system and check the classifier against it, so you know its agreement with your reviewers before you report a pass or fail. The PyRIT documentation describes the scorer setup for the version you install.

How a response flows from target to Llama Guard or ShieldGemma verdict

The flow starts with a PyRIT attack that sends a prompt to the target and receives a response. PyRIT stores that conversation in memory, then the Llama Guard or ShieldGemma scorer sends the response text to a classifier endpoint you host. Each ShieldGemma guideline is a separate request, and the verdict returns as a true/false score written back to memory and reporting. Check that the classifier endpoint sits inside your boundary, that the memory store is where your records must live, and that each guideline request is logged.

Response text flows through PyRIT memory to a self-hosted classifier, with verdicts stored as scores.

Choosing between LlamaGuardScorer, a ShieldGemmaScorer per guideline and a composite

This table compares the three ways to build a safety verdict with these classifiers: one Llama Guard call, one ShieldGemma call per guideline, or a composite of several. Read each row against your own policy, since the classifiers only judge what their taxonomy or guideline covers. The main takeaway is that the policy you need to enforce should decide the option, and the call count and cost follow from that.

Decision factorLlamaGuardScorerShieldGemmaScorer per guidelineComposite of ShieldGemma scorers
What it checksText against a Llama Guard category set in one classificationText against one ShieldGemma safety guideline per requestText against every guideline in your policy, combined into one verdict
Taxonomy assumedBundled default targets meta-llama/Llama-Guard-3-8B and its S1 to S14 taxonomyThe guideline text you supply for each scorerThe guidelines you chose, one scorer each
Classifier calls per verdictOne call to the Llama Guard endpointOne call per guidelineOne call per guideline, combined with TrueFalseCompositeScorer
Non-default variantsNeed a policy that matches the variant's categories, confirmed before useNot applicable, since each guideline is supplied directlyDepends on the guidelines and variants you combine, so confirm each one
Fits best whenYour policy maps cleanly onto the S1 to S14 categories and you want one call per responseYou need fine-grained guideline control and can accept more callsYour policy has several guidelines that must all be covered in one verdict
Main riskHarms outside the taxonomy go unscored unless you add a matching policyGaps appear if a guideline is missing from the setCall volume and latency grow with each added guideline
What to confirmYour endpoint, model variant and category mapping against the PyRIT sourceThe guideline wording and the model version your endpoint runsHow the composite logic matches your pass or fail rule

How to split a policy into ShieldGemma guidelines

ShieldGemma scores one guideline per request, so the work of covering a full policy starts before any code runs. The decisions below connect your written clauses to the guideline list, the composite logic that combines results, and the records you will need when someone asks why a response passed.

Map each clause to one guideline

Start from the internal policy text and find, for each clause, the ShieldGemma guideline that matches it most closely. Write the mapping down as a table with one row per clause. A clause that needs two guidelines to be covered is a sign the policy is broader than the classifier, so note it for review. Check that the guideline wording you use is the wording PyRIT sends, because a close match in your head may not match the classifier's definition.

ShieldGemma scorer source

Route unmatched clauses to other scorers

Some clauses will have no ShieldGemma guideline at all, such as rules about data handling, brand statements or domain-specific advice. Do not force these into the nearest guideline. Assign each unmatched clause to another scorer, such as an LLM judge with your own question or a refusal check, and record that assignment. Otherwise the composite will report coverage that the policy does not actually have.

Choose any-pass or all-pass logic

A TrueFalseCompositeScorer can require all of its guideline scorers to flag a response, or only one of them. Any-pass logic catches more violations but raises the false alarm rate, since one noisy guideline can fail a response. All-pass logic is stricter about what counts as harmful, so it can miss a violation that only one guideline sees. Decide which behavior matches the consequence of each clause, and document the choice per clause group rather than once for the whole policy.

Handle overlapping clauses

Two policy clauses about violence or self-harm may both map to the same guideline, and a single response can trigger several guidelines at once. Decide whether overlapping clauses share one scorer result or whether each clause gets its own score. Shared scores are simpler to report, while separate scores show which clause was breached. Test a few responses that touch two clauses to confirm the composite reports what you intended.

Count the cost of one request per guideline

Each ShieldGemma guideline is a separate classifier request, so a policy with many clauses sends many requests for each scored response. Time and compute grow with the number of guidelines, not with the length of the policy. Ask your team to estimate the total request count per response and per test run before you commit to full coverage, and confirm the classifier hosting capacity can handle that load.

Record the guideline list for audits

Save the exact guideline list, the policy version, the mapping table and the composite logic with each test run. Without these records, a result from six months ago cannot be explained or reproduced after the policy or the scorer configuration changes. PyRIT memory can store the scoring results, so link each run to the configuration version that produced it. Keep the records in a format an auditor can read without running PyRIT.

Matching your policy to the Llama Guard S1 to S14 taxonomy

PyRIT's LlamaGuardScorer ships with a default that targets meta-llama/Llama-Guard-3-8B and its S1 to S14 category taxonomy. That default only makes sense if your test policy uses the same categories. If your organization defines harms differently, for example by splitting privacy from fraud, or by folding self-harm into a broader wellbeing category, the verdicts the scorer returns will not map cleanly onto your risk register. A "safe" or "unsafe" result is only meaningful against the categories the model was asked to judge, so the first task is to confirm which categories apply to your deployment.

Start with a mapping table. List each harm category in your policy, then record which S1 to S14 category, if any, covers it and how closely. Expect three kinds of gap: harms in your policy with no matching category, taxonomy categories that your policy never tests, and categories that cover two of your harms at once. Each gap needs a decision. You can accept a partial mapping and document the uncovered harms as untested by this scorer, or you can use a different Llama Guard variant whose published policy matches your categories and configure the scorer to that variant. Choosing a variant changes both the model you host and the category text the scorer sends, so the two must be changed together, and the mapping table should be rebuilt for the new variant.

Before you finalize the table, confirm the category list against the model card for the exact model you deploy, not against this page or the default in the source. Check the category names and descriptions the model card publishes, and record the model version, quantization and the policy text in your test records. The mapping is a design artifact that auditors and reviewers will ask about, so keep it under version control with the PyRIT version and scorer configuration used for each test run.

Setting up a Llama Guard or ShieldGemma scorer in PyRIT

This sequence takes a team from a clean Python environment to a working open safety classifier scorer in PyRIT, with a check at each step so problems surface before any red teaming results depend on the verdicts.

  1. Install PyRIT on a supported Python version

    Create an isolated virtual environment and install PyRIT from PyPI with pip. The PyPI package supports Python 3.10 up to but not including 3.15, and the PyRIT documentation recommends Python 3.13, so pick that version if your platform team has it available. Confirm the install by importing the package in a Python session and printing its version, which should match the release you pinned, v1.1.0 in this sequence. Record the version in your test plan so later scorer results can be traced to the code that produced them.

  2. Host or reach the classifier endpoint

    Decide whether the classifier runs on your own GPU hosts or behind an internal inference service, then make it reachable from the machine that runs PyRIT. The LlamaGuardScorer expects a Llama Guard endpoint, and the bundled default targets meta-llama/Llama-Guard-3-8B with its S1 to S14 taxonomy. ShieldGemma scorers send one ShieldGemma guideline per request. Confirm the endpoint with a direct test request from the PyRIT host using a single benign and a single clearly unsafe sample, and check that it returns a classification rather than a connection or format error.

  3. Store endpoint credentials in the PyRIT environment file

    Place the endpoint address and any access token in the environment file at ~/.pyrit/.env rather than in notebook cells or scripts, so credentials stay out of source control and shared run logs. Keep the file readable only by the account that runs PyRIT. The exact configuration key names for the Llama Guard and ShieldGemma scorers should be confirmed against the v1.1.0 source files before you write them. Verify the setup by loading the scorer in a fresh session without passing the secret as a parameter. A clean load with no authentication error shows that the file is being read.

  4. Configure the scorer with your policy or guideline list

    Instantiate the scorer with the policy it should enforce. For Llama Guard, the bundled default uses the S1 to S14 taxonomy, so any other Llama Guard variant needs a policy that matches the categories it was trained on. For ShieldGemma, create one scorer per safety guideline you need to cover, then combine them with a TrueFalseCompositeScorer. Confirm the category list against your written policy and record which guideline each scorer covers. Check the configuration by scoring one sample and reading the returned category label, which should name a category from the list you configured.

  5. Run a labeled test set of known responses

    Build a small set of responses that humans have already labeled as safe or unsafe, including borderline cases that sit near your policy edges. Score each one with the configured scorer and compare the verdicts to the human labels, counting false positives and false negatives separately. The purpose is to find out whether the classifier agrees with your policy before its verdicts drive red teaming decisions. Treat this set as a baseline and keep it under version control so later scorer changes can be re-tested against the same data. For a more formal accuracy check, see the sibling topic on measuring PyRIT scorer accuracy.

  6. Confirm results are written to memory

    Run a short attack or a direct scoring call through the configured scorer and confirm the scores are saved in PyRIT memory. PyRIT memory stores conversations and results in SQLite or Azure SQL, so check the database that your configuration points to and find the new score records linked to the prompt and response. If the records are missing, the verdicts will not be available for later review, batch rescoring or evidence export. Only after this check passes should the scorer be used in an attack run that informs findings.

Security and operational risks of self-hosted classifier scoring

Running Llama Guard or ShieldGemma yourself moves the scoring path into your infrastructure, so the endpoint, its secrets, the stored transcripts and the model version all become part of your security and operations scope. The cards below cover the decisions that keep scoring trustworthy and the people who can see its results.

Endpoint placement and network reach

The classifier endpoint receives every prompt and response you score, so it holds the same sensitive content as the target under test. Decide where it runs, which subnets or services can call it, and whether it is reachable from outside your test network. Confirm that the PyRIT host is the only client allowed to call it, and that its logs do not capture full request bodies unless you have a reason to keep them.

Endpoint credentials outside source control

If the classifier endpoint requires an API key or token, keep it in ~/.pyrit/.env or a secrets manager rather than in notebooks, scripts or configuration committed to a repository. Rotate the credential on a schedule and after any staff change, and confirm that CI runners receive it through their own secret store. Treat a leaked key as a reason to rotate immediately, not to wait for the next test cycle.

Harmful content stored in memory

PyRIT memory records the test prompts, the model outputs and the scores, and some of those outputs contain the harmful content the test was meant to find. Whether the database is SQLite on a laptop or Azure SQL, apply access control, encryption at rest and a retention rule that you can explain to your compliance team. Restrict who can export conversations, because an export copies the harmful text out of the controlled store.

Capacity sizing and scoring throughput

Each ShieldGemma request scores one guideline, so a full policy multiplies the number of classifier calls by the number of guidelines. Llama Guard scoring runs one classification per response. Capacity for the endpoint, including GPU memory and concurrency, sets how many responses can be scored per run. Measure throughput with a representative batch before you size the run window, and confirm the classifier serving stack handles the concurrency PyRIT sends.

Pinning the classifier version

A verdict from a classifier is only comparable across runs if the model and its policy stay the same. Pin the exact checkpoint, such as the Llama Guard 3 8B variant the bundled default targets, and record it with each result. Changing the checkpoint, quantization or serving template can shift the verdicts without any change in the target. If you use a different Llama Guard variant, confirm that its taxonomy matches the policy your scorer is written against.

Reporting PyRIT vulnerabilities privately

If a test shows that PyRIT itself behaves unsafely, such as a flaw in how it handles credentials or memory, report it privately through the Microsoft Security Response Center under the project's security policy instead of a public issue. Record who reported it, when, and what fix you verified, because a reviewer may ask for that trail. Keep the report separate from the harmful model outputs stored during testing.

PyRIT on GitHub

Proving that per-guideline ShieldGemma scorers cover the whole policy

A set of ShieldGemma scorers covers a policy only when every clause in that policy maps to at least one guideline. Coverage is a property you prove, not one PyRIT gives you by default. PyRIT's ShieldGemmaScorer classifies text against one ShieldGemma safety guideline per request, so a policy with ten clauses needs a deliberate mapping from each clause to one or more guideline scorers before any verdict can be trusted as policy-wide. Start by writing the policy as a numbered list of clauses, then build a coverage matrix with clauses as rows and the ShieldGemma guidelines you run as columns. Mark each cell where a guideline addresses a clause, and treat any row with no marks as an uncovered clause that needs either a new guideline or an explicit decision to leave it to another scorer.

Next, combine the per-guideline verdicts with TrueFalseCompositeScorer and test the combined result against a labeled set. The composite is documented in PyRIT as the way to merge several scorers into one result for a policy, but the aggregation rule it applies to multiple true or false verdicts should be confirmed in the v1.1.0 source before you rely on it. Build a labeled set in which each clause has its own examples, including responses that should violate it and responses that should not. Run every guideline scorer over the whole set, record each verdict per clause, and compare results with the human labels. Keep the raw per-guideline results in PyRIT memory so each verdict can be traced later.

Then review two groups of results: clauses that produced no verdict and clauses where guideline scorers disagree. A missing verdict usually means the mapping is wrong, the guideline does not match the clause wording, or the scorer failed on that input, so check the run log before assuming the content is safe. Conflicting verdicts on the same clause mean the guidelines overlap or are worded differently, and the matrix should record which guideline is authoritative for that clause. Confirm with the scorer owners how each conflict will be resolved in the composite, and document that decision alongside the matrix so a reviewer can follow how a clause was judged.

Limits to confirm before relying on these scorers

A Llama Guard or ShieldGemma verdict is only as useful as the match between the classifier, the policy it was given and the content you test. The cards below cover what to confirm in your own environment before any pass or fail result feeds a release decision or an audit file.

Classifier variant matches the taxonomy

The bundled default targets meta-llama/Llama-Guard-3-8B and its S1 to S14 taxonomy. If your endpoint runs a different Llama Guard variant or a fine-tuned build, its category codes may differ, so a hit on one code may not mean what your policy expects. Confirm the exact model name and version your endpoint serves, then check that every category your policy uses maps to a code the classifier actually returns.

LlamaGuardScorer source

Coverage outside the training focus

Open safety classifiers are trained on particular languages, domains and content formats. Test your own prompts in each language your users write in, and in each format your target returns, such as code, tables, transcripts or image descriptions. Record where the classifier misses harmful content or flags benign content, because those gaps decide whether a scorer can be trusted for that population.

Agreement with human labels

A classifier's verdict is a prediction, not ground truth. Have trained reviewers label a sample of your own responses without seeing the classifier output, then compare the two. Look at both false negatives, where harmful output passes, and false positives, where refusals or safe answers are failed. Keep the labeled set so you can repeat the comparison later.

Scorer accuracy measured before use

Exact accuracy, precision and recall figures for these scorers depend on your model, your policy and your data, so they must come from your own test rather than from a published number. Use the objective metrics and inter-rater checks described in the scorer accuracy guidance, set a minimum acceptable level for your use case, and document the result alongside the scorer's configuration.

Endpoint protocol and request format

The scorer sends prompts in a format the classifier expects, and the endpoint must return output the scorer can parse. Confirm the chat template, the role structure, the response format and any authentication your hosting stack requires, using a few known-safe and known-unsafe test strings. A silent mismatch can return malformed or empty verdicts that look like passes.

Verdict drift after model updates

Pinning a model version prevents silent changes, but when you upgrade the classifier, weights, quantization or serving stack, verdicts can shift. Re-run your labeled set after every change, compare results with the previous version, and keep the old version available until the comparison is accepted. Treat each scorer change as a change to your evidence, and record it in your test history.

What buyers ask about Llama Guard and ShieldGemma scoring in PyRIT

What does a Llama Guard and ShieldGemma scoring setup cost, and what drives the price?

The cost depends on the written scope, which is the only basis for a quote. The main components are policy mapping (turning your guidelines into the categories each classifier will judge), hosting the classifier endpoints on infrastructure you control, building a labeled test set to check verdicts, and wiring the scorers into PyRIT. Cost rises with the number of guidelines, because ShieldGemma runs one scorer per guideline and each needs its own mapping and checks. Hosting cost is mostly accelerator capacity you pay for in your own environment, which recurs. DeployOpen does not publish a price list, so ask for a quote that separates one-time build work from recurring hosting and upkeep.

How long does it take to set up Llama Guard or ShieldGemma scoring?

Duration depends on how quickly your policy owners agree the guidelines, how many guidelines you need, whether endpoints are already available, and how much labeled test data exists. Hosting approvals and storage reviews in your organization often set the pace more than the PyRIT code does. The fixed-scope agreement records the timeline in writing before work starts, so ask for the milestones and the client dependencies that each one waits on.

What does our team need to provide before the work starts?

Plan to provide access to GPU capacity or a model endpoint in your environment, named policy owners who can settle what counts as a violation, a set of labeled example prompts and responses for checking verdicts, and approval to store test conversations in the memory backend you use. Llama Guard 3 is the bundled default in PyRIT and targets the meta-llama/Llama-Guard-3-8B model with its S1 to S14 taxonomy, so confirm with your legal and model owners that this model and its license fit your use. Other variants need a matching policy, which means the policy owners must be involved early.

Can an internal team set up Llama Guard and ShieldGemma scoring alone?

A team with Python, PyRIT and model-serving experience can build the scorers itself, because PyRIT exposes LlamaGuardScorer and ShieldGemmaScorer as classes. The harder parts are usually policy mapping, writing per-guideline ShieldGemma scorers, combining them with TrueFalseCompositeScorer so they cover the whole policy, and measuring whether the verdicts agree with human reviewers. Ask yourself whether someone owns those tasks and can keep them current when a guideline or model version changes.

Is the Llama Guard and ShieldGemma scoring work a fixed-scope engagement?

Most DeployOpen engagements are fixed-scope, so the scope, deliverables and timeline are agreed in writing before work starts. For this topic, the written scope would list the guidelines to cover, the classifier models and hosting approach, the labeled test set, the PyRIT integration and the handover. Ongoing support, model updates and continuous testing can be added as a retainer. Ask for the written scope before comparing quotes, so each party is pricing the same work.

How do I know whether a ShieldGemma verdict is reliable for my policy?

Reliability comes from checking verdicts against labeled examples that reflect your own policy, not from the classifier's default categories. Build a test set that includes clear violations, clear allowed content and borderline cases, then compare scorer output with human labels. Record the guideline each ShieldGemma scorer checks so a failing verdict can be traced to a single rule. Confirm with the model owner which ShieldGemma version you run, because the guideline wording and behavior are tied to that model.

Where should the classifier run, and does that affect compliance review?

Host Llama Guard or ShieldGemma in infrastructure you control so that test prompts and model responses stay inside your approved boundary. This keeps the scoring step aligned with the data handling rules your compliance and security teams review. The hosting choice also sets the accelerator capacity, endpoint security and logging you must maintain. Confirm the storage rules for test conversations with your compliance team before the first run.

How DeployOpen scopes and delivers PyRIT scoring work

DeployOpen plans and builds the PyRIT scoring setup around your own policy, so Llama Guard and ShieldGemma verdicts can be explained and reviewed. We host the classifier endpoints in infrastructure you control, map each guideline to a scorer, and document how the results were produced.

How we scope

  • Written scope names the policy, the responses to score and the target models under test.
  • Scope confirms which Llama Guard or ShieldGemma variants you will host and their license terms.
  • Scope lists each ShieldGemma guideline to cover and how composite results map to pass or fail.

How we build

  • We deploy the classifier endpoints in your infrastructure and connect them to PyRIT scorers.
  • We check that any non-default Llama Guard policy matches the taxonomy the scorer expects.
  • We combine per-guideline ShieldGemma scorers with composite logic and test them on labeled sample responses.

How we hand over

  • You receive configuration, scorer code and a record of the policy-to-scorer mapping.
  • Documentation covers how to run, rerun and interpret scoring results stored in PyRIT memory.
  • Handover includes a walkthrough with your security and AI teams and a retest of the final setup.

How we support

  • Ongoing support is available as a retainer for scorer updates and PyRIT version upgrades.
  • Retainers can cover re-checking scorer behavior when you change models, guidelines or endpoints.
  • Ask your quote to separate one-time build effort from recurring support and hosting responsibilities.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.