Package com.tnsai.guardrails
Record Class InputGuardrailConfig
java.lang.Object
java.lang.Record
com.tnsai.guardrails.InputGuardrailConfig
- Record Components:
maxLength- character upper bound on every String param (0 = no bound)minLength- character lower bound (0 = no bound)blockPatterns- regex denylist — a value matching ANY pattern violates (never null)allowPatterns- regex allowlist — a value matching NONE violates; empty disables it (never null)onFailure- disposition for a violation (never null)errorMessage- custom message prefix on rejection (never null; "" = none)logFailures- whether violations are logged
public record InputGuardrailConfig(int maxLength, int minLength, List<String> blockPatterns, List<String> allowPatterns, InputGuardrail.FailureAction onFailure, String errorMessage, boolean logFailures)
extends Record
Programmatic counterpart of
@InputGuardrail (TNS-561) — lets a
builder-built Role (which has no annotation to read)
opt into input guardrails via RoleBuilder.inputGuardrail(...).
InputGuardrailEnforcer resolves and enforces this record for the
common scalar/pattern fields. The annotation path also executes its declared
validator and sanitizer extension classes.
Scope: this record mirrors only the runtime-enforced subset of
@InputGuardrail (maxLength, minLength, blockPatterns,
allowPatterns, onFailure, errorMessage, logFailures).
Validator/sanitizer classes are annotation-only and are not modelled by this
record. The remaining scaffold fields (jsonSchema,
detectInjection, moderateContent, blockCategories) have
no runtime consumer and remain outside the programmatic builder contract.
- Since:
- 0.12.0 (TNS-561)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classFluent builder; unset fields take the@InputGuardraildefaults. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final InputGuardrailConfigNo-guardrail sentinel — same observable effect as no@InputGuardrailpresent. -
Constructor Summary
ConstructorsConstructorDescriptionInputGuardrailConfig(int maxLength, int minLength, List<String> blockPatterns, List<String> allowPatterns, InputGuardrail.FailureAction onFailure, String errorMessage, boolean logFailures) Creates an instance of aInputGuardrailConfigrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theallowPatternsrecord component.Returns the value of theblockPatternsrecord component.static InputGuardrailConfig.Builderbuilder()static InputGuardrailConfigdefaults()Defaults matching@InputGuardrail's field defaults (=NONE).final booleanIndicates whether some other object is "equal to" this one.Returns the value of theerrorMessagerecord component.static InputGuardrailConfigAdapts the annotation's scalar/pattern fields into the programmatic config.final inthashCode()Returns a hash code value for this object.booleanReturns the value of thelogFailuresrecord component.intReturns the value of themaxLengthrecord component.intReturns the value of theminLengthrecord component.Returns the value of theonFailurerecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
NONE
No-guardrail sentinel — same observable effect as no@InputGuardrailpresent.
-
-
Constructor Details
-
InputGuardrailConfig
public InputGuardrailConfig(int maxLength, int minLength, List<String> blockPatterns, List<String> allowPatterns, InputGuardrail.FailureAction onFailure, String errorMessage, boolean logFailures) Creates an instance of aInputGuardrailConfigrecord class.- Parameters:
maxLength- the value for themaxLengthrecord componentminLength- the value for theminLengthrecord componentblockPatterns- the value for theblockPatternsrecord componentallowPatterns- the value for theallowPatternsrecord componentonFailure- the value for theonFailurerecord componenterrorMessage- the value for theerrorMessagerecord componentlogFailures- the value for thelogFailuresrecord component
-
-
Method Details
-
from
Adapts the annotation's scalar/pattern fields into the programmatic config. Validator and sanitizer types remain attached to the annotation and are resolved separately byInputGuardrailEnforcer. -
defaults
Defaults matching@InputGuardrail's field defaults (=NONE). -
builder
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
maxLength
public int maxLength()Returns the value of themaxLengthrecord component.- Returns:
- the value of the
maxLengthrecord component
-
minLength
public int minLength()Returns the value of theminLengthrecord component.- Returns:
- the value of the
minLengthrecord component
-
blockPatterns
Returns the value of theblockPatternsrecord component.- Returns:
- the value of the
blockPatternsrecord component
-
allowPatterns
Returns the value of theallowPatternsrecord component.- Returns:
- the value of the
allowPatternsrecord component
-
onFailure
Returns the value of theonFailurerecord component.- Returns:
- the value of the
onFailurerecord component
-
errorMessage
Returns the value of theerrorMessagerecord component.- Returns:
- the value of the
errorMessagerecord component
-
logFailures
public boolean logFailures()Returns the value of thelogFailuresrecord component.- Returns:
- the value of the
logFailuresrecord component
-