Skip to content
Tracon

TraconContentGuardBuilderExtensions

Namespace Tracon · Assembly Tracon.Core.dll

Chain extensions that turn on content inspection.

public static class TraconContentGuardBuilderExtensions

objectTraconContentGuardBuilderExtensions

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

This is an extension method, not a member of ITraconBuilder: adding a member to the interface is a breaking change after release; adding an extension method is not.

Registers your own IContentGuard implementation.

public static ITraconBuilder AddContentGuard<TGuard>(this ITraconBuilder builder) where TGuard : class, IContentGuard

builder ITraconBuilder

The configuration chain.

ITraconBuilder

The chain, for further configuration.

TGuard

The guard type.

Multiple guards can be registered; all of them run in sequence and the strictest decision wins.

builder.AddTracon()
.AddPatternContentGuard()
.AddContentGuard<CustomerNameGuard>();

ArgumentNullException

builder is null.

AddContentGuard(ITraconBuilder, IContentGuard)

Section titled “ AddContentGuard(ITraconBuilder, IContentGuard)”

Registers a configured IContentGuard instance.

public static ITraconBuilder AddContentGuard(this ITraconBuilder builder, IContentGuard guard)

builder ITraconBuilder

The configuration chain.

guard IContentGuard

The guard instance.

ITraconBuilder

The chain, for further configuration.

Multiple guards can be registered; all of them run in sequence and the strictest decision wins. The caller owns the instance and any resources it holds.

ArgumentNullException

A parameter is null.

AddContentGuard(ITraconBuilder, Func<IServiceProvider, IContentGuard>)

Section titled “ AddContentGuard(ITraconBuilder, Func<IServiceProvider, IContentGuard>)”

Registers an IContentGuard factory.

public static ITraconBuilder AddContentGuard(this ITraconBuilder builder, Func<IServiceProvider, IContentGuard> factory)

builder ITraconBuilder

The configuration chain.

factory Func<IServiceProvider, IContentGuard>

The factory that creates the guard.

ITraconBuilder

The chain, for further configuration.

The container owns the produced singleton. The factory must not capture a scoped dependency because the result outlives that scope.

ArgumentNullException

A parameter is null.

AddPatternContentGuard(ITraconBuilder, Action<PatternContentGuardOptions>?)

Section titled “ AddPatternContentGuard(ITraconBuilder, Action<PatternContentGuardOptions>?)”

Registers Tracon’s built-in pattern-based content guard.

public static ITraconBuilder AddPatternContentGuard(this ITraconBuilder builder, Action<PatternContentGuardOptions>? configure = null)

builder ITraconBuilder

The configuration chain.

configure Action<PatternContentGuardOptions>?

Pattern and denied-term settings.

ITraconBuilder

The chain, for further configuration.

This call is the no-surprises rule’s gate. AddTracon alone registers no guard, and the inspection wrapper is never added to the model pipeline. Without this call no prompt is inspected, no response is inspected, and no cost is paid.

The built-in guard carries no rules by default: PatternContentGuardOptions.MaskedPii is PiiPatterns.None and PatternContentGuardOptions.DeniedTerms is empty. Which pattern family to turn on is an explicit choice; turning them all on at once compounds the false-positive risk.

The same settings are also read from the Tracon:ContentGuard:Pattern configuration section; if that section is present the guard is already registered by AddTracon and this call is redundant (the registration uses TryAddEnumerable, so it is never added twice).

builder.AddTracon()
.AddPatternContentGuard(options =>
{
options.MaskedPii = PiiPatterns.CreditCard | PiiPatterns.Email;
options.DeniedTerms.Add("secret-project");
});

ArgumentNullException

builder is null.