judgeval

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

README

Judgeval Go SDK

Go Reference License

Installation

Find the latest version on pkg.go.dev.

Go modules:

go get github.com/JudgmentLabs/judgeval-go

Usage

Tracer
package main

import (
    "context"
    "os"

    judgeval "github.com/JudgmentLabs/judgeval-go"
)

func main() {
    client, err := judgeval.NewJudgeval(
        "my-project",
        judgeval.WithAPIKey(os.Getenv("JUDGMENT_API_KEY")),
        judgeval.WithOrganizationID(os.Getenv("JUDGMENT_ORG_ID")),
    )
    if err != nil {
        panic(err)
    }

    ctx := context.Background()
    tracer, err := client.Tracer.Create(ctx, judgeval.TracerCreateParams{})
    if err != nil {
        panic(err)
    }
    defer tracer.Shutdown(ctx)

    _, span := tracer.Span(ctx, "my-operation")
    defer span.End()

    tracer.SetInput(span, "user input data")
    tracer.SetOutput(span, "operation result")
}
Scorer
package main

import (
    "context"
    "os"

    judgeval "github.com/JudgmentLabs/judgeval-go"
)

func main() {
    client, err := judgeval.NewJudgeval(
        "my-project",
        judgeval.WithAPIKey(os.Getenv("JUDGMENT_API_KEY")),
        judgeval.WithOrganizationID(os.Getenv("JUDGMENT_ORG_ID")),
    )
    if err != nil {
        panic(err)
    }

    ctx := context.Background()
    tracer, err := client.Tracer.Create(ctx, judgeval.TracerCreateParams{})
    if err != nil {
        panic(err)
    }
    defer tracer.Shutdown(ctx)

    scorer := client.Scorers.BuiltIn.AnswerCorrectness(judgeval.AnswerCorrectnessScorerParams{
        Threshold: judgeval.Float(0.7),
    })

    example := judgeval.NewExample(judgeval.ExampleParams{
        "input":           "What is 2+2?",
        "actual_output":   "4",
        "expected_output": "4",
    })

    spanCtx, span := tracer.Span(ctx, "evaluation")
    defer span.End()

    tracer.AsyncEvaluate(spanCtx, scorer, example)
}

Documentation

License

Apache 2.0

Documentation

Overview

Package v1 provides the Judgment SDK v1 format for tracing, scoring, and evaluation.

Basic usage:

client, err := v1.NewJudgeval(
	"my-project",
	v1.WithAPIKey("your-api-key"),
	v1.WithOrganizationID("your-org-id"),
)
if err != nil {
	log.Fatal(err)
}

tracer, err := client.Tracer.Create(ctx, v1.TracerCreateParams{
	Initialize: v1.Bool(true),
})
if err != nil {
	log.Fatal(err)
}
defer tracer.Shutdown(ctx)

scorer := client.Scorers.BuiltIn.Faithfulness(v1.FaithfulnessScorerParams{
	Threshold: v1.Float(0.8),
})

example := v1.NewExample(v1.ExampleParams{
	Name: v1.String("test-example"),
	Properties: map[string]interface{}{
		"input": "What is AI?",
		"output": "Artificial Intelligence...",
	},
})

Index

Constants

