Cortex · Output

Text and structured output

An output envelope can hold response and data together, from a single model turn. The example returns a sentence for the member in response and an order for the app in data. The model’s one turn is scripted; no model is called.

Agent
const Order = z.object({ night: z.string(), seats: z.number().int() });

const clerk = defineAgent({
  id: 'clerk',
  instructions: 'Read what the member wants into an order, and say it back.',
  output: { schema: Order },
});

const result = await clerk.run('Two seats for Sunday, please.', { llm }).result;
Scripted model turns
1  writes {"response":"Two seats for Sunday. Shall I book them?","data":{"night":"2026-10-25","seats":2}}
Result
{
  ok: true,
  output: {
    response: 'Two seats for Sunday. Shall I book them?',
    data: { night: '2026-10-25', seats: 2 },
  },
}
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.