Skip to documentation
Documentation navigation

Documentation navigation

Documentation / guides

OutputSchema

Define the name, description, JSON schema, and strictness of a result contract.

developer

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
FieldConstraint
NameASCII identifier, 1 to 64 bytes, not the reserved tool name
DescriptionValid UTF-8, at most 4096 bytes
SchemaValid UTF-8 JSON object in the portable subset, at most 1 MiB
StrictProvider-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

Related: Portable JSON Schema, Structured output requests.

← back to documentation