Class: RubyLLM::Contract::Step::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/contract/step/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, raw_output:, parsed_output:, validation_errors: [], trace: nil, observations: []) ⇒ Result

Returns a new instance of Result.



9
10
11
12
13
14
15
16
17
# File 'lib/ruby_llm/contract/step/result.rb', line 9

def initialize(status:, raw_output:, parsed_output:, validation_errors: [], trace: nil, observations: [])
  @status = status
  @raw_output = raw_output
  @parsed_output = parsed_output
  @validation_errors = validation_errors.freeze
  @observations = observations.freeze
  @trace = normalize_trace(trace)
  freeze
end

Instance Attribute Details

#observationsObject (readonly)

Returns the value of attribute observations.



7
8
9
# File 'lib/ruby_llm/contract/step/result.rb', line 7

def observations
  @observations
end

#parsed_outputObject (readonly)

Returns the value of attribute parsed_output.



7
8
9
# File 'lib/ruby_llm/contract/step/result.rb', line 7

def parsed_output
  @parsed_output
end

#raw_outputObject (readonly)

Returns the value of attribute raw_output.



7
8
9
# File 'lib/ruby_llm/contract/step/result.rb', line 7

def raw_output
  @raw_output
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/ruby_llm/contract/step/result.rb', line 7

def status
  @status
end

#traceObject (readonly)

Returns the value of attribute trace.



7
8
9
# File 'lib/ruby_llm/contract/step/result.rb', line 7

def trace
  @trace
end

#validation_errorsObject (readonly)

Returns the value of attribute validation_errors.



7
8
9
# File 'lib/ruby_llm/contract/step/result.rb', line 7

def validation_errors
  @validation_errors
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ruby_llm/contract/step/result.rb', line 23

def failed?
  @status != :ok
end

#ok?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ruby_llm/contract/step/result.rb', line 19

def ok?
  @status == :ok
end

#to_sObject



40
41
42
43
44
45
46
47
48
# File 'lib/ruby_llm/contract/step/result.rb', line 40

def to_s
  if ok?
    "#{@status} (#{@trace})"
  else
    errors = @validation_errors.first(3).join(", ")
    errors += ", ..." if @validation_errors.size > 3
    "#{@status}: #{errors}"
  end
end