Record Class OutputGuardrailConfig

java.lang.Object
java.lang.Record
com.tnsai.guardrails.OutputGuardrailConfig
Record Components:
maxChars - character upper bound on a String return value (0 = no bound)
minChars - character lower bound (0 = no bound)
onFailure - disposition for a violation (never null)
fallback - value substituted on FALLBACK / degraded TRUNCATE (never null)
logFailures - whether violations are logged

public record OutputGuardrailConfig(int maxChars, int minChars, OutputGuardrail.FailureAction onFailure, String fallback, boolean logFailures) extends Record
Programmatic counterpart of @OutputGuardrail (TNS-561) — lets a builder-built Role (which has no annotation to read) opt into output guardrails via RoleBuilder.outputGuardrail(...).

OutputGuardrailEnforcer resolves and enforces this record exactly as it does the annotation; the annotation path adapts through from(OutputGuardrail).

Scope: this record mirrors only the runtime-enforced subset of @OutputGuardrail (maxChars, minChars, onFailure, fallback, logFailures). The annotation's scaffold fields (format, schema, maxTokens, validators, postProcessors, maskPII, piiTypes, moderateContent, blockCategories, checkHallucination, hallucinationThreshold, maxRetries, includeSpec) are not modelled here — they have no runtime consumer today (note maxRetries is inert because Phase-1 RETRY degrades to REJECT with no re-execution callback), so surfacing them on the builder would be inert. They await the Phase-2 wiring epic, same as on the annotation.

Since:
0.12.0 (TNS-561)
  • Field Details

    • NONE

      public static final OutputGuardrailConfig NONE
      No-guardrail sentinel — same observable effect as no @OutputGuardrail present.
  • Constructor Details

    • OutputGuardrailConfig

      public OutputGuardrailConfig(int maxChars, int minChars, OutputGuardrail.FailureAction onFailure, String fallback, boolean logFailures)
      Creates an instance of a OutputGuardrailConfig record class.
      Parameters:
      maxChars - the value for the maxChars record component
      minChars - the value for the minChars record component
      onFailure - the value for the onFailure record component
      fallback - the value for the fallback record component
      logFailures - the value for the logFailures record component
  • Method Details

    • from

      public static OutputGuardrailConfig from(OutputGuardrail a)
      Adapts an @OutputGuardrail annotation into the config (the annotation enforcement path).
    • defaults

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

      public static OutputGuardrailConfig.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.
    • maxChars

      public int maxChars()
      Returns the value of the maxChars record component.
      Returns:
      the value of the maxChars record component
    • minChars

      public int minChars()
      Returns the value of the minChars record component.
      Returns:
      the value of the minChars record component
    • onFailure

      public OutputGuardrail.FailureAction onFailure()
      Returns the value of the onFailure record component.
      Returns:
      the value of the onFailure record component
    • fallback

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

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