Cortex · Failed runs

stopped: output retries

A run fails with code stopped and stop set to output_retries when its output keeps failing validation against the output schema. Each invalid output is sent back to the model with the validation issues; the third failure ends the run, and the error’s lastOutput holds the last output the model produced. The model’s three turns are scripted, all the same; 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.',
  output: { schema: Order },
});

const result = await clerk.run('Two seats for Sunday, please.', { llm }).result;
Scripted model turns
1  writes {"data":{"night":"2026-10-25","seats":"two"}}
2  writes {"data":{"night":"2026-10-25","seats":"two"}}
3  writes {"data":{"night":"2026-10-25","seats":"two"}}
Output
{
  retries: [
    'output 1: data.seats: Invalid input: expected number, received string',
    'output 2: data.seats: Invalid input: expected number, received string',
    'output 3: data.seats: Invalid input: expected number, received string',
  ],
  result: {
    ok: false,
    error: {
      code: 'stopped',
      stop: 'output_retries',
      message: 'output retries exhausted (3)',
      lastOutput: { data: { night: '2026-10-25', seats: 'two' } },
    },
  },
}
Output matches the expected value

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