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
- func ConfigField(name, label, description string) configuration.Field
- func ExtractJSON(text string) (any, bool)
- func Parse(raw any) (map[string]any, error)
- func Prepare(schema map[string]any, strict bool) map[string]any
- func PromptSuffix(schema map[string]any) string
- func ValidateAtSetup(raw string) error
Constants ¶
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
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 ¶
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 ¶
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
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
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.