AWS.Bedrock.MAG 0.2.0-preview

Prefix Reserved
This is a prerelease version of AWS.Bedrock.MAG.
dotnet add package AWS.Bedrock.MAG --version 0.2.0-preview
                    
NuGet\Install-Package AWS.Bedrock.MAG -Version 0.2.0-preview
                    
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="AWS.Bedrock.MAG" Version="0.2.0-preview" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AWS.Bedrock.MAG" Version="0.2.0-preview" />
                    
Directory.Packages.props
<PackageReference Include="AWS.Bedrock.MAG" />
                    
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 AWS.Bedrock.MAG --version 0.2.0-preview
                    
#r "nuget: AWS.Bedrock.MAG, 0.2.0-preview"
                    
#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 AWS.Bedrock.MAG@0.2.0-preview
                    
#: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=AWS.Bedrock.MAG&version=0.2.0-preview&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=AWS.Bedrock.MAG&version=0.2.0-preview&prerelease
                    
Install as a Cake Tool

AWS.Bedrock.MAG

AWS backends for Microsoft's Agent Governance Toolkit. This package plugs AWS managed services into the toolkit's existing extension points, so a .NET AI agent gets Bedrock-backed policy, PII sanitization, and durable audit with about two lines of configuration.

  • Bedrock Guardrails policy backend: ML policy evaluation added alongside the toolkit's rule, OPA, and Cedar backends. Use a pre-created guardrail (GuardrailId) or define checks inline (InlineChecks) with no guardrail resource to manage. Fails closed on error.
  • Bedrock Guardrails PII sanitization: redacts or blocks 30+ PII entity types in MCP tool output.
  • CloudWatch audit sink: writes governance events to CloudWatch Logs with aggregated metrics.

Preview (0.1.0). The API may change while the toolkit's extension surface stabilizes.

Install

dotnet add package AWS.Bedrock.MAG

Targets net8.0. Requires Microsoft.AgentGovernance 5.0.0.

Use it

MCP server (primary)

Add WithBedrockGovernance after the toolkit's WithGovernance:

builder.Services.AddMcpServer()
    .WithGovernance(o => o.PolicyPaths.Add("policies/default.yaml"))  // Microsoft's toolkit
    .WithBedrockGovernance(o =>                                        // this package
    {
        o.Policy.GuardrailId    = "gr-abc123";
        o.EnablePiiSanitization = true;                               // ANONYMIZE tool output
        o.Audit.LogGroupName    = "/agent-governance/audit";
    });

Non-MCP agent (plain DI)

builder.Services.AddBedrockGovernance(o =>
{
    o.Policy.GuardrailId    = "gr-abc123";
    o.Audit.MetricNamespace = "AgentGovernance/Bedrock";
});
// Requires a GovernanceKernel already in DI (from the toolkit).

Imperative (you already hold a kernel)

var kernel = new GovernanceKernel(new GovernanceOptions { PolicyPaths = { "policies/default.yaml" } });

kernel.AddBedrockGuardrailsPolicy(o => o.GuardrailId = "gr-abc123");
using var audit = kernel.AddCloudWatchAudit(o => o.LogGroupName = "/agent-governance/audit");

Inline guardrail checks (no pre-created guardrail)

When you don't want to manage a Bedrock guardrail resource, define the checks inline. The policy backend calls InvokeGuardrailChecks with the categories/entities from the request; a check trips the deny when its score meets the configured threshold. Detection only — this mode does not mask text, so PII sanitization still needs GuardrailId.

builder.Services.AddBedrockGovernance(o =>
{
    o.EnablePiiSanitization = false;
    o.Policy.InlineChecks   = new GuardrailChecksOptions
    {
        ContentFilterCategories      = { "HATE", "INSULTS", "VIOLENCE" },
        PromptAttackCategories       = { "PROMPT_INJECTION", "JAILBREAK" },
        SensitiveInformationEntities = { "US_SOCIAL_SECURITY_NUMBER", "EMAIL" },
        SeverityThreshold            = 0.5,   // content filter + prompt attack
        ConfidenceThreshold          = 0.5,   // PII
    };
});

InlineChecks composes with every entry point (WithBedrockGovernance, AddBedrockGovernance, and the imperative AddBedrockGuardrailsPolicy); set either GuardrailId or InlineChecks. When both are set the pre-created guardrail wins.

Required IAM

The credentials the agent runs under need:

  • bedrock:ApplyGuardrail on the guardrail (policy and PII sanitization).
  • bedrock:InvokeGuardrailChecks (inline-checks policy mode; no guardrail resource is referenced).
  • logs:CreateLogGroup, logs:CreateLogStream, logs:PutLogEvents on the audit log group (audit sink).
  • cloudwatch:PutMetricData (audit metrics, when EmitMetrics is on).

The audit sink uses AWS.Logger.Core, which creates the log group and stream on first use, so the logs:Create* permissions are required.

Limitations

PII sanitization covers the text blocks of an MCP tool result, matching the toolkit's own sanitizer. A tool result's StructuredContent (structured JSON) is passed through unchanged. If a tool returns PII in StructuredContent, mirror it into a text block so the guardrail sees it. Sanitizing arbitrary structured output is a post-v1 follow-up.

Cost

This package calls billed AWS services: Bedrock Guardrails (priced per text unit evaluated, once for policy on the input and once for PII on the output; inline checks are billed on the same per-text-unit basis), CloudWatch Logs ingestion and storage, and CloudWatch custom metrics. Tune FlushInterval to trade audit latency against request volume.

License

Apache-2.0.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.2.0-preview 82 11/2/2026