structured

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package structured provides utilities for generating JSON Schema from Go structs and parsing model responses into typed values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseResponse

func ParseResponse(resp *types.ModelResponse, target interface{}) error

ParseResponse unmarshals a ModelResponse.Content into the target struct. The target must be a non-nil pointer.

Types

type OutputSchema

type OutputSchema struct {
	Name        string                 // Name of the schema (derived from struct name)
	Description string                 // Optional description
	Schema      map[string]interface{} // JSON Schema as map
}

OutputSchema describes a JSON Schema derived from a Go struct.

func SchemaFromType

func SchemaFromType(v interface{}) (*OutputSchema, error)

SchemaFromType generates a JSON Schema from a Go struct using reflection. The value must be a struct or pointer to struct. Self-referencing types are detected and produce a generic object schema to avoid infinite recursion.

func (*OutputSchema) ToResponseFormat

func (s *OutputSchema) ToResponseFormat() *models.ResponseFormat

ToResponseFormat converts an OutputSchema to a models.ResponseFormat. The resulting JSONSchema map includes "name" and "description" metadata alongside the schema properties, ready for provider consumption.

Jump to

Keyboard shortcuts

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