RegexValidator

org.llm4s.agent.guardrails.builtin.RegexValidator
See theRegexValidator companion class

Attributes

Companion
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

A validator for non-empty text made only of ASCII letters and digits, so spaces and punctuation are rejected. The pattern ends with $, which also accepts one trailing line break (abc followed by a line break passes). A mismatch reports Content must be alphanumeric.

A validator for non-empty text made only of ASCII letters and digits, so spaces and punctuation are rejected. The pattern ends with $, which also accepts one trailing line break (abc followed by a line break passes). A mismatch reports Content must be alphanumeric.

Attributes

def apply(pattern: String): RegexValidator

Create a validator that searches for a pattern given as a string.

Create a validator that searches for a pattern given as a string.

The pattern goes through org.llm4s.security.RegexSafetyManager.safeCompile. One that is refused or does not compile does not throw here: the validator is still returned, and every validate call fails with Invalid or unsafe regex pattern: <reason>.

Value parameters

pattern

the regular expression to search for, in java.util.regex syntax

Attributes

Returns

a validator whose mismatch message is Value does not match pattern: <pattern>

def apply(pattern: Regex): RegexValidator

Create a validator that searches for a scala.util.matching.Regex.

Create a validator that searches for a scala.util.matching.Regex.

The pattern is used as given: unlike the String factories it is not pre-screened for dangerous shapes or length, though matching is still bounded.

Value parameters

pattern

the pattern to search for

Attributes

Returns

a validator whose mismatch message is Value does not match pattern: <pattern>

def apply(pattern: String, errorMessage: String): RegexValidator

Create a validator for a string pattern with a custom mismatch message.

Create a validator for a string pattern with a custom mismatch message.

As with the one-argument factory, a refused or invalid pattern fails every validate call with Invalid or unsafe regex pattern: <reason>; errorMessage is not used for that failure.

Value parameters

errorMessage

the detail to report when the pattern is not found

pattern

the regular expression to search for, in java.util.regex syntax

Attributes

Returns

the validator

A validator for email addresses, using a basic pattern.

A validator for email addresses, using a basic pattern.

Accepts local@domain.tld with letters, digits and + _ . - in the local part. It is a format check, not proof that the address exists, and it does not implement the full email grammar. The pattern ends with $, which also accepts one trailing line break. A mismatch reports Invalid email address format.

Attributes

A validator for phone numbers, using a basic pattern: an optional leading + and then 10 to 15 digits, with no spaces, dashes or brackets. The pattern ends with $, which also accepts one trailing line break. A mismatch reports Invalid phone number format.

A validator for phone numbers, using a basic pattern: an optional leading + and then 10 to 15 digits, with no spaces, dashes or brackets. The pattern ends with $, which also accepts one trailing line break. A mismatch reports Invalid phone number format.

Attributes