judgement

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 12 Imported by: 0

README

judgement

Jev decisions, ready for agents and scripts.

CI Go Reference

A Go library and CLI for TypeSafe AI's System One API. Use Jev to classify records, evaluate yes/no questions, and score content against rubrics from your own code. No runtime dependencies beyond the Go standard library.

This is an independent, unofficial client. It is not affiliated with TypeSafe AI. Jev returns structured decisions; your agent writes the scripts and controls the workflow. Judgement does not generate or execute model-supplied code.

TypeSafe is the only implemented provider today. The CLI keeps provider calls behind a small internal adapter so another provider can be added without rewriting input handling or batching. A custom base URL supports compatible TypeSafe endpoints; it does not translate other providers' APIs.

Install

Requires Go 1.23 or newer.

go install github.com/Mentioum/judgement/cmd/judgement@latest

Or build a local checkout:

go build -o bin/judgement ./cmd/judgement
./bin/judgement describe

Set TYPESAFE_API_KEY through your environment or secret manager. Get a key from the TypeSafe console. The CLI never prompts for credentials and does not read .env files automatically.

One request, three kinds of decision

Save this as request.json:

{
  "state": "I was charged twice. Please refund the extra payment today.",
  "questions": {
    "refund_requested": {
      "type": "noul",
      "instructions": "Does the customer request a refund?"
    },
    "team": {
      "type": "choice",
      "instructions": "Which team should handle this ticket?",
      "criteria": {
        "billing": "Payments and refunds",
        "support": "Product problems",
        "other": "None of the listed teams fits"
      }
    },
    "urgency": {
      "type": "score",
      "instructions": "How urgent is the request?",
      "criteria": ["No deadline", "This week", "Today"]
    }
  }
}
# Offline: catch malformed requests without credentials or API charges.
judgement validate --input request.json

# Network: retain answers, probabilities, confidence, model, and token usage.
judgement evaluate --input request.json > result.json
jq '.answers.team | {choice, confidence, probabilities}' result.json
Primitive Output Typical use
Noul Probability of yes, between 0 and 1 Verification, filters, conditions
Choice Selected label, probability distribution, confidence Routing, classification, candidate selection
Score Expected numeric score, rubric legend, distribution, confidence Ranking, severity, quality scoring

Instructions and criterion descriptions accept strings, objects, arrays, or null. Scores use an ordered list of at least two levels; the result may fall between level indices. Multiple question types can share a single state. Explicit null state is accepted for compatibility with the current JavaScript SDK; the general HTTP and Python documentation are narrower, so prefer concrete state. Input and question shapes are checked locally; server limits and model quality still require evaluation on your own data.

Built for agents

  • describe returns the command contract, JSON Schema, authentication details, and exit codes in one machine-readable response.
  • schema exposes a standalone JSON Schema for request construction.
  • Success output is JSON; batch output is JSONL. Errors use JSON on stderr.
  • Full responses are preserved, including new fields and large JSON integers.
  • Files and stdin avoid shell quoting for long content and structured rubrics.
  • Bounded concurrent batches preserve order and associate results with IDs.
  • Deadlines include retries. Interrupts cancel in-flight requests and backoff.
  • Authentication is environment-only. Remote error bodies are not echoed.

Read the agent workflow guide for validation, batching, retries, and confidence-based routing. See CLI details for exact contracts.

judgement describe
judgement schema > request.schema.json
judgement models

# Reuse a questions file with plain-text state from a pipeline.
cat ticket.txt | judgement evaluate --state-file - --questions examples/questions.json

# Use a specific model to keep evaluated thresholds reproducible.
judgement evaluate --input request.json --model jev-1.13.0 --timeout 30s

Process a dataset

Each JSONL line is a request, or an envelope with id and request:

{"id":"ticket-42","request":{"state":"Please refund me","questions":{"refund":{"type":"noul","instructions":"Is a refund requested?"}}}}
judgement batch --input examples/batch.jsonl --concurrency 4 > results.jsonl

Each output line contains index, optional id, and either result or error. Individual failures do not stop other records. Exit status is 1 if any record fails. Order matches input, with bounded windows of up to --concurrency records. This command is a client-side convenience; each record is an API call.

Use from Go

client, err := judgement.NewClient(judgement.Config{
    APIKey:     os.Getenv("TYPESAFE_API_KEY"),
    Timeout:    30 * time.Second,
    MaxRetries: 2,
})
if err != nil {
    return err
}
result, err := client.Evaluate(ctx, judgement.Request{
    State: "Please refund the duplicate charge.",
    Questions: map[string]judgement.Question{
        "refund": judgement.Noul("Is a refund requested?"),
        "team": judgement.Choice("Which team should handle this?", map[string]any{
            "billing": "Payments and refunds",
            "support": "Product problems",
        }),
    },
})
if err != nil {
    return err
}
fmt.Println(*result.Answers["refund"].Noul)

