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)
  • Field Details

    • NONE

      public static final InputGuardrailConfig NONE
      No-guardrail sentinel — same observable effect as no @InputGuardrail present.
  • 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 a InputGuardrailConfig record class.
      Parameters:
      maxLength - the value for the maxLength record component
      minLength - the value for the minLength record component
      blockPatterns - the value for the blockPatterns record component
      allowPatterns - the value for the allowPatterns record component
      onFailure - the value for the onFailure record component
      errorMessage - the value for the errorMessage record component
      logFailures - the value for the logFailures record component
  • Method Details

    • from

      public static InputGuardrailConfig from(InputGuardrail a)
      Adapts the annotation's scalar/pattern fields into the programmatic config. Validator and sanitizer types remain attached to the annotation and are resolved separately by InputGuardrailEnforcer.
    • defaults

      public static InputGuardrailConfig defaults()
      Defaults matching @InputGuardrail's field defaults (= NONE).
    • builder

      public static InputGuardrailConfig.Builder builder()
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • maxLength

      public int maxLength()
      Returns the value of the maxLength record component.
      Returns:
      the value of the maxLength record component
    • minLength

      public int minLength()
      Returns the value of the minLength record component.
      Returns:
      the value of the minLength record component
    • blockPatterns

      public List<String> blockPatterns()
      Returns the value of the blockPatterns record component.
      Returns:
      the value of the blockPatterns record component
    • allowPatterns

      public List<String> allowPatterns()
      Returns the value of the allowPatterns record component.
      Returns:
      the value of the allowPatterns record component
    • onFailure

      public InputGuardrail.FailureAction onFailure()
      Returns the value of the onFailure record component.
      Returns:
      the value of the onFailure record component
    • errorMessage

      public String errorMessage()
      Returns the value of the errorMessage record component.
      Returns:
      the value of the errorMessage record component
    • logFailures

      public boolean logFailures()
      Returns the value of the logFailures record component.
      Returns:
      the value of the logFailures record component