This commit is contained in:
31
docs/snippets/csharp/min_length_validator.md
Normal file
31
docs/snippets/csharp/min_length_validator.md
Normal file
@@ -0,0 +1,31 @@
|
||||
```csharp title="C#"
|
||||
using Kreuzberg;
|
||||
|
||||
var validator = new MinLengthValidator(minLength: 100);
|
||||
KreuzbergLib.RegisterValidator(validator);
|
||||
|
||||
public class MinLengthValidator : IValidator
|
||||
{
|
||||
private readonly int _minLength;
|
||||
|
||||
public MinLengthValidator(int minLength = 100)
|
||||
{
|
||||
_minLength = minLength;
|
||||
}
|
||||
|
||||
public string Name() => "min_length_validator";
|
||||
public string Version() => "1.0.0";
|
||||
public int Priority() => 100;
|
||||
|
||||
public void Validate(Dictionary<string, object> result)
|
||||
{
|
||||
var contentLength = result["content"].ToString()?.Length ?? 0;
|
||||
if (contentLength < _minLength)
|
||||
throw new ValidationError($"Content too short: {contentLength}");
|
||||
}
|
||||
|
||||
public bool ShouldValidate(Dictionary<string, object> result) => true;
|
||||
public void Initialize() { }
|
||||
public void Shutdown() { }
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user