The complete Go example includes imports and executable error handling. ListModels discovers model names; EvaluateRaw and ListModelsRaw preserve the entire JSON response. The client is reusable across goroutines; keep request maps unchanged while calls are in progress. Zero MaxRetries disables retries in the library; the CLI defaults to two retries.

Development

go test -race ./...
go vet ./...
go build ./...

Tests use local HTTP servers and need no API credentials. They cover request serialization, structured criteria, retries, cancellation, error redaction, redirect handling, numeric precision, and batch ordering. Live service behavior has not been verified with an API key for this initial release.

CI checks Go 1.23 and the current stable toolchain on Linux, macOS, and Windows. Tagged versions build downloadable binaries with checksums through the release workflow. See contributing, security, and the changelog.

API reference and scope

Implemented against TypeSafe's published documentation, checked September 18, 2026: HTTP API, models, structured rubrics, and SDK types.

Coverage includes the documented evaluation endpoint, model listing, all three question types, structured descriptions, model selection, and complete response data. Jev's current input is text/JSON; this client does not add media input, text generation, fine-tuning, or code execution.

MIT licensed.

Documentation

Overview

Package judgement provides a Go client for TypeSafe AI's System One API.

Index

Constants

View Source
const DefaultBaseURL = "https://api.typesafe.ai/v1"
View Source
const DefaultModel = "jev-latest"

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int    `json:"status"`
	RequestID  string `json:"request_id,omitempty"`
	Retryable  bool   `json:"retryable"`
}

APIError is a sanitized remote failure. Bodies are intentionally not included: providers and proxies may echo credentials or private request data.

func (*APIError) Error

func (e *APIError) Error() string

type Answer

type Answer struct {
	Type          string             `json:"type"`
	Noul          *float64           `json:"noul,omitempty"`
	Choice        *string            `json:"choice,omitempty"`
	Score         *float64           `json:"score,omitempty"`
	Confidence    *float64           `json:"confidence,omitempty"`
	Probabilities map[string]float64 `json:"probabilities,omitempty"`
	Legend        map[string]any     `json:"legend,omitempty"`
}

Answer preserves zero probabilities and scores using pointers. Legend values may be structured JSON when the request uses structured score criteria.

type Client

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

Client is safe for concurrent use. Configuration is immutable after creation.

func NewClient

func NewClient(cfg Config) (*Client, error)

func (*Client) Evaluate

func (c *Client) Evaluate(ctx context.Context, r Request) (*Response, error)

func (*Client) EvaluateRaw

func (c *Client) EvaluateRaw(ctx context.Context, r Request) (json.RawMessage, error)

EvaluateRaw preserves all response fields, including future API additions.

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context) (*ModelsResponse, error)

func (*Client) ListModelsRaw

func (c *Client) ListModelsRaw(ctx context.Context) (json.RawMessage, error)

type Config

type Config struct {
	APIKey     string
	BaseURL    string
	HTTPClient *http.Client
	Timeout    time.Duration
	MaxRetries int
}

Config is copied by NewClient. Timeout covers all attempts and retry delays. MaxRetries counts attempts after the initial request; zero disables retries.

type Model

type Model struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	ReleaseDate string `json:"release_date"`
}

type ModelsResponse

type ModelsResponse struct {
	Models []Model `json:"models"`
}

type Question

type Question struct {
	Type         string `json:"type"`
	Instructions any    `json:"instructions"`
	Criteria     any    `json:"criteria,omitempty"`
}

Question supports Noul, Choice and Score. Instructions and descriptions accept strings, objects, arrays or nil, including the API's structured rubrics.

func Choice

func Choice(instructions any, options map[string]any) Question

func Noul

func Noul(instructions any) Question

func Score

func Score(instructions any, levels []any) Question

type Request

type Request struct {
	State     any                 `json:"state"`
	Model     string              `json:"model"`
	Questions map[string]Question `json:"questions"`
}

func (Request) Validate

func (r Request) Validate() error

Validate checks documented request shapes without restricting nested JSON.

type Response

type Response struct {
	Model   string            `json:"model"`
	Answers map[string]Answer `json:"answers"`
	Usage   Usage             `json:"usage"`
}

type TransportError

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

func (*TransportError) Error

func (e *TransportError) Error() string

func (*TransportError) Unwrap

func (e *TransportError) Unwrap() error

type Usage

type Usage struct {
	InputTokens  int64 `json:"input_tokens"`
	OutputTokens int64 `json:"output_tokens"`
}

Directories

Path Synopsis
cmd
judgement command
examples
go command
internal
cli
Package cli implements the script-oriented judgement command.
Package cli implements the script-oriented judgement command.

Jump to

Keyboard shortcuts

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