structjudge

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package structjudge adapts an injected structured-output completion client to Reliquary's judgment contracts.

Structured-output providers force a JSON Schema on their responses, which is exactly what the strict judgment primitives need: a Choice distribution that sums to one, a Score in [0, 100], a Noul verdict from a two-value enum. This adapter owns the per-primitive response schemas, renders each judgment request into one instruction, forwards it to the injected Client, maps the JSON response back, and validates the pair with the judgment package. Transport, credentials, endpoints, retries, and model choice belong entirely to the injected Client; the adapter performs no network, file, or environment I/O and retains no state beyond the client reference.

The motivating client is a multi-provider LLM gateway (for example Wormhole's structured builder), wired with a few lines of caller glue:

type wormholeJudge struct{ w *wormhole.Wormhole }

func (g wormholeJudge) Generate(ctx context.Context, r structjudge.Request) ([]byte, error) {
	resp, err := g.w.Structured().Model("…").Prompt(r.Instruction).Schema(r.Schema).Do(ctx)
	// … extract the JSON payload from resp …
}

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrGenerate = errors.New("structjudge adapter: generate")

ErrGenerate reports a client-side generation failure.

View Source
var ErrInvalidResponse = errors.New("structjudge adapter: invalid response")

ErrInvalidResponse reports a response that is not valid JSON for the primitive's schema or fails the judgment contract.

View Source
var ErrNilClient = errors.New("structjudge adapter: client must not be nil")

ErrNilClient reports construction with a missing client.

Functions

This section is empty.

Types

type Adapter

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

Adapter maps judgment primitives onto an injected Client.

func New

func New(client Client) (*Adapter, error)

New constructs an Adapter over client.

Example
package main

import (
	"context"
	"fmt"

	"github.com/dotcommander/reliquary/adapter/structjudge"
)

type staticStructClient struct{}

func (staticStructClient) Generate(_ context.Context, _ structjudge.Request) ([]byte, error) {
	return []byte(`{"selected":"a","distribution":{"a":1.0},"confidence":1.0}`), nil
}

func main() {
	judge, err := structjudge.New(staticStructClient{})
	fmt.Println(judge != nil, err == nil)
}
Output:
true true

func (*Adapter) Ask

func (a *Adapter) Ask(ctx context.Context, request judgment.NoulRequest) (judgment.Noul, error)

Ask renders the noul request into one instruction, generates a schema-forced response, and validates the mapped verdict.

func (*Adapter) Choose

func (a *Adapter) Choose(ctx context.Context, request judgment.ChoiceRequest) (judgment.Choice, error)

Choose renders the choice request into one instruction, generates a schema-forced response, and validates the mapped choice.

func (*Adapter) Score

func (a *Adapter) Score(ctx context.Context, request judgment.ScoreRequest) (judgment.Score, error)

Score renders the score request into one instruction, generates a schema-forced response, and validates the mapped score.

type Client

type Client interface {
	Generate(ctx context.Context, request Request) ([]byte, error)
}

Client generates one schema-forced JSON completion. Implementations own the provider, transport, credentials, and retry policy.

type Request

type Request struct {
	// Instruction is the complete prompt for the judgment.
	Instruction string
	// Schema is the JSON Schema the response must satisfy.
	Schema []byte
}

Request is one structured completion: the full instruction text and the JSON Schema the response must satisfy.

Jump to

Keyboard shortcuts

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