Class: SentinelRb::Analyzers::IrrelevantInfo
- Defined in:
- lib/sentinel_rb/analyzers/irrelevant_info.rb
Overview
A1: Irrelevant Information Detector Detects prompts containing irrelevant or noisy information that could degrade LLM performance or confuse the model.
Constant Summary collapse
- ANALYZER_ID =
"A1"
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from SentinelRb::Analyzers::Base
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sentinel_rb/analyzers/irrelevant_info.rb', line 13 def call findings = [] begin # Get relevance analysis from LLM analysis = @client.analyze_content(@prompt) relevance_score = analysis[:relevance_score] threshold = @config.relevance_threshold # Check if relevance score is below threshold if threshold_exceeded?(relevance_score, threshold, higher_is_better: true) findings << create_finding( id: ANALYZER_ID, level: :warn, message: "Prompt contains potentially irrelevant information (relevance score: #{relevance_score.round(3)} < threshold: #{threshold})", details: { relevance_score: relevance_score, threshold: threshold, raw_response: analysis[:raw_response], suggestions: generate_suggestions(relevance_score) } ) end rescue StandardError => e # If LLM analysis fails, we'll rely on heuristic checks only # Log the error but don't fail the entire analysis if @config["log_level"] == "debug" warn "Warning: LLM analysis failed for irrelevant info detection: #{e.}" end end # Additional heuristic checks (these work even if LLM fails) findings.concat(check_length_ratio) findings.concat(check_repetitive_content) findings.concat(check_off_topic_markers) findings end |