AiAssertions.Core 0.2.1

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

AiAssertions

<p align="center"> <img src=".github/images/logo.png" alt="Logo" style="width: 40%"> </p>

AiAssertions is an AI-powered codebase assertion library.

Developers write normal unit tests, but describe business requirements in natural language. AiAssert asks an AI agent to inspect the project with local tools, gather evidence, and return a verdict with model confidence and a short comment.

[Fact]
public async Task Students_CannotModifyMarks()
{
    await AiAssert
        .OnCodebase()
        .That("""
            Students must never be able to modify
            their own marks or marks of other students.

            Only teachers and administrators
            may update marks.
            """);
}

AI Test Flow

<p align="center"> <img src=".github/images/ai-test-flow.png" alt="Logo" style="width: 100%"> </p>

Installation

dotnet add package AiAssertions

Public API

using AiAssertions;
using AiAssertions.OpenRouter.Configuration;

AiAssert
    .Configure(OpenRouterClientFactory.Create(new OpenRouterOptions
        {
            ApiKey = Environment.GetEnvironmentVariable("OPENROUTER_API_KEY")!,
            Model = OpenRouterModel.OpenAiGpt4O
        }))
    // Timeout is a threshold for how long the model has to return a verdict.
    // If the model does not return a verdict within this time, the result verdict is NotDetermined.
    .WithDefaultTimeout(TimeSpan.FromMinutes(1)) // Optional: override default timeout for all assertions.
    .WithDefaultMaxToolIterations(10) // Optional: override the default tool-calling iteration limit.
    .WithGlobalApproximateTokenLimit(32_000) // Optional: limit conversation tokens for all assertions.
    .WithGlobalExecutionTrace() // Optional: collect model, tool, compaction, and timing diagnostics.
    .WithGlobalAdditionalSystemPrompt("Prefer direct code evidence over inference.")
    // Confedence tolerance is a threshold for the model's confidence in its verdict. 
    // If the model returns a confidence below this threshold, the assertion fails.
    .WithGlobalConfidenceTolerance(0.85); // Optional: override default confidence tolerance for all assertions.

var result = await AiAssert
    .OnCodebase()
    .WithTimeout(TimeSpan.FromMinutes(1)) // Optional: override default timeout for this concrete assertion.
    .WithMaxToolIterations(300) // Optional: override default tool-calling iteration limit for this assertion.
    .WithExecutionTrace() // Optional: expose the complete run trace on the result.
    .IncludeDirectory("SampleCode/Security") // Optional: include directory as initial evidence for the model.
    .That("Business requirement in natural language.");

Console.WriteLine(result.Verdict);
Console.WriteLine(result.Confidence);
Console.WriteLine(result.Comment);

foreach (var evidence in result.Evidence)
    Console.WriteLine($"{evidence.File}:{evidence.StartLine}-{evidence.EndLine} {evidence.Description}");

foreach (var missingEvidence in result.MissingEvidence)
    Console.WriteLine($"Missing: {missingEvidence.Description}");

AiAssert.OnCodebase() uses an AI agent and native tool/function calling.

By default, global tolerance is not set, so AiAssertions accepts any model confidence.

By default, timeout is two minutes.

IncludeDirectory(...), IncludeFile(...), and IncludeType(...) send selected files to the model as initial evidence before the agent starts calling tools.

This pre-included evidence is intentionally capped: At most 20 resolved files are included.

Each included file is truncated to 30,000 characters.

The agent can still inspect additional files later through its local tools.

WithTimeout(...) can be applied on a codebase assertion before That(...) when a single assertion needs a different timeout:

var result = await AiAssert
    .OnCodebase()
    .WithTimeout(TimeSpan.FromSeconds(30))
    .That("Students must never be able to modify their own marks.");

Assert using requirements from a file

Requirements can also be stored in .txt or .md files and used instead of .That(...):

var result = await AiAssert
    .OnCodebase()
    .IncludeDirectory("SampleCode/Security")
    .AgainstRequirementFile("Requirements/password-registration.md");

Make your custom AI model provider

See Custom Models for the provider implementation guide.

Existing Providers

Verdict JSON

Final codebase verdicts from AI Model must be strict JSON:

{
  "passed": false,
  "confidence": 0.82,
  "is_conclusive": true,
  "reason": "UpdateMarkHandler updates marks without checking user role.",
  "evidence": [
    {
      "file": "SampleCode/School/MarksController.cs",
      "start_line": 18,
      "end_line": 25,
      "description": "MarksController exposes an update endpoint."
    }
  ],
  "missing_evidence": [
    {
      "description": "No role authorization check was found before updating marks.",
      "expected_location": "SampleCode/School/MarksController.cs"
    }
  ]
}

Sample

Check the sample project: samples/AiAssertions.Sample.

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.
  • net10.0

    • No dependencies.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on AiAssertions.Core:

Package Downloads
AiAssertions

AI-powered codebase assertions. Write natural-language requirements in tests and let an AI agent inspect your project.

AiAssertions.Gemini

This package provides Gemini models for AiAssertions.

AiAssertions.OpenRouter

This package provides the OpenRouter model for AiAssertions.

AiAssertions.OpenAi

This package provides the OpenAI model for AiAssertions.

AiAssertions.Grok

This package provides the Grok model for AiAssertions.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.2-rc.1 105 8/12/2026
0.2.1 166 8/10/2026
0.2.1-rc.5 97 8/6/2026
0.2.1-rc.4 94 8/6/2026
0.2.1-rc.3 103 8/6/2026
0.2.1-rc.2 96 8/5/2026
0.2.1-rc.1 101 8/5/2026
0.2.0 179 7/30/2026
0.1.3 175 7/29/2026
0.1.2 188 6/27/2026
0.1.1 193 6/26/2026
0.1.0 193 6/26/2026