Module: RailsAiBridge::Tools::ConfidenceTag

Defined in:
lib/rails_ai_bridge/tools/confidence_tag.rb

Overview

Maps an evidence source to a compact [VERIFIED] / [INFERRED] tag.

Verified only when ActiveRecord reflection or rubydex/Prism agrees. Source-regex extracts and static schema parses stay inferred. Unknown sources under-claim as inferred — there is no third status.

Constant Summary collapse

VERIFIED =
'[VERIFIED]'
INFERRED =
'[INFERRED]'
VERIFIED_SOURCES =
%i[reflection rubydex prism live].freeze

Class Method Summary collapse

Class Method Details

Summarizes how many facts came from each evidence source.

Parameters:

  • counts (Hash) —

    fact count per source, keyed by Symbol or String, in display order

Returns:

  • (String, nil) —

    e.g. "Verification: [VERIFIED] reflection (3) · [INFERRED] regex (2)", or nil when no source has a positive count



38
39
40
41
42
43
44
45
46
47
# File 'lib/rails_ai_bridge/tools/confidence_tag.rb', line 38

def footer(counts)
  parts = counts.filter_map do |source, count|
    next unless count.to_i.positive?

    "#{tag(source)} #{source} (#{count})"
  end
  return if parts.empty?

  "Verification: #{parts.join(' · ')}"
end

.tag(source) ⇒ String

Returns [VERIFIED] or [INFERRED].

Parameters:

  • source (Symbol, String, nil) —

    evidence origin

Returns:

  • (String) —

    [VERIFIED] or [INFERRED]



20
21
22
23
24
# File 'lib/rails_ai_bridge/tools/confidence_tag.rb', line 20

def tag(source)
  return INFERRED if source.nil?

  VERIFIED_SOURCES.include?(source.to_sym) ? VERIFIED : INFERRED
end

.tagged(text, source) ⇒ String

Returns text with a trailing confidence tag.

Parameters:

  • text (String) —

    fact line without a tag

  • source (Symbol, String, nil) —

    evidence origin

Returns:

  • (String) —

    text with a trailing confidence tag



29
30
31
# File 'lib/rails_ai_bridge/tools/confidence_tag.rb', line 29

def tagged(text, source)
  "#{text} #{tag(source)}"
end