Structured Output
The built-in generate_object tool asks the configured LLM for a JSON value,
validates the response against a JSON Schema you supply, and returns the
validated value only on a zero-exit result. Use it whenever you need
machine-readable results: extraction, classification, config generation, or
feeding another program.
You can call it directly through session.tool('generate_object', ...). The
tool result carries the validated object as JSON on result.output — parse it
and read the object field. The same tool also supports agent-driven
invocation, where the model decides to call it during a send.
Direct tool call
The simplest path: call generate_object directly, check the tool exit code,
and parse the validated object out of the result.
The validated value lives on the object key of the parsed output. When
result.exitCode (Node) / result.exit_code (Python) is zero, fields declared
in required have passed runtime validation. If the model cannot satisfy the
schema after repair attempts, the tool reports a non-zero exit code.
Enum classification
Constrain a field to a fixed set with enum. This turns a free-form model
classification into a schema-gated result.
Nested schemas and arrays
Schemas can nest objects and arrays within the runtime's bounded schema-depth limit, and the runtime validates the whole structure. This models real config files, manifests, or API payloads in one call.
Agent-driven invocation
You can also let the agent decide when to use structured output. Ask it to call generate_object during a send; it gathers context first, then emits the object.
Schema validation coverage
The built-in validator supports:
type(including nullable arrays like["string", "null"])required,properties,additionalPropertiesenum,const$refwith local$defsordefinitionsallOf,anyOf,oneOfminLength,maxLength,patternminimum,maximum,exclusiveMinimum,exclusiveMaximumminItems,maxItems,items- Nested object and array validation, including root arrays and scalar values
Notes
- The validated value is on the
objectkey of the parsedresult.output.autoselects forced-tool mode when the provider declares that capability and otherwise uses the prompt+schema fallback. Explicitstrictandjsonmodes use provider-native response formats only when supported, then safely fall back to forced-tool or prompt mode. - List every field you depend on in
required— the runtime enforces it, so missing or mistyped fields fail validation instead of silently returning partial data. generate_objectis a built-in tool registered independently of built-in skills.- Direct
session.tool(...)calls are host control-plane calls. UsepermissionPolicywhen you let the model choose tools insidesend/run/stream; use host authorization before direct SDK calls.
A runnable version ships at sdk/node/examples/basic/test_generate_object.ts and sdk/python/examples/test_generate_object.py.