Skip to main content
The ComplianceEngine class provides offline compliance monitoring with built-in and custom rules for banking and financial services. It evaluates agent interactions against regulatory requirements like PII detection, fair lending, and BSA/AML compliance.

Constructor

ComplianceEngine(config)

Creates a new ComplianceEngine instance with the specified configuration.
ComplianceEngineConfig
required
Configuration object for the compliance engine.
Example:

Core Methods

evaluateInteraction(context)

Evaluates an agent interaction against all active compliance rules.
InteractionContext
required
The interaction context to evaluate for compliance violations.
Returns: ComplianceResult Example:

Rule Management

addRule(rule)

Adds a new compliance rule to the engine or updates an existing rule.
ComplianceRule
required
The compliance rule to add or update.
Returns: void Example:

removeRule(ruleId)

Removes a compliance rule from the engine.
string
required
The ID of the rule to remove.
Returns: boolean - True if the rule was found and removed, false otherwise. Example:

setRuleActive(ruleId, isActive)

Activates or deactivates a compliance rule without removing it.
string
required
The ID of the rule to activate/deactivate.
boolean
required
Whether the rule should be active.
Returns: boolean - True if the rule was found and updated, false otherwise. Example:

getActiveRules()

Returns all currently active compliance rules. Returns: ComplianceRule[] Example:

getAllRules()

Returns all compliance rules (both active and inactive). Returns: ComplianceRule[] Example:

getRule(ruleId)

Retrieves a specific compliance rule by ID.
string
required
The ID of the rule to retrieve.
Returns: ComplianceRule | undefined Example:

Built-in Compliance Rules

The ComplianceEngine comes with several built-in rules for common banking compliance requirements:

PII Detection Rules

Category: privacy Severity: violation Description: Detects potential PII like phone numbers and emails Patterns: Email addresses, phone numbers (US format) Risk Score: 15-20 points per detection
Category: privacy Severity: violation Description: Robust SSN validation with format checking Patterns: Valid SSN formats, excludes known invalid ranges Risk Score: 50 points per valid SSN detected

Fair Lending Rules

Category: fair_lending Severity: violation Description: Detects potentially discriminatory language Patterns: “people like you”, “your kind”, “typical for”, “based on your background” Risk Score: 60 points per discriminatory phrase

BSA/AML Rules

Additional BSA/AML rules can be added through custom rule implementation.

Custom Rule Examples

Advanced PII Detection

BSA/AML Suspicious Activity Detection

Consumer Protection Rule

ComplianceResult Type

The result returned by evaluateInteraction() and rule functions:

Best Practices

  • Keep rules focused: Each rule should check for one specific type of violation
  • Use descriptive IDs: Rule IDs should be clear and consistent
  • Provide context: Include relevant context in violation objects
  • Test thoroughly: Test rules with various input scenarios
  • Document patterns: Clearly document what patterns trigger violations
  • Optimize regex patterns: Use efficient regular expressions
  • Cache compiled patterns: Pre-compile complex patterns in rule constructors
  • Limit text processing: Only process relevant text content
  • Set appropriate severity: Use ‘info’ for low-impact violations
  • Batch evaluations: Process multiple interactions efficiently
  • Regular rule updates: Keep rules current with regulatory changes
  • Audit trail: Log all rule changes and activations
  • False positive monitoring: Track and reduce false positives
  • Risk scoring consistency: Use consistent risk scoring across rules
  • Review thresholds: Set appropriate review thresholds for your organization
  • Stay current: Keep up with regulatory guidance and changes
  • Industry standards: Follow established compliance patterns
  • Documentation: Maintain thorough documentation of compliance procedures
  • Human oversight: Always include human review for high-risk violations
  • Regular auditing: Perform regular compliance audits and assessments

Error Handling

The ComplianceEngine handles errors gracefully:
Individual rule failures are logged but don’t prevent other rules from executing.

Next Steps

Custom Rules Example

See detailed examples of creating custom compliance rules

Compliance Monitoring

Learn about comprehensive compliance monitoring workflows

Banking Workflows

Implement compliance in banking workflows

AgentMonitor Class

Learn about the main monitoring class