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 readresult.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:- Converts the schema to a provider-specific format (e.g.,
json_schemafor OpenAI) - Instructs the LLM to respond in that format
- Parses and validates the response against the schema
- Exposes the result in
RunOutput.structured
Using Zod Schemas
SetstructuredOutput 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
WhenstructuredOutput 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 withstructuredOutput 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.
POST /api/agents/analyst/run will include:
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.