Skip to main content
Examples using security: { mode: "local" } are for trusted local use. Hosted deployments require verified identity and resource authorization.

In plain terms

Ask for a form, not an essay. You pass a Zod schema. The model fills it in. You read result.structured as typed data.

What is Structured Output?

With structured output, you define a Zod schema that describes the expected shape of the response. Agentium:
  1. Converts the schema to a provider-specific format (e.g., json_schema for OpenAI)
  2. Instructs the LLM to respond in that format
  3. Parses and validates the response against the schema
  4. Exposes the result in RunOutput.structured

Using Zod Schemas

Set structuredOutput in AgentConfig:

How It Works

1

Schema

Define a Zod schema (object, array, nested, etc.).
2

responseFormat

Agentium converts the schema to the provider’s responseFormat (e.g., { type: "json_schema", schema: {...} }).
3

LLM

The model is instructed to return valid JSON matching the schema.
4

Parse & Validate

The raw response is parsed and validated with schema.safeParse(). Invalid output may throw or be handled by the provider.

RunOutput.structured

When structuredOutput is set, the parsed and validated result is available on RunOutput.structured:

Example: Sentiment Analysis Agent


Example: City Info with Rich Schema


Structured Output in Express / Swagger

When you expose an agent with structuredOutput via Express, Agentium automatically generates a typed response schema in the OpenAPI spec. Swagger UI will display the exact shape of the structured field — consumers of your API see the full contract without extra documentation.
The generated OpenAPI spec for POST /api/agents/analyst/run will include:
Agents without structuredOutput use the generic RunOutput schema where structured is untyped.

Provider Support

Agentium abstracts provider differences. Use a Zod schema and the framework handles the rest.
On Jev, agent.run(input, { questions }) wins over structuredOutput. Skip per-run questions if you want result.structured to parse as the Zod object.