module AiGuard
AiGuard — block system/shell probes and scrub sensitive output from AI replies. Public: system_request?, scrub_urls, rejection_message, guard_prompt, output_leak?, filter_output Depends: (none) Tests: test/lib/ai_chat_core_test.rb
Constants
- OUTPUT_LEAK_PATTERN
- REJECTION
- SECURITY_PREAMBLE
- SYSTEM_REQUEST_PATTERN
Public Class Methods
Source
# File lib/ai/guard.rb, line 111 def self.filter_output(text) return rejection_message if output_leak?(text) text.to_s end
Source
# File lib/ai/guard.rb, line 90 def self.guard_prompt(prompt) "#{SECURITY_PREAMBLE}\n\n#{prompt}" end
Source
# File lib/ai/guard.rb, line 104 def self.output_leak?(text) normalized = text.to_s.strip return false if normalized.empty? normalized.match?(OUTPUT_LEAK_PATTERN) end
Source
# File lib/ai/guard.rb, line 86 def self.rejection_message REJECTION end
Source
# File lib/ai/guard.rb, line 82 def self.scrub_urls(text) text.gsub(%r{https?://\S+}i, " ") end
Source
# File lib/ai/guard.rb, line 75 def self.system_request?(text) normalized = text.to_s.strip return false if normalized.empty? scrub_urls(normalized).match?(SYSTEM_REQUEST_PATTERN) end