ManagedCode.Presidio.Structured 0.0.2

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package ManagedCode.Presidio.Structured --version 0.0.2
                    
NuGet\Install-Package ManagedCode.Presidio.Structured -Version 0.0.2
                    
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="ManagedCode.Presidio.Structured" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ManagedCode.Presidio.Structured" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="ManagedCode.Presidio.Structured" />
                    
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 ManagedCode.Presidio.Structured --version 0.0.2
                    
#r "nuget: ManagedCode.Presidio.Structured, 0.0.2"
                    
#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 ManagedCode.Presidio.Structured@0.0.2
                    
#: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=ManagedCode.Presidio.Structured&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=ManagedCode.Presidio.Structured&version=0.0.2
                    
Install as a Cake Tool

ManagedCode Presidio for .NET

Status: Early alpha. The API surface area is evolving while we complete the port from the Python reference implementation.

CI Release License: MIT

ManagedCode Presidio is the .NET 9 rewrite of Microsoft's Presidio project. The original Python codebase remains the authoritative reference implementation and is vendored in this repository as a Git submodule under external/microsoft-presidio. Our goal is feature parity with the Python release while delivering first-class NuGet packages for .NET applications.

The analyzer and anonymizer run in process. AnalyzerEngine uses configured deterministic recognizers by default and does not download NLP models. Optional ONNX NER requires local model artifacts. This port does not require Python, a sidecar, or a hosted AI service.


Solution Layout

  • Presidio.slnx – Visual Studio / dotnet solution for all libraries and tests.
  • src/ManagedCode.Presidio.Core – cross-cutting primitives (TextSpan, RecognizerResult, AnalysisExplanation, etc.).
  • src/ManagedCode.Presidio.Analyzer – contracts for recognizers and NLP artefacts.
  • src/ManagedCode.Presidio.Anonymizer – operators, engine results, and shared anonymization abstractions.
  • src/ManagedCode.Presidio.ImageRedactor – image request/result and bounding-box primitives; OCR and redaction engines remain unported.
  • src/ManagedCode.Presidio.Structured – nested JSON analysis, reading, and anonymization.
  • src/ManagedCode.Presidio.Evaluation – explicit evidence sanitization and an IEvaluator privacy metric.
  • tests/ManagedCode.Presidio.* – unit and integration suites validating parity against the Python behaviour.
  • external/microsoft-presidio – Git submodule pointing at the upstream Python repository.

NuGet Packages

The solution produces the following packages (versioned centrally via Directory.Build.props):

  • ManagedCode.Presidio.Core
  • ManagedCode.Presidio.Analyzer
  • ManagedCode.Presidio.Anonymizer
  • ManagedCode.Presidio.Structured
  • ManagedCode.Presidio.ImageRedactor
  • ManagedCode.Presidio.Evaluation

Publishing is handled by the release.yml GitHub workflow which runs on pushes to main.


Getting Started

Prerequisites

  • .NET SDK 9.0.301 (configured via global.json).
  • Git 2.35+ with submodule support.
  • Optionally, Python 3.9+ if you need to run the original reference code or regenerate fixtures.

Clone the Repository

git clone https://github.com/managedcode/presidio.git
cd presidio
git submodule update --init --recursive

Build & Test

dotnet restore Presidio.slnx
dotnet build Presidio.slnx --configuration Release
dotnet format Presidio.slnx
dotnet test Presidio.slnx --configuration Release

Run dotnet format Presidio.slnx before dotnet test Presidio.slnx --configuration Release.

Usage Examples

The .NET APIs mirror the Python surface. The snippets below show the most common entry points.

Analyzing and anonymizing raw text
using System.Collections.Generic;
using ManagedCode.Presidio.Analyzer;
using ManagedCode.Presidio.Anonymizer;

using var analyzer = new AnalyzerEngine();
var text = "Contact alice@example.org";
var recognizerResults = analyzer.Analyze(text, "en", ["EMAIL_ADDRESS"]);
var anonymizer = new AnonymizerEngine();
var result = anonymizer.Anonymize(
    text,
    recognizerResults,
    new Dictionary<string, OperatorConfig>
    {
        ["EMAIL_ADDRESS"] = new OperatorConfig("redact"),
    });

