Skip to main content
net10.0

AgentGuard guardrail adapter for Presidio PII detection/de-identification.

Published
Oct 18, 2026
today
Total Downloads
117
117

Install

dotnet add package AgentGuard.Extensions.Presidio --version 0.0.2
ProductVersions
.NET
net10.0

README

AgentGuard.Extensions.Presidio

Example

using AgentGuard.Core;
using AgentGuard.Extensions.Abstractions;
using AgentGuard.Extensions.Presidio;
using Microsoft.Extensions.DependencyInjection;
using Presidio;
using Presidio.DependencyInjection;
using Presidio.Enums;
using Presidio.Models;
using Presidio.Options;

var services = new ServiceCollection();
services.AddPresidioSDK(new PresidioSDKOptions
{
    AnalyzerBaseAddress = new Uri("http://localhost:5002"),
    AnonymizerBaseAddress = new Uri("http://localhost:5001")
});

var serviceProvider = services.BuildServiceProvider();

var analyzer = serviceProvider.GetRequiredService<IPresidioAnalyzer>();
var anonymizer = serviceProvider.GetRequiredService<IPresidioAnonymizer>();

var options = new PresidioRuleOptions
{
    Analyzer = analyzer,
    Anonymizer = anonymizer,
    Language = "nl",
    Operation = PiiOperation.Replace,
    Replacement = "<REDACTED>",
    AdHocRecognizers =
    [
        new PatternRecognizer
        {
            Name = "Dutch Postcode recognizer",
            SupportedEntity = "NL_POSTCODE",
            SupportedLanguage = "nl",
            GlobalRegexFlags = RegexFlags.Multiline | RegexFlags.DotAll,
            Patterns =
            [
                new Pattern
                {
                    Name = "Dutch Postcode",
                    Regex = @"\b[1-9][0-9]{3}\s?(?!SA|SD|SS)[A-Z]{2}\b",
                    Score = 1
                }
            ],
            Context = ["postcode"]
        }
    ]
};

var policy = new GuardrailPolicyBuilder()
    .RedactPresidioPii(options)
    .Build();

var input = "Peter Jansen, Dorpsstraat 10, 5678 CD Utrecht, [email protected]";
var result = await policy.EvaluateInputAsync(input);

Console.WriteLine(result.Text);

Sponsors

Entity Framework Extensions and Dapper Plus are major sponsors and proud to contribute to the development of AgentGuard.Extensions.

Entity Framework Extensions

Dapper Plus

Changes from Previous Version

No structural changes between v0.0.1-preview-02 and v0.0.2.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.