Skip to content

Guardrails

Nuget package dotnet License: MIT Discord

Features 🔥

  • Fully generated C# SDK based on official Guardrails AI OpenAPI specification using AutoSDK
  • Same day update to support new features
  • Updated and supported automatically if there are no breaking changes
  • All modern .NET features - nullability, trimming, NativeAOT, etc.
  • MEAI AIFunction tools for use with any IChatClient

Usage

1
2
3
4
5
6
7
using Guardrails;

// Connect to a self-hosted Guardrails server (default: http://localhost:8000)
using var client = new GuardrailsClient(apiKey);

// Or specify a custom base URL
using var client = new GuardrailsClient(apiKey, baseUri: new Uri("https://my-guardrails-server.example.com"));

Validate LLM Output

1
2
3
4
5
var result = await client.Validate.ValidateAsync(
    guardName: "my-guard",
    llmOutput: "Some LLM output to validate");

Console.WriteLine($"Validation passed: {result.ValidationPassed}");

List Guards

1
2
3
4
5
var guards = await client.Guard.GetGuardsAsync();
foreach (var guard in guards)
{
    Console.WriteLine($"Guard: {guard.Name} ({guard.Id})");
}

MEAI Tools

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
using Microsoft.Extensions.AI;

// Use Guardrails as tools with any IChatClient
var tools = new[]
{
    client.AsValidateTool(),
    client.AsListGuardsTool(),
    client.AsGetGuardTool(),
};

var chatOptions = new ChatOptions { Tools = [..tools] };

Generate

Basic example showing how to create a client and make a request.

1
using var client = new GuardrailsClient(apiKey);

Support

Priority place for bugs: https://github.com/tryAGI/Guardrails/issues
Priority place for ideas and general questions: https://github.com/tryAGI/Guardrails/discussions
Discord: https://discord.gg/Ca2xhfBf3v

Acknowledgments

JetBrains logo

This project is supported by JetBrains through the Open Source Support Program.