Class: Langfuse::ItemResult

Inherits:
Object
  • Object
show all
Defined in:
lib/langfuse/item_result.rb

Overview

Result of processing a single item in an experiment run

Captures the task output, associated trace, evaluations, and any errors for one dataset item or data hash processed by ExperimentRunner.

Examples:

Successful result

result.success?     # => true
result.output       # => "Hello Alice!"
result.evaluations  # => [#<Evaluation name="relevance" value=0.9>]

Failed result

result.failed?        # => true
result.error.message  # => "API timeout"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item:, output: nil, trace_id: nil, observation_id: nil, evaluations: [], error: nil) ⇒ ItemResult

Returns a new instance of ItemResult.

Parameters:

  • item (DatasetItemClient, ExperimentItem)

    the input item

  • output (Object, nil) (defaults to: nil)

    task output

  • trace_id (String, nil) (defaults to: nil)

    trace ID from the observed execution

  • observation_id (String, nil) (defaults to: nil)

    observation (span) ID from the observed execution

  • evaluations (Array<Evaluation>) (defaults to: [])

    item-level evaluation results

  • error (StandardError, nil) (defaults to: nil)

    error if the task failed



32
33
34
35
36
37
38
39
# File 'lib/langfuse/item_result.rb', line 32

def initialize(item:, output: nil, trace_id: nil, observation_id: nil, evaluations: [], error: nil)
  @item = item
  @output = output
  @trace_id = trace_id
  @observation_id = observation_id
  @evaluations = evaluations
  @error = error
end

Instance Attribute Details

#errorDatasetItemClient, ... (readonly)

Returns:

  • (DatasetItemClient, ExperimentItem)

    the original input item

  • (Object, nil)

    task output, nil on failure

  • (String, nil)

    trace ID for the task execution

  • (String, nil)

    observation (span) ID for the task execution

  • (Array<Evaluation>)

    item-level evaluation results

  • (StandardError, nil)

    error raised during task execution



24
25
26
# File 'lib/langfuse/item_result.rb', line 24

def error
  @error
end

#evaluationsDatasetItemClient, ... (readonly)

Returns:

  • (DatasetItemClient, ExperimentItem)

    the original input item

  • (Object, nil)

    task output, nil on failure

  • (String, nil)

    trace ID for the task execution

  • (String, nil)

    observation (span) ID for the task execution

  • (Array<Evaluation>)

    item-level evaluation results

  • (StandardError, nil)

    error raised during task execution



24
25
26
# File 'lib/langfuse/item_result.rb', line 24

def evaluations
  @evaluations
end

#itemDatasetItemClient, ... (readonly)

Returns:

  • (DatasetItemClient, ExperimentItem)

    the original input item

  • (Object, nil)

    task output, nil on failure

  • (String, nil)

    trace ID for the task execution

  • (String, nil)

    observation (span) ID for the task execution

  • (Array<Evaluation>)

    item-level evaluation results

  • (StandardError, nil)

    error raised during task execution



24
25
26
# File 'lib/langfuse/item_result.rb', line 24

def item
  @item
end

#observation_idDatasetItemClient, ... (readonly)

Returns:

  • (DatasetItemClient, ExperimentItem)

    the original input item

  • (Object, nil)

    task output, nil on failure

  • (String, nil)

    trace ID for the task execution

  • (String, nil)

    observation (span) ID for the task execution

  • (Array<Evaluation>)

    item-level evaluation results

  • (StandardError, nil)

    error raised during task execution



24
25
26
# File 'lib/langfuse/item_result.rb', line 24

def observation_id
  @observation_id
end

#outputDatasetItemClient, ... (readonly)

Returns:

  • (DatasetItemClient, ExperimentItem)

    the original input item

  • (Object, nil)

    task output, nil on failure

  • (String, nil)

    trace ID for the task execution

  • (String, nil)

    observation (span) ID for the task execution

  • (Array<Evaluation>)

    item-level evaluation results

  • (StandardError, nil)

    error raised during task execution



24
25
26
# File 'lib/langfuse/item_result.rb', line 24

def output
  @output
end

#trace_idDatasetItemClient, ... (readonly)

Returns:

  • (DatasetItemClient, ExperimentItem)

    the original input item

  • (Object, nil)

    task output, nil on failure

  • (String, nil)

    trace ID for the task execution

  • (String, nil)

    observation (span) ID for the task execution

  • (Array<Evaluation>)

    item-level evaluation results

  • (StandardError, nil)

    error raised during task execution



24
25
26
# File 'lib/langfuse/item_result.rb', line 24

def trace_id
  @trace_id
end

Instance Method Details

#failed?Boolean

Returns true if the task raised an error.

Returns:

  • (Boolean)

    true if the task raised an error



45
# File 'lib/langfuse/item_result.rb', line 45

def failed? = !success?

#success?Boolean

Returns true if the task completed without error.

Returns:

  • (Boolean)

    true if the task completed without error



42
# File 'lib/langfuse/item_result.rb', line 42

def success? = error.nil?