Custom Guardrail Evaluators
Create custom guardrail evaluators to enforce domain-specific safety and compliance rules.
Guardrail evaluators are the components that perform the actual content evaluation within guardrail rules. Umbraco.AI ships with built-in evaluators (Contains, Regex, LLM Judge), but you can create custom evaluators for domain-specific needs.
Overview
Each evaluator:
Has a unique ID and display name
Defines what it checks (prohibited content, sensitive patterns, brand compliance, etc.)
Can be code-based (deterministic, fast) or model-based (LLM-powered, nuanced)
Optionally accepts configuration with a dynamic UI schema
Is auto-discovered at startup
Creating a Code-Based Evaluator
Code-based evaluators use deterministic logic like pattern matching. They run during streaming and provide fast responses.
Step 1: Define Configuration
Create a configuration class with [AIField] attributes for backoffice UI generation:
using Umbraco.AI.Core.EditableModels;
public class ProfanityFilterConfig
{
[AIField(
Label = "Word List",
Description = "Comma-separated list of words to flag",
EditorUiAlias = "Umb.PropertyEditorUi.TextArea",
SortOrder = 1)]
public string WordList { get; set; } = string.Empty;
[AIField(
Label = "Ignore Case",
Description = "Case-insensitive matching",
EditorUiAlias = "Umb.PropertyEditorUi.Toggle",
SortOrder = 2)]
public bool IgnoreCase { get; set; } = true;
}Step 2: Implement the Evaluator
Extend AIGuardrailEvaluatorBase<TConfig> and apply the [AIGuardrailEvaluator] attribute:
The evaluator is automatically discovered and available in the backoffice when creating guardrail rules.
Creating a Model-Based Evaluator
Model-based evaluators use an AI model to perform nuanced evaluation. They run after streaming completes (on the full response).
Evaluator Registration
Evaluators are auto-discovered via the [AIGuardrailEvaluator] attribute and IDiscoverable interface. No manual registration is needed.
To manually add or exclude evaluators in a Composer:
Requiring a Capability
If your evaluator depends on an experimental capability, such as Decision, mark it with [AIRequiresCapability]. The attribute hides the evaluator from the evaluator listing endpoint while that capability is disabled. You can apply it more than once when an evaluator needs more than one capability. The same attribute works on custom test graders.
AIGuardrailResult
Every evaluator returns an AIGuardrailResult:
EvaluatorId
string
ID of the evaluator that produced this result
Flagged
bool
Whether the content was flagged
Score
double?
Confidence score (0-1). Code-based evaluators typically return 0 or 1
Reason
string?
Human-readable explanation
Metadata
JsonElement?
Evaluator-specific metadata (matched patterns, LLM reasoning, etc.)
Built-in Evaluators
contains
Contains
Code-based
Flags content containing a specific substring
regex
Regex Match
Code-based
Flags content matching a regular expression pattern
llm-judge
LLM Safety Judge
Model-based
Uses an AI model to evaluate content for safety and compliance
decision-judge
Decision Safety Judge
Model-based
Uses a calibrated AI decision to judge content for safety and compliance (experimental). See Decision Safety Judge Evaluator
Related
Guardrails Concept - Understanding guardrails
Managing Guardrails - Backoffice guide
Custom Providers - Creating AI providers
Last updated
Was this helpful?