Class GuardrailViolationException

All Implemented Interfaces:
Serializable

public class GuardrailViolationException extends AgenorException
Thrown when a guardrail in the chain returns GuardrailResult.Blocked, indicating that the content must not proceed through the pipeline.

Extends AgenorException (unchecked) to be consistent with the Agenor exception hierarchy (ADR-014). Callers may catch it explicitly when they need to handle policy violations, but are not required to declare it.

Example:


 try {
     String response = agent.chat(userInput);
 } catch (GuardrailViolationException e) {
     log.warn("Guardrail {} blocked request: {}", e.blockedBy(), e.reason());
     return "Your request could not be processed due to content policy.";
 }
 
Since:
0.13.0
See Also:
  • Constructor Details

    • GuardrailViolationException

      public GuardrailViolationException(String reason, String blockedBy)
      Creates a new violation exception.
      Parameters:
      reason - human-readable explanation from the blocking guardrail; never null
      blockedBy - fully-qualified class name of the guardrail that issued the block; never null
    • GuardrailViolationException

      public GuardrailViolationException(String reason, String blockedBy, Throwable cause)
      Creates a new violation exception with an underlying cause.
      Parameters:
      reason - human-readable explanation; never null
      blockedBy - guardrail class name; never null
      cause - the underlying exception, if any
  • Method Details

    • reason

      public String reason()
      Returns the human-readable reason provided by the blocking guardrail.
      Returns:
      the block reason; never null
    • blockedBy

      public String blockedBy()
      Returns the fully-qualified class name of the guardrail that blocked the content.
      Returns:
      the guardrail class name; never null