structuredoutput

package
v1.125.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package structuredoutput implements the internal tool behind tool-mode structured output (structured_output.mode: tool). Instead of asking the provider for native structured output, the runtime exposes a single tool whose Parameters are exactly the configured JSON schema; the model delivers its final answer by calling it, and the runtime validates the arguments against the same schema before accepting the result.

Index

Constants

View Source
const ToolName = "__structured_output__"

ToolName is the reserved name of the internal structured-output tool. The dunder form is provider-compatible ([a-zA-Z0-9_-]) and unlikely to collide with real tools; the runtime fails loudly when a real tool claims it rather than masking either one.

Variables

This section is empty.

Functions

This section is empty.

Types

type OutputTool

type OutputTool struct {
	// contains filtered or unexported fields
}

OutputTool bundles the structured-output configuration with its compiled JSON schema so validation and the tool definition stay in sync.

func New

New compiles cfg.Schema and returns the ready-to-expose tool. It fails when the configured schema is not a valid JSON Schema or references anything outside the document, so callers can surface the problem at load time instead of on the first model turn.

func (*OutputTool) Definition

func (t *OutputTool) Definition() tools.Tool

Definition returns the tool definition offered to the model. Parameters are exactly the configured JSON schema.

func (*OutputTool) Validate

func (t *OutputTool) Validate(rawJSON string) (string, error)

Validate checks rawJSON against the configured schema and returns its compacted, canonical form. The returned error is model-facing: it details what failed so the model can correct itself on the next attempt.

Jump to

Keyboard shortcuts

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