Exception: DSPy::PredictionInvalidError

Inherits:
StandardError
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dspy/predict.rb

Overview

Exception raised when prediction fails validation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors, context: nil) ⇒ PredictionInvalidError

Returns a new instance of PredictionInvalidError.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dspy/predict.rb', line 16

def initialize(errors, context: nil)
  @errors = errors
  @context = context
  
  # Format the error message using ErrorFormatter for better readability
  formatted_message = if errors.key?(:output) && errors[:output].is_a?(String)
    # This is likely a type validation error from Sorbet
    formatted = DSPy::ErrorFormatter.format_error(errors[:output], context)
    "Prediction validation failed:\n\n#{formatted}"
  elsif errors.key?(:input) && errors[:input].is_a?(String)
    # This is an input validation error
    formatted = DSPy::ErrorFormatter.format_error(errors[:input], context)
    "Input validation failed:\n\n#{formatted}"
  else
    # Fallback to original format for any other error structure
    "Prediction validation failed: #{errors}"
  end
  
  super(formatted_message)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



41
42
43
# File 'lib/dspy/predict.rb', line 41

def context
  @context
end

#errorsObject (readonly)

Returns the value of attribute errors.



38
39
40
# File 'lib/dspy/predict.rb', line 38

def errors
  @errors
end