> ## Documentation Index
> Fetch the complete documentation index at: https://phaseo.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Outputs and retries

> Validate final outputs, retry transient model failures, and apply managed routing defaults.

Use output parsing when the rest of your application needs a typed value instead of free-form text. Add bounded retries for transient model failures, while leaving validation and policy failures visible to your application.

## Parse a typed output

`parseOutput` converts the final text after the agent loop completes:

```typescript theme={null}
const agent = createAgent<string, { summary: string }>({
  id: "summary-agent",
  parseOutput(text) {
    return JSON.parse(text) as { summary: string };
  },
});
```

For stricter model behaviour, combine parsing with a structured response from the gateway client:

```typescript theme={null}
const client = createGatewayAgentClient({
  clientOptions: {
    apiKey: process.env.PHASEO_API_KEY!,
  },
  responseFormat: {
    type: "json_schema",
    name: "agent_answer",
    schema: {
      type: "object",
      properties: {
        summary: { type: "string" },
      },
      required: ["summary"],
      additionalProperties: false,
    },
  },
  plugins: [{ id: "response-healing" }],
});
```

## Retry model requests

Use `modelRetry` when a transient model failure should be retried inside the current run:

```typescript theme={null}
const agent = createAgent({
  id: "support-agent",
  modelRetry: {
    maxRetries: 2,
    backoffMs: 250,
  },
});
```

`maxRetries` counts attempts after the first request. The final attempt count is stored on the step as `modelAttempts`.

## Use managed routing defaults

Use `preset` when routing, prompt, or parameter defaults should remain in the dashboard:

```typescript theme={null}
const agent = createAgent({
  id: "support-triage-agent",
  preset: "support-triage",
});
```

The gateway adapter can also carry `responseFormat`, `plugins`, `gatewayTools`, `toolChoice`, `webSearchOptions`, `providerOptions`, `promptCacheKey`, and `includeMeta`.

## Related guides

* [Change later model turns](./agent-sdk-dynamic-turns)
* [Stop an agent safely](./agent-sdk-stop-conditions)
* [Handle errors](./agent-sdk-events-and-errors)
