Files
virtual-banker/backend/safety/filter.go

69 lines
1.5 KiB
Go

package safety
import (
"context"
"strings"
)
// Filter filters content for safety
type Filter interface {
Filter(ctx context.Context, text string) (*FilterResult, error)
}
// FilterResult contains filtering results
type FilterResult struct {
Allowed bool
Blocked bool
Redacted string
Categories []string // e.g., "profanity", "pii", "abuse"
}
// ContentFilter implements content filtering
type ContentFilter struct {
blockedWords []string
}
// NewContentFilter creates a new content filter
func NewContentFilter() *ContentFilter {
return &ContentFilter{
blockedWords: []string{
// Add blocked words/phrases
},
}
}
// Filter filters content
func (f *ContentFilter) Filter(ctx context.Context, text string) (*FilterResult, error) {
lowerText := strings.ToLower(text)
var categories []string
// Check for blocked words
for _, word := range f.blockedWords {
if strings.Contains(lowerText, strings.ToLower(word)) {
categories = append(categories, "profanity")
return &FilterResult{
Allowed: false,
Blocked: true,
Redacted: f.redactPII(text),
Categories: categories,
}, nil
}
}
// TODO: Add more sophisticated filtering (ML models, etc.)
return &FilterResult{
Allowed: true,
Blocked: false,
Redacted: f.redactPII(text),
}, nil
}
// redactPII redacts personally identifiable information
func (f *ContentFilter) redactPII(text string) string {
// TODO: Implement PII detection and redaction
// For now, return as-is
return text
}