Structured Output
The built-in generate_object tool asks the configured LLM for a JSON object,
validates the response against a JSON Schema you supply, and returns the
validated object 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 to any depth, 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,constanyOf,oneOfminLength,maxLength,patternminimum,maximum,exclusiveMinimum,exclusiveMaximumminItems,maxItems,items- Nested object and array validation
Notes
- The validated value is on the
objectkey of the parsedresult.output. Passmode: 'tool'for the current cross-provider default, ormode: 'prompt'for a prompt-only fallback.auto,strict, andjsoncurrently resolve totoolin this runtime path. - 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 crates/code/sdk/node/examples/basic/test_generate_object.ts and crates/code/sdk/python/examples/test_generate_object.py.