outputSchema to a run. The agent loop runs to completion, coerces the final answer to your schema, and returns a validated object — typed against the schema you defined. The schema is an ArkType assertion built with Assert from @ooneex/validation.
Asking for an object
Define the shape, pass it asoutputSchema, and type the call with the schema’s inferred type:
run returns the assistant’s text as a string. With one, it returns the validated object — the result is coerced and checked before it reaches you, so a malformed answer fails loudly rather than slipping through.
Richer schemas
Anything ArkType expresses works — optional fields, unions, arrays, and constraints:With tools
Structured output and tools combine: the agent can call tools across the loop to gather what it needs, then shape the final answer into your schema. The object you get back reflects everything the agent learned during the run.Middleware can transform the structured-output call before it is sent — including the JSON Schema handed to the provider — through the
onStructuredOutputConfig hook. See Middleware.