PatternContentGuard
AgentPrism.Core.dllAgentPrism’s built-in pattern-based content guard.
public sealed class PatternContentGuard : IContentGuardInheritance
Section titled “Inheritance”Implements
Section titled “Implements”Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”The extension point alone is not enough: the rule is that an in-memory
implementation is first-class,“ and without a built-in implementation
IContentGuard would be an empty promise. It carries three
pattern families: a denied-term list (ContentGuardAction.Block),
PII patterns, and secret patterns (ContentGuardAction.Mask).
Every pattern is written with the source generator
(RegularExpressions.GeneratedRegexAttribute). AgentPrism.Core is
AOT-compatible; a RegularExpressions.Regex compiled at runtime would break that.
Every pattern carries a timeout (1000 ms). This is the only defense against ReDoS and is mandatory on the hot path.
Card and Turkish national ID patterns are validated with AgentPrism.CheckDigits. Without it, every order number would be masked and the guard would get turned off.
Allocation order: a match is looked for first with IsMatch /
EnumerateMatches, and a new string is produced only if there
is a match. If no rule is defined, ContentGuardResult.Allow
is returned on the first line.
Constructors
Section titled “Constructors”PatternContentGuard(IOptionsMonitor<PatternContentGuardOptions>)
Section titled “ PatternContentGuard(IOptionsMonitor<PatternContentGuardOptions>)”Creates a new built-in guard.
public PatternContentGuard(IOptionsMonitor<PatternContentGuardOptions> options)Parameters
Section titled “Parameters”options IOptionsMonitor<PatternContentGuardOptions>
Pattern and denied-term settings.
Exceptions
Section titled “Exceptions”options is null.
Properties
Section titled “Properties”The guard’s name. This name is written to the audit trail and the run event.
public string Name { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”InspectAsync(ContentGuardContext, CancellationToken)
Section titled “ InspectAsync(ContentGuardContext, CancellationToken)”Inspects the content.
public ValueTask<ContentGuardResult> InspectAsync(ContentGuardContext context, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”context ContentGuardContext
The inspection context.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”The decision. Returns ContentGuardResult.Allow when the content passes unchanged; this path allocates nothing.