GovUK.Dfe.AI.Agents.Guardrails 0.0.5

Prefix Reserved
dotnet add package GovUK.Dfe.AI.Agents.Guardrails --version 0.0.5
                    
NuGet\Install-Package GovUK.Dfe.AI.Agents.Guardrails -Version 0.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GovUK.Dfe.AI.Agents.Guardrails" Version="0.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GovUK.Dfe.AI.Agents.Guardrails" Version="0.0.5" />
                    
Directory.Packages.props
<PackageReference Include="GovUK.Dfe.AI.Agents.Guardrails" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GovUK.Dfe.AI.Agents.Guardrails --version 0.0.5
                    
#r "nuget: GovUK.Dfe.AI.Agents.Guardrails, 0.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GovUK.Dfe.AI.Agents.Guardrails@0.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GovUK.Dfe.AI.Agents.Guardrails&version=0.0.5
                    
Install as a Cake Addin
#tool nuget:?package=GovUK.Dfe.AI.Agents.Guardrails&version=0.0.5
                    
Install as a Cake Tool

GovUK.Dfe.AI.Agents.Guardrails

Makes sure every model deployment, or agent version, your GovUK.Dfe.AI.Agents agents use has an Azure AI Foundry guardrail. Foundry then blocks:

  • harmful content (hate, sexual, violence, self-harm)
  • jailbreak attempts in the question
  • protected material in answers

Instructions planted in evidence or tool output (indirect attacks) need ScanEvidence and ScanToolOutput, which the app runs itself: see Which setting catches indirect attacks.

Set up

dotnet add package GovUK.Dfe.AI.Agents.Guardrails
"AiAgents": {
  "Guardrails": {
    "SubscriptionId": "<subscription id>",
    "ResourceGroup": "<resource group>",
    "Name": "briefing-guardrail",
    "Deployment": "gpt-5.1"
  }
}
builder.Services.AddAgents(builder.Configuration, agents => agents
    .AddAgents(BriefingAgents.All)
    .AddGuardrails());

You need these roles, all on the Foundry resource (not the project), where guardrails live:

Identity Role For
Every app Reader Checking the guardrail at startup
Apps using ScanPrompts, ScanEvidence or ScanToolOutput Cognitive Services User Scanning input with Prompt Shields, a data-plane call Contributor doesn't grant (on ContentSafetyEndpoint's resource if set)
A provisioning job Cognitive Services Contributor ApplyAsync; not needed if Bicep or Terraform creates the guardrail

