Files
fil/docs/snippets/kotlin/plugins/min_length_validator.md
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

806 B

import dev.kreuzberg.*

class MinLengthValidator(private val minLength: Int) : IValidator {
    override fun name(): String = "min-length-validator"
    override fun version(): String = "1.0.0"

    override fun validate(result: ExtractionResult, config: ExtractionConfig) {
        val length = result.content().length
        if (length < minLength) {
            throw IllegalStateException(
                "Content too short: $length < $minLength characters",
            )
        }
    }

    override fun should_validate(
        _result: ExtractionResult,
        _config: ExtractionConfig,
    ): Boolean = true

    override fun priority(): Int = 100
}

fun registerMinLengthValidator() {
    ValidatorBridge.registerValidator(MinLengthValidator(minLength = 100))
}