Documentation
¶
Overview ¶
Package schema provides JSON schema generation utilities for AI agent tool definitions.
Use NewGenerator or the package-level Reflect and ReflectType helpers to derive JSON schemas from Go types. The generator is pre-configured with defaults suitable for tool input schemas.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Reflect ¶
func Reflect(v any) *jsonschema.Schema
Reflect derives the JSON schema for the provided value using a default generator.
func ReflectType ¶
func ReflectType[T any]() *jsonschema.Schema
ReflectType allocates a zero value of T and reflects it to a schema.
Example ¶
ExampleReflectType demonstrates generating a JSON schema from a Go type.
package main
import (
"encoding/json"
"fmt"
"chainguard.dev/driftlessaf/agents/schema"
)
func main() {
type Input struct {
Path string `json:"path" jsonschema:"required,description=File path to read"`
Offset int `json:"offset,omitempty" jsonschema:"description=Byte offset"`
}
s := schema.ReflectType[Input]()
data, err := json.Marshal(s)
if err != nil {
panic(err)
}
var m map[string]any
if err := json.Unmarshal(data, &m); err != nil {
panic(err)
}
fmt.Println("type:", m["type"])
}
Output: type: object
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator wraps jsonschema.Reflector with project defaults.
func NewGenerator ¶
func NewGenerator() *Generator
NewGenerator constructs a generator wired with the defaults we need for tool schemas.
Example ¶
ExampleNewGenerator demonstrates creating a generator and reflecting a value.
package main
import (
"encoding/json"
"fmt"
"chainguard.dev/driftlessaf/agents/schema"
)
func main() {
type Params struct {
Query string `json:"query" jsonschema:"required"`
}
g := schema.NewGenerator()
s := g.Reflect(&Params{})
data, _ := json.Marshal(s)
var m map[string]any
_ = json.Unmarshal(data, &m)
fmt.Println("type:", m["type"])
}
Output: type: object
Directories
¶
| Path | Synopsis |
|---|---|
|
Package schematest provides test helpers for comparing JSON schemas.
|
Package schematest provides test helpers for comparing JSON schemas. |