Package dev.agenor.core.guardrail
Class GuardrailViolationException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
dev.agenor.core.exceptions.AgenorException
dev.agenor.core.guardrail.GuardrailViolationException
- All Implemented Interfaces:
Serializable
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 Summary
ConstructorsConstructorDescriptionGuardrailViolationException(String reason, String blockedBy) Creates a new violation exception.GuardrailViolationException(String reason, String blockedBy, Throwable cause) Creates a new violation exception with an underlying cause. -
Method Summary
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
GuardrailViolationException
Creates a new violation exception.- Parameters:
reason- human-readable explanation from the blocking guardrail; nevernullblockedBy- fully-qualified class name of the guardrail that issued the block; nevernull
-
GuardrailViolationException
Creates a new violation exception with an underlying cause.- Parameters:
reason- human-readable explanation; nevernullblockedBy- guardrail class name; nevernullcause- the underlying exception, if any
-
-
Method Details
-
reason
Returns the human-readable reason provided by the blocking guardrail.- Returns:
- the block reason; never
null
-
blockedBy
Returns the fully-qualified class name of the guardrail that blocked the content.- Returns:
- the guardrail class name; never
null
-