PrivacyFilter.Net 0.1.2

dotnet add package PrivacyFilter.Net --version 0.1.2
                    
NuGet\Install-Package PrivacyFilter.Net -Version 0.1.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="PrivacyFilter.Net" Version="0.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PrivacyFilter.Net" Version="0.1.2" />
                    
Directory.Packages.props
<PackageReference Include="PrivacyFilter.Net" />
                    
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 PrivacyFilter.Net --version 0.1.2
                    
#r "nuget: PrivacyFilter.Net, 0.1.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 PrivacyFilter.Net@0.1.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=PrivacyFilter.Net&version=0.1.2
                    
Install as a Cake Addin
#tool nuget:?package=PrivacyFilter.Net&version=0.1.2
                    
Install as a Cake Tool

<p align="center"> <img src="https://raw.githubusercontent.com/ericstj/PrivacyFilter.Net/main/eng/icon.png" alt="PrivacyFilter.Net logo" width="128" height="128"> </p>

PrivacyFilter.Net

A managed C# port of the inference API and decoding pipeline from OpenAI Privacy Filter. It uses the official ONNX model, Microsoft.ML.Tokenizers for byte-compatible o200k_base tokenization, and managed constrained BIOES Viterbi decoding, span reconstruction, and redaction.

Unofficial. This project is not affiliated with or endorsed by OpenAI.

Features

  • Loads the official fp32, fp16, q4, q4f16, or quantized ONNX checkpoints.
  • Uses Microsoft.ML.Tokenizers for o200k_base token ids and per-token character offsets.
  • Reproduces the upstream 33-label BIOES space and constrained Viterbi decoder.
  • Supports typed placeholders such as <PRIVATE_PERSON> or a single <REDACTED> output mode.
  • Processes long inputs in non-overlapping token windows, matching the upstream CPU runtime default of 4,096 tokens.
  • Returns the upstream schema fields and JSON names.

Usage

Download an ONNX variant and its metadata from openai/privacy-filter. Keep the ONNX external-data file beside its .onnx graph:

privacy-filter/
  config.json
  viterbi_calibration.json
  onnx/
    model_q4f16.onnx
    model_q4f16.onnx_data

For a smaller CPU checkpoint:

hf download openai/privacy-filter `
  --revision 7ffa9a043d54d1be65afb281eddf0ffbe629385b `
  --include config.json viterbi_calibration.json onnx/model_q4f16.onnx onnx/model_q4f16.onnx_data `
  --local-dir C:\models\privacy-filter
using PrivacyFilterNet;

using var filter = PrivacyFilter.Load(@"C:\models\privacy-filter");
PrivacyFilterResult result =
    filter.Redact("Alice's email is alice@example.com.");

Console.WriteLine(result.RedactedText);
foreach (PrivacyFilterSpan span in result.DetectedSpans)
{
    Console.WriteLine($"{span.Label}: {span.Text} [{span.Start}, {span.End})");
}

To collapse all detected types:

using var filter = PrivacyFilter.Load(
    @"C:\models\privacy-filter",
    new PrivacyFilterOptions
    {
        OutputMode = PrivacyFilterOutputMode.Redacted,
    });

The loader prefers model_q4f16.onnx, then the quantized, q4, fp16, and fp32 variants. Set ModelFileName to choose one explicitly. ONNX Runtime is a native runtime dependency; tokenization and all post-model decoding are managed C#.

Scope

PrivacyFilter.Net ports inference and redaction. Training, fine-tuning, and the PyTorch/Triton sparse-MoE implementation are out of scope because OpenAI publishes official ONNX graphs that preserve the model architecture directly.

Building and testing

dotnet build PrivacyFilter.Net.sln -c Release
dotnet test PrivacyFilter.Net.sln -c Release

Tests validate tokenizer ids, decoded text, and offsets against Python tiktoken across deterministic Unicode and special-token corpora; compare Viterbi paths and BIOES span reconstruction against committed Python oracles; and run the complete pipeline through a tiny ONNX fixture with the same input/output contract as the official model.

Benchmarks

Set PRIVACY_FILTER_MODEL_DIR to a downloaded checkpoint, then run:

dotnet run -c Release --project bench\PrivacyFilter.Net.Benchmarks

The BenchmarkDotNet suite measures short single-record inference and a longer multi-record input while reporting managed allocations. Current measurements and the upstream Python comparison are in bench/results.md.

License

Apache-2.0. See LICENSE and THIRD-PARTY-NOTICES.md.

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.1.2 155 7/24/2026
0.1.1 126 7/23/2026
0.1.0 119 7/22/2026