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 ¶
- func Any() agent.ResponseFormat
- func For[T any]() (agent.ResponseFormat, error)
- func ForType(rt reflect.Type) (agent.ResponseFormat, error)
- func MustFor[T any]() agent.ResponseFormat
- func New(name, description string, schema *jsonschema.Schema) agent.ResponseFormat
- func Nothing() agent.ResponseFormat
- func WrapNonObjectSchema(format agent.ResponseFormat) (agent.ResponseFormat, error)
- type Format
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 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.
func WrapNonObjectSchema ¶ added in v0.1.1
func WrapNonObjectSchema(format agent.ResponseFormat) (agent.ResponseFormat, error)
WrapNonObjectSchema returns a response format with an object-root schema. A non-object JSON schema is copied into a required "data" property. The supplied format and its schema are not modified; ForType still describes the unwrapped value for local validation.
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 ¶
Marshal marshals v into JSON according to the provided format, validating against the format's schema.
func (*Format) Normalize ¶
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 ¶
Unmarshal unmarshals data into v according to the provided format, validating against the format's schema.
func (*Format) UnmarshalStructuredOutput ¶ added in v0.1.1
UnmarshalStructuredOutput validates and decodes a response formatted by WrapNonObjectSchema. It unwraps non-object results from "data", while accepting valid bare JSON as a fallback. Extra envelope properties are ignored. Object results use the first top-level JSON value; wrapped results require a single top-level value. Format.Unmarshal uses its schema as supplied.