jsonformat

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package jsonformat provides JSON schema-based response formatting and validation for structured agent output, deriving schemas from Go types and validating and normalizing values against them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any() agent.ResponseFormat

Any returns a ResponseFormat representing the any type (no schema constraints).

func For

func For[T any]() (agent.ResponseFormat, error)

For creates a ResponseFormat for the type T.

func ForType

func ForType(rt reflect.Type) (agent.ResponseFormat, error)

ForType creates a ResponseFormat for the given reflect.Type. A nil rt is treated as Nothing.

func MustFor

func MustFor[T any]() agent.ResponseFormat

MustFor calls For and panics on error.

func New

func New(name, description string, schema *jsonschema.Schema) agent.ResponseFormat

New creates a new JSON response format with the given name, description, and schema. A nil schema represents an unconstrained JSON value.

func Nothing

func Nothing() agent.ResponseFormat

Nothing returns a ResponseFormat that matches no values.

Types

type Format

type Format struct {
	agent.ResponseFormat
	// contains filtered or unexported fields
}

Format provides JSON schema-based response formatting and validation.

func FromResponseFormat

func FromResponseFormat(format agent.ResponseFormat) (*Format, error)

FromResponseFormat creates a Format from a response format data value.

func (*Format) Marshal

func (f *Format) Marshal(v any) ([]byte, error)

Marshal marshals v into JSON according to the provided format, validating against the format's schema.

func (*Format) Normalize

func (f *Format) Normalize(v any) error

Normalize applies schema defaults to v and validates it against the format's schema.

v must be a non-nil pointer to the value being normalized.

func (*Format) Unmarshal

func (f *Format) Unmarshal(data []byte, v any) error

Unmarshal unmarshals data into v according to the provided format, validating against the format's schema.

Jump to

Keyboard shortcuts

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