View Source
const (
	AttributeKeysJudgmentSpanKind          = "judgment.span_kind"
	AttributeKeysJudgmentInput             = "judgment.input"
	AttributeKeysJudgmentOutput            = "judgment.output"
	AttributeKeysJudgmentOfflineMode       = "judgment.offline_mode"
	AttributeKeysJudgmentUpdateID          = "judgment.update_id"
	AttributeKeysJudgmentCustomerID        = "judgment.customer_id"
	AttributeKeysJudgmentSessionID         = "judgment.session_id"
	AttributeKeysJudgmentAgentID           = "judgment.agent_id"
	AttributeKeysJudgmentParentAgentID     = "judgment.parent_agent_id"
	AttributeKeysJudgmentAgentClassName    = "judgment.agent_class_name"
	AttributeKeysJudgmentAgentInstanceName = "judgment.agent_instance_name"
	AttributeKeysJudgmentIsAgentEntryPoint = "judgment.is_agent_entry_point"
	AttributeKeysJudgmentCumulativeLLMCost = "judgment.cumulative_llm_cost"
	AttributeKeysJudgmentStateBefore       = "judgment.state_before"
	AttributeKeysJudgmentStateAfter        = "judgment.state_after"
	AttributeKeysPendingTraceEval          = "judgment.pending_trace_eval"

	AttributeKeysGenAIPrompt                        = "gen_ai.prompt"
	AttributeKeysGenAICompletion                    = "gen_ai.completion"
	AttributeKeysGenAIRequestModel                  = "gen_ai.request.model"
	AttributeKeysGenAIResponseModel                 = "gen_ai.response.model"
	AttributeKeysGenAIResponseID                    = "gen_ai.response.id"
	AttributeKeysGenAISystem                        = "gen_ai.system"
	AttributeKeysGenAIUsageInputTokens              = "gen_ai.usage.input_tokens"
	AttributeKeysGenAIUsageOutputTokens             = "gen_ai.usage.output_tokens"
	AttributeKeysGenAIUsageTotalTokens              = "gen_ai.usage.total_tokens"
	AttributeKeysGenAIUsageCacheCreationInputTokens = "gen_ai.usage.cache_creation_input_tokens"
	AttributeKeysGenAIUsageCacheReadInputTokens     = "gen_ai.usage.cache_read_input_tokens"
	AttributeKeysGenAIRequestTemperature            = "gen_ai.request.temperature"
	AttributeKeysGenAIRequestMaxTokens              = "gen_ai.request.max_tokens"
	AttributeKeysGenAIRequestTopP                   = "gen_ai.request.top_p"
	AttributeKeysGenAIRequestTopK                   = "gen_ai.request.top_k"
	AttributeKeysGenAIRequestFrequencyPenalty       = "gen_ai.request.frequency_penalty"
	AttributeKeysGenAIRequestPresencePenalty        = "gen_ai.request.presence_penalty"
	AttributeKeysGenAIRequestStopSequences          = "gen_ai.request.stop_sequences"
	AttributeKeysGenAIRequestStream                 = "gen_ai.request.stream"
	AttributeKeysGenAIResponseFinishReasons         = "gen_ai.response.finish_reasons"
)
View Source
const (
	ResourceKeysServiceName          = "service.name"
	ResourceKeysTelemetrySDKLanguage = "telemetry.sdk.language"
	ResourceKeysTelemetrySDKName     = "telemetry.sdk.name"
	ResourceKeysTelemetrySDKVersion  = "telemetry.sdk.version"
	ResourceKeysJudgmentProjectID    = "judgment.project_id"
)
View Source
const TracerName = "judgeval"

Variables

View Source
var Version = strings.TrimSpace(versionFile)

Functions

func Bool

func Bool(v bool) *bool

func Float

func Float(v float64) *float64

func Int

func Int(v int) *int

func NewJudgmentSpanExporter added in v0.2.4

func NewJudgmentSpanExporter(ctx context.Context, endpoint string, apiClient *api.Client, projectID string) sdktrace.SpanExporter

func NewJudgmentSpanProcessor added in v0.2.4

func NewJudgmentSpanProcessor(
	delegate sdktrace.SpanProcessor,
	lifecycle []sdktrace.SpanProcessor,
) sdktrace.SpanProcessor

func NewNoOpSpanExporter added in v0.2.4

func NewNoOpSpanExporter() sdktrace.SpanExporter

func NewNoOpSpanProcessor added in v0.2.4

func NewNoOpSpanProcessor() sdktrace.SpanProcessor

func String

func String(v string) *string

Types

type APIScorerType

type APIScorerType string
const (
	APIScorerTypePromptScorer      APIScorerType = "Prompt Scorer"
	APIScorerTypeTracePromptScorer APIScorerType = "Trace Prompt Scorer"
	APIScorerTypeFaithfulness      APIScorerType = "Faithfulness"
	APIScorerTypeAnswerRelevancy   APIScorerType = "Answer Relevancy"
	APIScorerTypeAnswerCorrectness APIScorerType = "Answer Correctness"
	APIScorerTypeCustom            APIScorerType = "Custom"
)