// result.Text == "Contact "
Sanitizing evaluation evidence

The optional Evaluation package accepts explicit entity types, language, and score threshold. It never rewrites chat messages or tool arguments implicitly.

using ManagedCode.Presidio.Analyzer;
using ManagedCode.Presidio.Anonymizer;
using ManagedCode.Presidio.Evaluation;

using var analyzer = new AnalyzerEngine();
var policy = new PresidioPiiPolicy("en", ["EMAIL_ADDRESS"], scoreThreshold: 0.5);
var sanitizer = new PresidioEvidenceSanitizer(analyzer, new AnonymizerEngine());
var safeEvidence = sanitizer.Sanitize(
    "The customer is alice@example.org",
    policy,
    PresidioEvidenceRedactionMode.ReplaceWithEntity);

// safeEvidence.Text == "The customer is <EMAIL_ADDRESS>"

PresidioPrivacyEvaluator implements Microsoft.Extensions.AI.Evaluation.IEvaluator, scans only the assistant response, and emits a numeric count metric without copying detected values into metric text. It does not call a model.

Working with collections (BatchAnonymizerEngine)
using System.Collections.Generic;
using ManagedCode.Presidio.Anonymizer;

var batch = new BatchAnonymizerEngine(anonymizer);

var response = batch.AnonymizeDict(new[]
{
    new DictRecognizerResult(
        "names",
        new[] { "John", "Jill" },
        new[]
        {
            new[] { new ManagedCode.Presidio.Anonymizer.RecognizerResult("PERSON", 0, 4, 0.9) },
            new[] { new ManagedCode.Presidio.Anonymizer.RecognizerResult("PERSON", 0, 4, 0.9) },
        })
});

// response["names"] == ["<PERSON>", "<PERSON>"]
Deanonymizing previously encrypted entities
using System.Collections.Generic;
using ManagedCode.Presidio.Anonymizer;

var deanonymizer = new DeanonymizeEngine();

var decrypted = deanonymizer.Deanonymize(
    cipherText: "My name is S184CMt9Drj7QaKQ21JTrpYzghnboTF9pn/neN8JME0=",
    entities: new[] { new OperatorResult(11, 55, "PERSON") },
    operators: new Dictionary<string, OperatorConfig>
    {
        ["DEFAULT"] = new OperatorConfig("decrypt", new Dictionary<string, object?>
        {
            [EncryptOperator.KeyParameter] = "WmZq4t7w!z%C&F)J",
        })
    });

// decrypted.Text == "My name is Chloë"

Python Reference Submodule

The external/microsoft-presidio directory tracks the upstream Python implementation. Tests under tests/ManagedCode.Presidio.Core.IntegrationTests load fixtures derived from the Python suite to prove behavioural parity of key primitives. As the port progresses, more fixtures will be mirrored directly from the submodule so that regressions can be caught early.

If you update the submodule revision, ensure you run:

git submodule update --remote external/microsoft-presidio

and commit the resulting SHA change.


Roadmap

  1. Core parity – finalise domain primitives and validate them against Python fixtures.
  2. Analyzer engine – port recognizer registry, pattern recognizers, and ONNX-backed NER execution.
  3. Anonymizer engine – reproduce the operator pipeline, conflict resolution, and policy parsing.
  4. Image/Structured pipelines – deliver feature parity for image redaction and structured anonymisation flows.
  5. Packaging – stabilise public APIs, documentation, and automate NuGet publishing.

The conversion does not yet claim full Python feature parity. Current implementation and known gaps are tracked in PLAN-MIGRATION.md.


Contributing

We welcome pull requests and issues. Please read CONTRIBUTING.md and follow the existing coding conventions (see .editorconfig). All code must target .NET 9 and pass dotnet format + dotnet test before a PR can be merged.


License

This project is licensed under the MIT License.


Maintainers

ManagedCode SAS is the primary maintainer of this fork. For questions, please open a GitHub issue or contact the ManagedCode team.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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.0.3 31 10/3/2026
0.0.2 48 10/2/2026
0.0.1 206 11/8/2025