Apply once, check everywhere

  • A provisioning job calls await guardrails.ApplyAsync(ct) (IFoundryGuardrailsService). It creates or updates the guardrail and assigns it to each deployment, writing only what differs.
  • Every app does nothing: at startup it checks each deployment has the guardrail, unweakened.
  • Infrastructure as code instead: create the guardrail in Bicep or Terraform and skip ApplyAsync; apps still check it, with only Reader.
  • Missing or weakened: startup fails, saying what's wrong ("RequireAtStartup": false only warns).
  • Resource Manager unreachable: startup warns, so an outage doesn't stop new instances ("FailWhenUnreachable": true fails instead).
  • Release check: the release gate's CheckReleaseAsync checks the guardrail before any agent is tested, and fails every agent while it's missing or weakened (see the Evaluation package's release gate).
  • Metric: every check counts dfe.ai_agents.guardrail.checks once per agent the app runs, with its outcome and whether ApplyAsync made it. It shows whether an agent's safety net was in place when it was released. See Release metrics.

Models through a connection

When Foundry:DefaultModel is <connection>/<model>, the deployments aren't in your Foundry resource, so the guardrail goes on the agents. That's the default then; no Targets or Deployment is needed:

"Guardrails": {
  "SubscriptionId": "<subscription id>",
  "ResourceGroup": "<resource group>",
  "Name": "briefing-guardrail"
}
  • ApplyAsync creates or updates only the guardrail and blocklists.
  • Every agent version the app creates gets the guardrail, by its full Resource Manager ID (it becomes Foundry:Guardrail).
  • The startup check confirms each pinned or externally managed version has it, e.g. agent 'rsd-trust-agent' version 4 uses no guardrail. Fix by provisioning a new version.
  • "Targets": "Deployments, Agents" does both.

Settings

Setting Default Purpose
SubscriptionId, ResourceGroup Required Where the Foundry resource is
AccountName The resource in Foundry:Endpoint Set only if the deployments are on another Foundry resource
Name Required The guardrail's name in Foundry
Targets Agents on a connection Where the guardrail goes: Deployments, Agents, or both. Otherwise Deployments
Deployment Required for Deployments Plain text, e.g. "gpt-5.1"; several are separated by commas
BlockFrom Medium Lowest harm severity blocked in prompts and answers. Low blocks the most
PromptShields true Blocks jailbreak attempts
IndirectAttacks true The guardrail's indirect attack filter; not relied on for evidence or your tools' output (why)
CheckBlocklists false Checks each run's question and evidence against Blocklists in the app (see below)
ScanPrompts false Scans each run's question with Prompt Shields before it's sent (see below)
ScanEvidence false Scans each run's evidence with Prompt Shields before it's sent (see below)
ScanToolOutput false Scans the output of each tool your app runs with Prompt Shields before the model reads it (see below)
ContentSafetyEndpoint The Foundry resource's own The Content Safety endpoint ScanPrompts, ScanEvidence and ScanToolOutput call
ProtectedMaterial true Blocks answers that reproduce protected text or code
Blocklists None Your own blocked terms and patterns (see below)
RequireAtStartup true Fails startup when a deployment or agent version lacks the guardrail
FailWhenUnreachable false Fails startup when the guardrail can't be checked, e.g. Resource Manager is unreachable
Authentication The default identity A separate identity for Resource Manager (or agents.UseGuardrailsCredential(...) in code)

Blocklists

Block your own terms, such as project code names or case reference formats:

"Blocklists": {
  "case-references": { "Terms": [ "Project Falcon" ], "Patterns": [ "CASE-\\d{6}" ] }
}

ApplyAsync creates each blocklist with exactly these entries, for prompts and answers. The startup check reports a blocklist that's detached or missing entries, by count only. Load sensitive terms from Key Vault, not appsettings.json.

When a guardrail blocks something

The run fails with an inner AgentGuardrailException (Stage: prompt, answer, evidence or tool_output), counted by dfe.ai_agents.guardrail.blocks. In parallel and sequential runs, the agent gets a fallback result instead. Core reports blocks with or without this package.

Which setting catches indirect attacks

An indirect attack is an instruction planted in material the agent reads, e.g. a search result telling it to reveal data. Where it can come from decides what catches it:

Planted in Caught by Why not the guardrail's IndirectAttacks
Evidence you pass, e.g. search results, documents, earlier answers ScanEvidence Evidence is sent in Foundry's <documents> format, but Foundry documents scanning that format only for model calls, not for agents' input, so it isn't relied on
Output of tools your app runs, e.g. MCP servers, AddTools ScanToolOutput Foundry scans tool responses only for its own tools, e.g. Azure AI Search or Bing Grounding, in preview (intervention points), never the output of tools your app runs
Any input, for a model behind your own gateway ScanEvidence and ScanToolOutput No Foundry guardrail runs there at all
  • So, for indirect attack detection, turn on ScanEvidence and, if agents call tools, ScanToolOutput. Keep IndirectAttacks on too: it covers Foundry's own tools, and the startup check refuses a guardrail with it turned off.
  • Prove it: a release-gate test case with planted instructions in its evidence and "guardrailMustBlock": true passes only when your configuration blocks it.

Checking input in the app

A Foundry guardrail isn't relied on to scan evidence (see above), and doesn't apply at all to a model behind your own gateway (Bring your own model). So the app can check each run's input itself, after redaction and before anything is sent. A match blocks the run like a guardrail block, with the reason in AgentGuardrailException.Reason:

Setting Checks How Blocks with Stage
CheckBlocklists The question and the evidence against Blocklists In the app, no call to Azure; first prompt or evidence
ScanPrompts The question, for jailbreak attempts Prompt Shields, one call prompt
ScanEvidence The evidence, for planted instructions Prompt Shields, one call per 9,000 characters, up to 4 at a time (8 across the app) evidence
ScanToolOutput Each tool's output, for planted instructions Prompt Shields, as evidence; a round's outputs side by side, after capping and redaction, before the model reads them tool_output
  • Endpoint: https://<resource>.cognitiveservices.azure.com/, unless ContentSafetyEndpoint is set.
  • Cost: the question and evidence scans run side by side, about 100–200 ms for a typical run; ScanToolOutput adds about as much to each round of tool calls. Blocklists cost nothing.
  • Fails closed: if input or tool output can't be scanned, e.g. because the role is missing, the run fails rather than sending it.
  • Busy service: at most 8 Prompt Shields calls are in flight at once across the app, however many agents run in parallel (e.g. a release gate's MaxParallelTestRuns); the rest wait their turn. A call that's throttled, fails with a server error or takes over 30 seconds is retried up to 3 times. One that still times out fails its run with a TimeoutException: in the release gate, that case fails and the others still run.
  • Release gate: test cases with "guardrailMustBlock": true prove each check works.
  • Your own: register an IInputShield for other checks of the question and evidence, or an IToolOutputShield for tool output.

Not included

PII filtering: Foundry's PII filter is in preview model, and this package uses GA APIs only. If you need it, turn it on in the Foundry portal; the startup check leaves it alone. Currently, managing with regular expressions by creating a blocklist.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.5 238 11/12/2026
0.0.5-prerelease.6 65 11/12/2026
0.0.5-prerelease.3 60 11/12/2026
0.0.4 137 11/4/2026
0.0.4-prerelease.2 64 11/4/2026
0.0.3 72 11/4/2026
0.0.3-prerelease.98 86 11/4/2026
0.0.3-prerelease.81 63 11/4/2026
0.0.3-prerelease.65 69 11/4/2026
0.0.3-prerelease.50 66 11/3/2026
0.0.3-prerelease.36 70 11/3/2026
0.0.3-prerelease.23 64 11/3/2026
0.0.3-prerelease.11 65 11/3/2026
0.0.2 120 10/30/2026
0.0.2-prerelease.2 60 10/30/2026
0.0.1 70 10/30/2026
0.0.1-prerelease.5666 76 10/30/2026
0.0.1-prerelease.5551 67 10/30/2026
0.0.1-prerelease.5437 64 10/30/2026
0.0.1-prerelease.5324 60 10/30/2026
Loading failed