Documentation / guides
OutputSchema
Define the name, description, JSON schema, and strictness of a result contract.
OutputSchema is the provider-neutral request for one schema-constrained JSON object.
API surface
const (
StructuredOutputToolName = "_looprig_final_output"
StructuredOutputRevision = "structured-output/v1"
)
type OutputSchema struct {
Name string
Description string
Schema json.RawMessage
Strict bool
}
func (o OutputSchema) Clone() OutputSchema
func ValidateOutputSchema(output OutputSchema) error
| Field | Constraint |
|---|---|
Name | ASCII identifier, 1 to 64 bytes, not the reserved tool name |
Description | Valid UTF-8, at most 4096 bytes |
Schema | Valid UTF-8 JSON object in the portable subset, at most 1 MiB |
Strict | Provider-neutral strictness request passed to supporting codecs |
output := inference.OutputSchema{
Name: "answer",
Description: "A concise answer with a confidence score.",
Schema: json.RawMessage(`{
"type":"object",
"properties":{
"answer":{"type":"string"},
"confidence":{"type":"number"}
},
"required":["answer","confidence"],
"additionalProperties":false
}`),
Strict: true,
}
if err := inference.ValidateOutputSchema(output); err != nil {
panic(err)
}
Clone copies Schema into independent storage, preserving nil versus non-nil empty raw messages. The reserved name is used internally when a provider represents structured output as a terminal tool call and cannot collide with an ordinary tool.
Proof
- Source:
inference/output.go - Tests:
inference/output_test.gocovers clone non-aliasing, metadata bounds, and portable schema acceptance.
Related: Portable JSON Schema, Structured output requests.