Skip to content
tnsaijava agent framework

Guardrails — three different things

TnsAI uses the word guardrail for three distinct APIs in three modules. They are not interchangeable: different types, different call sites, different imports. Pick by when you need to gate something.

What you wantTypeModuleWhen it runs
Validate or sanitize an action's input/output@InputGuardrail / @OutputGuardrailtnsai-core (com.tnsai.annotations, enforced by com.tnsai.guardrails.*Enforcer)Immediately before / after the action body
Allow or block an agent action in a multi-agent groupcom.tnsai.coordination.supervisor.Guardrailtnsai-coordinationEvery action request routed through SupervisorAgent
Score traced text for PII, toxicity, off-topiccom.tnsai.quality.tracing.guardrail.Guardrailtnsai-qualityPre/post response on traced input+output (GuardrailRegistry)

The two Guardrail interfaces share a name and nothing else. Import the FQN; IDE auto-import will happily pick the wrong one.

This page is discovery only. It does not rename the types.

Action I/O — @InputGuardrail / @OutputGuardrail

Per-action (or role-default) field checks: length bounds, deny/allow patterns, validators, sanitizers. Wired today — see runtime status.

@ActionSpec(type = ActionType.LOCAL, description = "Process user message")
@InputGuardrail(maxLength = 10_000, blockPatterns = {"ignore previous"})
@OutputGuardrail(maxLength = 8_000)
public String processMessage(String message) {
    return message;
}

Use this when the question is "is this payload safe to enter or leave this method?" Not "is this agent allowed to call deploy?"

TnsAI 0.14.0 (PR #168 (TAN-3016) adds PiiInputValidator / PiiInputSanitizer on this annotation. That is action-input detection, not PiiGuardrail below. See PII input guardrails.

More on approvals and @Security: Approvals and Annotations.

Supervisor permission — com.tnsai.coordination.supervisor.Guardrail

SupervisorAgent asks each registered guardrail check(agentId, action, context) before the action runs. The result is allow / warn / block (GuardrailSeverity). Typical uses: read-only mode, budget caps, HITL on deploy / delete.

SupervisorAgent supervisor = new SupervisorAgent(group, List.of(
    new HITLApproval(Set.of("deploy", "delete"), approvalCallback)));

Guardrail.GuardrailResult result =
    supervisor.checkAction("agent-1", "deploy", Map.of("target", "production"));

Use this when the question is "may this agent perform this action?" Worked example: SupervisorAgent with Guardrails.

Content evaluation — com.tnsai.quality.tracing.guardrail.Guardrail

Observability SPI. Implementations (PiiGuardrail, custom toxicity checks) register on GuardrailRegistry and evaluate(input, output) after (or before) a traced response. This is content quality, not action authorization and not @InputGuardrail field validation.

GuardrailRegistry registry = new GuardrailRegistry();
registry.registerPostResponse(new PiiGuardrail());
List<GuardrailResult> results = registry.evaluatePostResponse(input, output);

Use this when the question is "does this text leak PII or fail a quality check?" Full API: Content Guardrails.

You might also be looking for