func (APIScorerType) String

func (t APIScorerType) String() string

type AnswerCorrectnessScorer

type AnswerCorrectnessScorer struct {
	// contains filtered or unexported fields
}

func (AnswerCorrectnessScorer) GetName

func (s AnswerCorrectnessScorer) GetName() string

func (*AnswerCorrectnessScorer) GetScorerConfig

func (s *AnswerCorrectnessScorer) GetScorerConfig() *models.ScorerConfig

type AnswerCorrectnessScorerParams

type AnswerCorrectnessScorerParams struct {
	Threshold  *float64
	Name       *string
	StrictMode *bool
	Model      *string
}

type AnswerRelevancyScorer

type AnswerRelevancyScorer struct {
	// contains filtered or unexported fields
}

func (AnswerRelevancyScorer) GetName

func (s AnswerRelevancyScorer) GetName() string

func (*AnswerRelevancyScorer) GetScorerConfig

func (s *AnswerRelevancyScorer) GetScorerConfig() *models.ScorerConfig

type AnswerRelevancyScorerParams

type AnswerRelevancyScorerParams struct {
	Threshold  *float64
	Name       *string
	StrictMode *bool
	Model      *string
}

type BaseScorer

type BaseScorer interface {
	GetName() string
	GetScorerConfig() *models.ScorerConfig
}

type BaseTracer

type BaseTracer struct {
	// contains filtered or unexported fields
}

func (*BaseTracer) AsyncEvaluate

func (b *BaseTracer) AsyncEvaluate(ctx context.Context, scorer BaseScorer, example *Example)

func (*BaseTracer) AsyncTraceEvaluate

func (b *BaseTracer) AsyncTraceEvaluate(ctx context.Context, scorer BaseScorer)

func (*BaseTracer) EndSpan

func (b *BaseTracer) EndSpan(span trace.Span)

func (*BaseTracer) GetTracer

func (b *BaseTracer) GetTracer() trace.Tracer

func (*BaseTracer) SetAttribute

func (b *BaseTracer) SetAttribute(span trace.Span, key string, value interface{})

func (*BaseTracer) SetAttributes

func (b *BaseTracer) SetAttributes(span trace.Span, attrs map[string]interface{})

func (*BaseTracer) SetCustomerID added in v0.3.0

func (b *BaseTracer) SetCustomerID(ctx context.Context, customerID string) context.Context

func (*BaseTracer) SetGeneralSpan

func (b *BaseTracer) SetGeneralSpan(span trace.Span)

func (*BaseTracer) SetInput

func (b *BaseTracer) SetInput(span trace.Span, input interface{})

func (*BaseTracer) SetLLMSpan

func (b *BaseTracer) SetLLMSpan(span trace.Span)

func (*BaseTracer) SetOutput

func (b *BaseTracer) SetOutput(span trace.Span, output interface{})

func (*BaseTracer) SetSessionID added in v0.3.0

func (b *BaseTracer) SetSessionID(ctx context.Context, sessionID string) context.Context

func (*BaseTracer) SetSpanKind

func (b *BaseTracer) SetSpanKind(span trace.Span, kind string)

func (*BaseTracer) SetToolSpan

func (b *BaseTracer) SetToolSpan(span trace.Span)

func (*BaseTracer) Span

func (b *BaseTracer) Span(ctx context.Context, spanName string) (context.Context, trace.Span)

func (*BaseTracer) StartSpan

func (b *BaseTracer) StartSpan(ctx context.Context, spanName string) (context.Context, trace.Span)

type BuiltInScorersFactory

type BuiltInScorersFactory struct{}

func (*BuiltInScorersFactory) AnswerCorrectness

func (*BuiltInScorersFactory) AnswerRelevancy

func (*BuiltInScorersFactory) Faithfulness

type CustomScorer

type CustomScorer struct {
	// contains filtered or unexported fields
}

func (*CustomScorer) GetBaseScorer added in v0.3.0

func (s *CustomScorer) GetBaseScorer() models.BaseScorer

func (*CustomScorer) GetClassName

