SafetyPipeline<T>
Models & Types · AiDotNet.Safety
Composable safety pipeline that runs multiple safety modules and aggregates their findings.
For Beginners
Think of the safety pipeline as an assembly line of inspectors. Content flows through each inspector (module), and at the end you get a combined report of everything they found. If anything dangerous is detected, the pipeline can block the content or throw an exception, depending on your configuration.
How It Works
The SafetyPipeline is the runtime orchestrator for content safety. It holds a list of
ISafetyModule instances, runs them against content, and produces a
unified SafetyReport. It respects the SafetyConfig to
determine enabled modules, action thresholds, and exception behavior.
Usage via facade: The pipeline is constructed automatically based on your SafetyConfig.
Constructors
| Constructor | Summary |
|---|---|
SafetyPipeline(SafetyConfig config) |
Initializes a new safety pipeline with the given configuration. |
Properties
| Property | Summary |
|---|---|
IReadOnlyList<ISafetyModule<T>> Modules { get; } |
Gets the registered safety modules. |
SafetyConfig Config { get; } |
Gets the configuration for this pipeline. |
Methods
| Method | Summary |
|---|---|
ICausalLanguageModel<T> WatermarkLanguageModel(ICausalLanguageModel<T> model) |
Wraps a language model so that everything it generates carries the pipeline’s keyed generation-time watermark (the green-list watermark of TextWatermarker). |
SafetyPipeline<T> AddModule(ISafetyModule<T> module) |
Adds a safety module to the pipeline. |
SafetyReport EvaluateAudio(Vector<T> audioSamples, int sampleRate) |
Evaluates audio content through all registered audio safety modules. |
SafetyReport EvaluateImage(Tensor<T> image) |
Evaluates image content through all registered image safety modules. |
SafetyReport EvaluateText(string text) |
Evaluates text content through all registered text safety modules. |
SafetyReport EvaluateVector(Vector<T> content) |
Evaluates content represented as a numeric vector through all registered modules. |
SafetyReport EvaluateVideo(IReadOnlyList<Tensor<T>> frames, double frameRate) |
Evaluates video content through all registered video safety modules. |
Tensor<T> EmbedImageWatermark(Tensor<T> image) |
Returns image marked by the pipeline’s keyed image watermarker. |
Vector<T> EmbedAudioWatermark(Vector<T> audioSamples, int sampleRate) |
Returns audioSamples marked by the pipeline’s keyed audio watermarker. |
string EmbedTextWatermark(string text) |
Returns text marked by the pipeline’s keyed post-hoc text watermarker (for example LexicalWatermarker). |
void EnforcePolicy(SafetyReport report, bool isInput) |
Checks a safety report and throws SafetyViolationException if the content should be blocked based on the current configuration. |