Documentation
¶
Overview ¶
Package schema derives JSON Schema from Go types and emits provider-specific dialects. Reflection-based frameworks all trip on the same wall: the schema reflection emits ($ref/$defs, missing additionalProperties) gets rejected by OpenAI strict mode and Gemini, so everyone reinvents a sanitizer. We emit INLINE (no $ref/$defs — recursion-safe) and provide dialect transforms so the tool author never hand-edits JSON Schema.
Tools expose the neutral schema (For); each model adapter dialectizes it at request time (Anthropic accepts the neutral form; OpenAI needs OpenAIStrict).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func For ¶
func For[T any]() (json.RawMessage, error)
For derives an inline JSON Schema from Go type T's exported fields. Nested structs are inlined (no $ref/$defs). Field names + optionality come from the `json` tag (a field is required unless it is a pointer or its json tag has ",omitempty"); descriptions come from the `desc` tag.
It mirrors encoding/json's actual marshaling: embedded structs are flattened (promoted) into the parent; []byte is a base64 string but a byte array is a JSON number array; time.Time is a date-time string; json.RawMessage and interface{} are unconstrained. A type with a custom marshaler is not reflected field-by-field (reflection can't see the custom shape): encoding.TextMarshaler → string, any other json.Marshaler → unconstrained. Deeply-nested embedding-conflict resolution is not fully modeled (the common shallow-shadows-deep case is).
func OpenAIStrict ¶
func OpenAIStrict(neutral json.RawMessage) (json.RawMessage, error)
OpenAIStrict transforms a neutral schema into OpenAI structured-output "strict" form: additionalProperties:false on every object and every property listed in required (OpenAI strict rejects schemas that omit either). Operates on the inline schema.
Types ¶
This section is empty.