func (s *CustomScorer) GetClassName() string

func (*CustomScorer) GetName

func (s *CustomScorer) GetName() string

func (*CustomScorer) GetScorerConfig

func (s *CustomScorer) GetScorerConfig() *models.ScorerConfig

func (*CustomScorer) IsServerHosted

func (s *CustomScorer) IsServerHosted() bool

type CustomScorerFactory

type CustomScorerFactory struct{}

func (*CustomScorerFactory) Get

func (f *CustomScorerFactory) Get(name string, className string) (*CustomScorer, error)

type CustomScorerParams

type CustomScorerParams struct {
	Name      string
	ClassName *string
}

type CustomerIDProcessor added in v0.3.0

type CustomerIDProcessor struct{}

func (*CustomerIDProcessor) ForceFlush added in v0.3.0

func (p *CustomerIDProcessor) ForceFlush(ctx context.Context) error

func (*CustomerIDProcessor) OnEnd added in v0.3.0

func (*CustomerIDProcessor) OnStart added in v0.3.0

func (p *CustomerIDProcessor) OnStart(parentContext context.Context, span sdktrace.ReadWriteSpan)

func (*CustomerIDProcessor) Shutdown added in v0.3.0

func (p *CustomerIDProcessor) Shutdown(ctx context.Context) error

type Evaluation

type Evaluation struct {
	// contains filtered or unexported fields
}

type EvaluationCreateParams

type EvaluationCreateParams struct {
}

type EvaluationFactory

type EvaluationFactory struct {
	// contains filtered or unexported fields
}

func (*EvaluationFactory) Create

type Example

type Example struct {
	// contains filtered or unexported fields
}

func NewExample

func NewExample(params ExampleParams) *Example

func (*Example) GetCreatedAt

func (e *Example) GetCreatedAt() string

func (*Example) GetExampleID

func (e *Example) GetExampleID() string

func (*Example) GetName

func (e *Example) GetName() *string

func (*Example) GetProperties

func (e *Example) GetProperties() map[string]interface{}

func (*Example) GetProperty

func (e *Example) GetProperty(key string) interface{}

func (*Example) SetName

func (e *Example) SetName(name string)

func (*Example) SetProperty

func (e *Example) SetProperty(key string, value interface{}) *Example

type ExampleParams

type ExampleParams map[string]any

type FaithfulnessScorer

type FaithfulnessScorer struct {
	// contains filtered or unexported fields
}

func (FaithfulnessScorer) GetName

func (s FaithfulnessScorer) GetName() string

func (*FaithfulnessScorer) GetScorerConfig

func (s *FaithfulnessScorer) GetScorerConfig() *models.ScorerConfig

type FaithfulnessScorerParams

type FaithfulnessScorerParams struct {
	Threshold  *float64
	Name       *string
	StrictMode *bool
	Model      *string
}

type FilterTracerFunc added in v0.2.4

type FilterTracerFunc func(name string, opts ...trace.TracerOption) bool

type Judgeval

type Judgeval struct {
	Tracer     *TracerFactory
	Scorers    *ScorersFactory
	Evaluation *EvaluationFactory
	// contains filtered or unexported fields
}

func NewJudgeval

func NewJudgeval(projectName string, opts ...Option) (*Judgeval, error)

type JudgevalTracerLike added in v0.2.7

type JudgevalTracerLike interface {
	Initialize(ctx context.Context) error
	ForceFlush(ctx context.Context) error
	Shutdown(ctx context.Context) error

	GetTracer() trace.Tracer
	Span(ctx context.Context, spanName string) (context.Context, trace.Span)
	SetSpanKind(span trace.Span, kind string)
	SetLLMSpan(span trace.Span)
	SetToolSpan(span trace.Span)
	SetGeneralSpan(span trace.Span)
	SetAttribute(span trace.Span, key string, value interface{})
	SetAttributes(span trace.Span, attrs map[string]interface{})
	SetInput(span trace.Span, input interface{})
	SetOutput(span trace.Span, output interface{})
	SetCustomerID(ctx context.Context, customerID string) context.Context
	SetSessionID(ctx context.Context, sessionID string) context.Context
	AsyncEvaluate(ctx context.Context, scorer BaseScorer, example *Example)
	AsyncTraceEvaluate(ctx context.Context, scorer BaseScorer)
	StartSpan(ctx context.Context, spanName string) (context.Context, trace.Span)
	EndSpan(span trace.Span)
}

