structuredoutput

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package structuredoutput lets LLM components accept a JSON Schema describing the desired response, validating it and normalizing it to the constraints strict-mode providers enforce (every object gets "additionalProperties": false; strict mode also requires listing every property in "required").

Some agent-style components have no server-side schema enforcement at all. For those, PromptSuffix and ExtractJSON emulate it by asking the model to comply and best-effort parsing its final message.

Index

Constants

View Source
const DefaultSchema = `` /* 264-byte string literal not displayed */

DefaultSchema is the starter JSON Schema shown in the field for the user to edit.

Variables

This section is empty.

Functions

func ConfigField

func ConfigField(name, label, description string) configuration.Field

ConfigField returns the togglable JSON-schema text field for a component.

func ExtractJSON added in v0.30.0

func ExtractJSON(text string) (any, bool)

ExtractJSON pulls a JSON object out of text produced by PromptSuffix's instructions: it tries each fenced code block (last to first), then the whole trimmed text, and reports false if none parse as a JSON object. This is best-effort with no schema validation — callers decide when to trust it.

func Parse

func Parse(raw any) (map[string]any, error)

Parse reads the raw config value (a JSON Schema string) into a schema object. It returns (nil, nil) when the field is unset, so callers can treat structured output as optional. Otherwise it validates that the value is a JSON object that looks like an object schema, so malformed input surfaces at config/Setup time rather than as a provider error.

func Prepare

func Prepare(schema map[string]any, strict bool) map[string]any

Prepare returns a copy of the schema normalized to provider constraints, ready to send. It does not mutate the input.

func PromptSuffix added in v0.30.0

func PromptSuffix(schema map[string]any) string

PromptSuffix renders schema-following instructions to append to an agent's task prompt, for components with no server-side schema enforcement to rely on instead. Returns "" if schema is nil.

func ValidateAtSetup added in v0.30.0

func ValidateAtSetup(raw string) error

ValidateAtSetup validates a raw structured-output config value at Setup time. An empty value is fine (structured output is optional). A value that still contains an unresolved "{{" expression is skipped, mirroring how the prompt field itself is only resolved at Execute.

Types

This section is empty.

Jump to

Keyboard shortcuts

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