Class GuardrailAnnotationProcessor

java.lang.Object
dev.agenor.runtime.guardrail.GuardrailAnnotationProcessor

public final class GuardrailAnnotationProcessor extends Object
Reads the WithGuardrails annotation from an LLMAgent subclass and injects a GuardrailChain into the agent at registration time.

Called by AgenorRuntime.registerAgent() whenever the registered agent is an instance of LLMAgent:


 // Inside AgenorRuntime.registerAgent():
 if (agent instanceof LLMAgent llmAgent) {
     GuardrailAnnotationProcessor.process(llmAgent);
 }
 

Wiring logic

  1. If the agent class has no @WithGuardrails annotation → no-op.
  2. Instantiate each listed InputGuardrail and OutputGuardrail class via its public no-arg constructor (reflection).
  3. If the agent already has a programmatically configured chain, the annotation-derived guardrails are prepended to it.
  4. Otherwise a new chain is built and injected via LLMAgent.setGuardrailChain(dev.agenor.runtime.guardrail.GuardrailChain).

Error handling

If a guardrail class listed in the annotation cannot be instantiated (missing no-arg constructor, abstract class, etc.) a GuardrailAnnotationProcessor.GuardrailWiringException is thrown, which aborts agent registration with a clear message.
Since:
0.13.0
  • Method Details

    • process

      public static void process(LLMAgent agent)
      Processes the WithGuardrails annotation on agent's class and injects the resulting chain.

      This method is a no-op if the agent class carries no annotation.

      Parameters:
      agent - the LLM agent being registered; never null
      Throws:
      GuardrailAnnotationProcessor.GuardrailWiringException - if any guardrail class cannot be instantiated