type JudgmentSpanExporter added in v0.2.4

type JudgmentSpanExporter struct {
	// contains filtered or unexported fields
}

func (*JudgmentSpanExporter) ExportSpans added in v0.2.4

func (e *JudgmentSpanExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error

func (*JudgmentSpanExporter) Shutdown added in v0.2.4

func (e *JudgmentSpanExporter) Shutdown(ctx context.Context) error

type JudgmentSpanProcessor added in v0.2.4

type JudgmentSpanProcessor struct {
	// contains filtered or unexported fields
}

func (*JudgmentSpanProcessor) ForceFlush added in v0.2.4

func (p *JudgmentSpanProcessor) ForceFlush(ctx context.Context) error

func (*JudgmentSpanProcessor) OnEnd added in v0.2.4

func (*JudgmentSpanProcessor) OnStart added in v0.2.4

func (p *JudgmentSpanProcessor) OnStart(parentContext context.Context, span sdktrace.ReadWriteSpan)

func (*JudgmentSpanProcessor) Shutdown added in v0.2.4

func (p *JudgmentSpanProcessor) Shutdown(ctx context.Context) error

type JudgmentTracerProvider added in v0.2.4

type JudgmentTracerProvider struct {
	embedded.TracerProvider
	// contains filtered or unexported fields
}

func NewJudgmentTracerProvider added in v0.2.4

func NewJudgmentTracerProvider(config *JudgmentTracerProviderConfig, opts ...sdktrace.TracerProviderOption) *JudgmentTracerProvider

func (*JudgmentTracerProvider) ForceFlush added in v0.2.4

func (j *JudgmentTracerProvider) ForceFlush(ctx context.Context) error

func (*JudgmentTracerProvider) Shutdown added in v0.2.4

func (j *JudgmentTracerProvider) Shutdown(ctx context.Context) error

func (*JudgmentTracerProvider) Tracer added in v0.2.4

func (j *JudgmentTracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer

type JudgmentTracerProviderConfig added in v0.2.4

type JudgmentTracerProviderConfig struct {
	// FilterTracer filters what tracers are allowed to be created. This is useful when you want to disable any instrumentation
	// or control instrumentation that is automatically created by auto-instrumentations or other libraries.
	// If set to return false, the caller will receive a NoOpTracer.
	// The function receives the tracer name and options to check if it should be allowed.
	// Returns true if the tracer should be allowed, false otherwise.
	FilterTracer FilterTracerFunc
}

type NoOpSpanExporter added in v0.2.4

type NoOpSpanExporter struct{}

func (*NoOpSpanExporter) ExportSpans added in v0.2.4

func (e *NoOpSpanExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error

func (*NoOpSpanExporter) Shutdown added in v0.2.4

func (e *NoOpSpanExporter) Shutdown(ctx context.Context) error

type NoOpSpanProcessor added in v0.2.4

type NoOpSpanProcessor struct{}

func (*NoOpSpanProcessor) ForceFlush added in v0.2.4

func (p *NoOpSpanProcessor) ForceFlush(ctx context.Context) error

func (*NoOpSpanProcessor) OnEnd added in v0.2.4

func (*NoOpSpanProcessor) OnStart added in v0.2.4

func (p *NoOpSpanProcessor) OnStart(parentContext context.Context, span sdktrace.ReadWriteSpan)

func (*NoOpSpanProcessor) Shutdown added in v0.2.4

func (p *NoOpSpanProcessor) Shutdown(ctx context.Context) error

type NoOpTracer added in v0.2.7

type NoOpTracer struct {
	*BaseTracer
}

NoOpTracer is a no-op implementation of JudgevalTracerLike.

func NewNoOpTracer added in v0.2.7

func NewNoOpTracer() *NoOpTracer

func (*NoOpTracer) ForceFlush added in v0.2.7

func (n *NoOpTracer) ForceFlush(ctx context.Context) error

func (*NoOpTracer) Initialize added in v0.2.7

func (n *NoOpTracer) Initialize(ctx context.Context) error

func (*NoOpTracer) Shutdown added in v0.2.7

func (n *NoOpTracer) Shutdown(ctx context.Context) error

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithAPIKey

func WithAPIKey(key string) Option

func WithAPIURL

func WithAPIURL(url string) Option

func WithOrganizationID

func WithOrganizationID(id string) Option

type PromptScorer

type PromptScorer struct {
	// contains filtered or unexported fields
}

func (*PromptScorer) AppendToPrompt

func (s *PromptScorer) AppendToPrompt(addition string)

func (*PromptScorer) GetDescription

func (s *PromptScorer) GetDescription() string

func (*PromptScorer) GetModel

func (s *PromptScorer) GetModel() string

func (*PromptScorer) GetName

func (s *PromptScorer) GetName() string

func (*PromptScorer) GetOptions

func (s *PromptScorer) GetOptions() map[string]float64

func (*PromptScorer) GetPrompt

func (s *PromptScorer) GetPrompt() string

func (*PromptScorer) GetScorerConfig

func (s *PromptScorer) GetScorerConfig() *models.ScorerConfig

func (*PromptScorer) GetThreshold

func (s *PromptScorer) GetThreshold() float64

func (*PromptScorer) SetDescription

func (s *PromptScorer) SetDescription(description string)

func (*PromptScorer) SetModel

func (s *PromptScorer) SetModel(model string)

func (*PromptScorer) SetOptions

func (s *PromptScorer) SetOptions(options map[string]float64)

func (*PromptScorer) SetPrompt

func (s *PromptScorer) SetPrompt(prompt string)

func (*PromptScorer) SetThreshold

func (s *PromptScorer) SetThreshold(threshold float64)

type PromptScorerFactory

type PromptScorerFactory struct {
	// contains filtered or unexported fields
}

func (*PromptScorerFactory) Get

type ScorerConfig

type ScorerConfig = models.ScorerConfig

type ScorersFactory

type ScorersFactory struct {
	BuiltIn           *BuiltInScorersFactory
	PromptScorer      *PromptScorerFactory
	TracePromptScorer *PromptScorerFactory
	CustomScorer      *CustomScorerFactory
	// contains filtered or unexported fields
}

type SerializerFunc

type SerializerFunc func(interface{}) (string, error)

type SessionIDProcessor added in v0.3.0

type SessionIDProcessor struct{}

func (*SessionIDProcessor) ForceFlush added in v0.3.0

func (p *SessionIDProcessor) ForceFlush(ctx context.Context) error

func (*SessionIDProcessor) OnEnd added in v0.3.0

func (*SessionIDProcessor) OnStart added in v0.3.0

func (p *SessionIDProcessor) OnStart(parentContext context.Context, span sdktrace.ReadWriteSpan)

func (*SessionIDProcessor) Shutdown added in v0.3.0

func (p *SessionIDProcessor) Shutdown(ctx context.Context) error

type Tracer

type Tracer struct {
	*BaseTracer
	// contains filtered or unexported fields
}

func (*Tracer) ForceFlush

func (t *Tracer) ForceFlush(ctx context.Context) error

func (*Tracer) Initialize

func (t *Tracer) Initialize(ctx context.Context) error

func (*Tracer) Shutdown

func (t *Tracer) Shutdown(ctx context.Context) error

type TracerCreateParams

type TracerCreateParams struct {
	EnableEvaluation   *bool
	Serializer         SerializerFunc
	ResourceAttributes map[string]any
	FilterTracer       FilterTracerFunc
	Initialize         *bool
}

type TracerFactory

type TracerFactory struct {
	// contains filtered or unexported fields
}

func (*TracerFactory) Create

func (f *TracerFactory) Create(ctx context.Context, params TracerCreateParams) (*Tracer, error)

Directories

Path Synopsis
Package integrations provides middleware for instrumenting LLM client libraries with Judgment tracing.
Package integrations provides middleware for instrumenting LLM client libraries with Judgment tracing.
internal
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL