Class CommunicationEnforcer

java.lang.Object
com.tnsai.communication.CommunicationEnforcer

public final class CommunicationEnforcer extends Object
Enforces communication policies defined via @Communication annotation.

This class handles runtime enforcement of:

  • Language restrictions (responses must be in allowed languages)
  • Response length limits
  • Response format validation

Usage


 CommunicationEnforcer enforcer = new CommunicationEnforcer();

 // Get system prompt constraints
 String constraints = enforcer.buildConstraintsPrompt(role);

 // Validate response
 enforcer.validateResponse(role, response);
 
Author:
TnsAI Team
See Also:
  • Constructor Details

    • CommunicationEnforcer

      public CommunicationEnforcer()
  • Method Details

    • buildConstraintsPrompt

      public String buildConstraintsPrompt(Role role)
      Builds a system prompt section that describes communication constraints.
      Parameters:
      role - the role with communication settings
      Returns:
      constraint description for system prompt
    • validateResponse

      public void validateResponse(Role role, String response)
      Validates a response against communication constraints.
      Parameters:
      role - the role with communication settings
      response - the response to validate
      Throws:
      CommunicationViolationException - if validation fails
    • truncateIfNeeded

      public String truncateIfNeeded(Role role, String response)
      Truncates response to max length if needed.
      Parameters:
      role - the role with communication settings
      response - the response to truncate
      Returns:
      truncated response