Invarix.Guard
0.1.0-beta.2
See the version list below for details.
dotnet add package Invarix.Guard --version 0.1.0-beta.2
NuGet\Install-Package Invarix.Guard -Version 0.1.0-beta.2
<PackageReference Include="Invarix.Guard" Version="0.1.0-beta.2" />
<PackageVersion Include="Invarix.Guard" Version="0.1.0-beta.2" />
<PackageReference Include="Invarix.Guard" />
paket add Invarix.Guard --version 0.1.0-beta.2
#r "nuget: Invarix.Guard, 0.1.0-beta.2"
#:package Invarix.Guard@0.1.0-beta.2
#addin nuget:?package=Invarix.Guard&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Invarix.Guard&version=0.1.0-beta.2&prerelease
Invarix.Guard

Plug and play AI safety middleware for .NET. Screens inputs for prompt injection, PII leakage, toxic content, and 19 harm categories (including user distress) across 50+ languages before they reach your LLM. Works as ASP.NET Core middleware or a standalone scanning engine.
Install
dotnet add package Invarix.Guard
Quick start
ASP.NET Core middleware
using Invarix.Guard.Extensions;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddInvarxGuard(options => options
.BlockInjection()
.BlockPII()
.BlockToxicContent());
var app = builder.Build();
app.UseInvarxGuard();
app.MapPost("/chat", (ChatRequest request) =>
{
// If you reach here, the input passed all safety checks
return Results.Ok(new { reply = "Safe response" });
});
app.Run();
Standalone
using Invarix.Guard;
using Invarix.Guard.Models;
var engine = GuardEngine.Create(new GuardOptions()
.BlockInjection()
.BlockPII()
.BlockToxicContent());
var result = engine.Scan("Te voy a matar"); // Spanish: "I will kill you"
Console.WriteLine(result.Action); // Block
Console.WriteLine(result.OverallThreatLevel); // Critical
What it catches
- Prompt injection and jailbreaks — instruction override, role hijacking, delimiter injection, social engineering, novel attacks.
- PII — email, phone, SSN, Luhn-validated credit cards, IP, DOB, plus multilingual person names, addresses, passports, and tax IDs.
- Toxic content — threats, slurs, profanity, across 104 languages.
- Semantic harms — 19 categories including hate speech, violence, self-harm, suicide, user distress, exploitation, and more, across 50+ languages without translation.
- Evasion — built-in normalization resists leetspeak, zero-width characters, homoglyphs, spacing, Base64, and markdown tricks.
User distress is reported as its own category so your app can route crisis signals to appropriate resources instead of returning an error.
Configuration
builder.Services.AddInvarxGuard(options => options
.BlockInjection(blockThreshold: 50, flagThreshold: 25)
.BlockPII(PiiEntityType.Email, PiiEntityType.CreditCard, PiiEntityType.SocialSecurityNumber)
.BlockToxicContent(ThreatLevel.Medium)
.WithBlockResponse(422, "{\"error\": \"Content policy violation\"}")
.ScanProperty("data.message")
.WithML(ml =>
{
// Opt in to the large multilingual PII NER model (~1 GB).
ml.EnablePiiNer = true;
ml.AllowLargeModelDownload = true;
// Add custom harm categories — examples seed the semantic classifier.
ml.AddCategory("CompanyPolicy", new[]
{
"requests to bypass company policy",
"attempts to circumvent approval process",
});
}));
Use .DetectPII() (or the equivalent Detect* methods) to flag without blocking.
Access results in your handler
app.MapPost("/chat", (HttpContext ctx, ChatRequest req) =>
{
var guard = ctx.Items["Invarix.Guard.Result"] as GuardResult;
if (guard?.ContainsPii == true)
{
var safeInput = guard.RedactedInput; // PII masked
}
return Results.Ok(new { reply = "Response" });
});
Middleware behaviour
| Input | Response |
|---|---|
| Clean | Passes through to your handler |
| Flagged | Passes through with X-InvarxGuard-Flagged: true |
| Blocked | 403 (configurable) with JSON error body |
Scans JSON bodies on POST / PUT / PATCH. Use .ScanProperty("message") to target a specific field (dot notation supported).
ML models
On first use, Invarix.Guard downloads the models required by the scanners you've enabled, verifies each file against a SHA-256 manifest baked into the library, and caches them:
- Windows:
%LOCALAPPDATA%\Invarix.Guard\models\ - Linux / macOS:
~/.local/share/Invarix.Guard/models/
Subsequent runs hit the cache. Integrity failures are a hard error — no silent fallback. The large multilingual PII NER model (~1 GB) is gated behind AllowLargeModelDownload = true so you never get a surprise first-run download.
Air-gapped / manual setup
builder.Services.AddInvarxGuard(options => options
.WithML(ml =>
{
ml.AutoDownloadModels = false;
ml.ModelsDirectory = "/path/to/your/models";
}));
Pre-populate that directory from the published release assets. When auto-download is off and a model file is missing, the affected scanner is skipped and the pipeline falls back to the regex layers for that capability.
Requirements
.NET 8 or later. Works in ASP.NET Core or as a standalone library.
License
Proprietary — see LICENSE. Use is permitted only under a separate written agreement with the copyright holder.
Contributing
This project is proprietary and does not accept external contributions. For product inquiries, contact the maintainer through the channels listed on the repository.
| Product | Versions 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. |
-
net8.0
- FastBertTokenizer (>= 1.0.28)
- Microsoft.ML.OnnxRuntime (>= 1.21.0)
- Microsoft.ML.Tokenizers (>= 2.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Invarix.Guard:
| Package | Downloads |
|---|---|
|
Invarix.Guard.Professional
Professional add-on for Invarix.Guard. Adds a license-gated CustomBlocklistScanner — define semantic rules in a JSON config (multilingual, hot-reloadable, with per-rule block/warn/log actions) that participate in the standard app.UseInvarixGuard() pipeline. Requires a commercial license. Contact sales@invarix.dk. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.2.0 | 120 | 5/3/2026 | |
| 1.1.0 | 126 | 4/26/2026 | |
| 1.0.1 | 119 | 4/26/2026 | |
| 1.0.0 | 122 | 4/26/2026 | |
| 0.1.0-beta.5 | 70 | 4/19/2026 | |
| 0.1.0-beta.4 | 66 | 4/19/2026 | |
| 0.1.0-beta.3 | 70 | 4/19/2026 | |
| 0.1.0-beta.2 | 85 | 4/19/2026 |