Module: Langfuse::Types

Defined in:
lib/langfuse/types.rb

Overview

Type definitions and constants for Langfuse domain models

Provides observation type constants and attribute classes for type-safe handling of Langfuse observations and traces.

Examples:

Using observation types

Langfuse::Types::OBSERVATION_TYPES # => ["span", "generation", ...]
Langfuse::Types::LEVELS # => ["DEBUG", "DEFAULT", "WARNING", "ERROR"]

Using attribute classes

attrs = Langfuse::Types::SpanAttributes.new(
  input: { query: "test" },
  level: "DEFAULT",
  metadata: { source: "api" }
)
attrs.to_h # => { input: {...}, level: "DEFAULT", metadata: {...} }

Defined Under Namespace

Classes: EmbeddingAttributes, GenerationAttributes, SpanAttributes, TraceAttributes

Constant Summary collapse

OBSERVATION_TYPES =

Types of observations that can be created in Langfuse

  • span: General-purpose observations for tracking operations, functions, or logical units of work
  • generation: Specialized observations for LLM calls with model parameters, usage, and costs
  • event: Point-in-time occurrences or log entries within a trace
  • embedding: Observations for embedding generation calls
  • agent: Observations for agent-based workflows
  • tool: Observations for tool/function calls
  • chain: Observations for chain-based workflows
  • retriever: Observations for retrieval operations
  • evaluator: Observations for evaluation operations
  • guardrail: Observations for guardrail checks

Returns:

  • (Array<String>)

    Array of observation type strings

%w[
  span generation event embedding
  agent tool chain retriever
  evaluator guardrail
].freeze
LEVELS =

Severity levels for observations in Langfuse

Used to categorize the importance or severity of observations:

  • DEBUG: Detailed diagnostic information
  • DEFAULT: Normal operation information
  • WARNING: Potentially problematic situations
  • ERROR: Error conditions that need attention

Returns:

  • (Array<String>)

    Array of level strings

%w[DEBUG DEFAULT WARNING ERROR].freeze
SCORE_DATA_TYPES =

Data types for Langfuse scores

Used to categorize score values:

  • numeric: Numeric values (Integer, Float, BigDecimal)
  • boolean: Boolean values (true/false or 0/1)
  • categorical: String values for categorical scores
  • text: Free-form String values (1 to 500 characters)
  • correction: Corrected output String attached to a trace or observation (conventionally named "output")

Returns:

  • (Hash<Symbol, String>)

    Hash mapping symbol keys to API string values

{
  numeric: "NUMERIC",
  boolean: "BOOLEAN",
  categorical: "CATEGORICAL",
  text: "TEXT",
  correction: "CORRECTION"
}.freeze
VALID_SCORE_DATA_TYPES =

Valid score data type symbols

Returns:

  • (Array<Symbol>)

    Array of valid data type symbols

SCORE_DATA_TYPES.keys.freeze
EXPERIMENT_SCORE_DATA_TYPES =

Score data types accepted by experiment evaluations

Experiment evaluations represent metrics, so this set is intentionally narrower than SCORE_DATA_TYPES: text notes and corrected outputs are general scores, not experiment metrics (matching langfuse-python).

Returns:

  • (Array<Symbol>)

    Array of experiment-safe data type symbols

%i[numeric boolean categorical].freeze
EventAttributes =

Alias for event observation attributes (same as SpanAttributes)

SpanAttributes
AgentAttributes =

Alias for agent observation attributes (same as SpanAttributes)

SpanAttributes
ToolAttributes =

Alias for tool observation attributes (same as SpanAttributes)

SpanAttributes
ChainAttributes =

Alias for chain observation attributes (same as SpanAttributes)

SpanAttributes
RetrieverAttributes =

Alias for retriever observation attributes (same as SpanAttributes)

SpanAttributes
EvaluatorAttributes =

Alias for evaluator observation attributes (same as SpanAttributes)

SpanAttributes
GuardrailAttributes =

Alias for guardrail observation attributes (same as SpanAttributes)

SpanAttributes