we-promise/sure · error · Provenance::Citation::InvalidError

estimated values must carry a reliability grade, e.g. "#{EST

Error message

estimated values must carry a reliability grade, e.g. "#{ESTIMATED_PREFIX}... (grade: C)"

What it means

Provenance::Citation.parse! raises InvalidError when the citation carries the 'estimated: ' prefix but no grade suffix: estimates must end with ' (grade: A|B|C)'. Grades encode reliability (C is a proxy that should be re-derived later), so an estimate without one cannot age out or be triaged. The error message embeds a copy-pasteable example.

Source

Thrown at app/models/provenance/citation.rb:66

        end

        if (suffix = value.match(GRADE_SUFFIX)) && !GRADES.include?(suffix[:grade])
          raise InvalidError, "reliability grade must be one of #{GRADES.join(", ")} (got #{suffix[:grade].inspect})"
        end

        match = value.match(FORMAT)
        raise InvalidError, "source citation does not match #{grammar}" unless match

        text = match[:text].to_s.strip
        if text.length < MIN_TEXT_LENGTH
          raise InvalidError, "source citation must name the document it came from"
        end

        estimated = match[:estimated].present?
        grade = match[:grade]

        if estimated && grade.blank?
          raise InvalidError, "estimated values must carry a reliability grade, e.g. \"#{ESTIMATED_PREFIX}... (grade: C)\""
        end

        new(raw: value, text: text, estimated: estimated, grade: grade)
      end

      def valid?(raw)
        parse!(raw)
        true
      rescue InvalidError
        false
      end

      def grammar
        %(["#{ESTIMATED_PREFIX}"] citation [" (grade: #{GRADES.join("|")})"])
      end
    end

    def initialize(raw:, text:, estimated:, grade:)

View on GitHub (pinned to e69894adb9)

Solutions

  1. Append a grade suffix: 'estimated: interpolated from 2024 anchors (grade: C)'.
  2. Use lowercase 'grade:' exactly — '(Grade: C)' will not capture.
  3. If unsure of reliability, default to C (the designated proxy grade).
  4. Validate with Provenance::Citation.valid? and prompt the caller with the example from the message.

Example fix

# before
Provenance::Citation.parse!("estimated: interpolated from 2024 anchors")

# after
Provenance::Citation.parse!("estimated: interpolated from 2024 anchors (grade: C)")
Defensive patterns

Strategy: validation

Validate before calling

v = value.to_s
!v.start_with?("estimated: ") || v =~ /\(grade:\s*[ABC]\)\s*\z/

Type guard

def estimated_has_grade?(v)
  v = v.to_s.strip
  !v.start_with?(Provenance::Citation::ESTIMATED_PREFIX) || v.match?(/\(grade:\s*[ABC]\)\s*\z/)
end

Try / catch

begin
  Provenance::Citation.parse!(source)
rescue Provenance::Citation::InvalidError => e
  errors.add(:source, e.message) # message contains a valid example to copy
end

Prevention

When it happens

Trigger: Citations like 'estimated: interpolated from anchors' with no suffix, or where the suffix failed to capture (e.g. '(Grade: C)' with capital G does not match FORMAT's '(grade:' literal, leaving grade nil).

Common situations: Agent told to mark estimates but not grades; human capitalizing 'Grade:'; suffix typo after earlier normalization.

Related errors


AI-assisted analysis of we-promise/sure@e69894adb9 (2026-08-21). Data as JSON: /api/errors/22e381b55d31375d. Report an issue: GitHub.