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

# Devin SDK structured output and launchSession

> Use launchSession in the Devin SDK to create and run a session in one call, and pass a schema to get a validated, typed result back.

## Launch a session

`launchSession` combines `createSession` and `run` on both cloud and local clients:

```ts theme={null}
const { session, turn } = await devin.launchSession("Fix the flaky test");
const result = await turn; // Or stream events with: for await (const event of turn)
```

`session` takes the client's creation options; `turn` takes the existing `run` options,
including typed `output`. Launch waits for prompt acceptance, not work completion. On ACP v1,
acceptance uses the matching user-message echo, falling back to the completion response if the
agent doesn't echo.

Keep the client alive while using the turn; local work is not detached from the CLI. Cancel
explicitly with `session.cancel()`. Startup failures after allocation throw
`SessionStartupError` with `sessionId` and `cause`; inspect that session before retrying. Later
execution failures reject `turn`.

## Structured output

Pass a [Zod](https://zod.dev) (or any [Standard Schema](https://standardschema.dev)) schema as
`output` and the turn resolves to a validated, typed value. A completed reply that doesn't match
the schema rejects the turn instead of returning bad data. A turn that stops without finishing —
cancelled, refused, or out of tokens — resolves with that `stopReason` (since `0.0.1-beta.2`;
earlier betas rejected with "The turn produced no JSON to validate"): `stopReason`, `text` and
`events` are readable, and reading `outcome.output` throws, so code that needs the value still
fails loudly.

> [!NOTE]
>
> Zod is an optional dependency: `npm install zod`.

```ts theme={null}
import { z } from "zod";

const outcome = await session.run("Outline a 3-section blog post about TypeScript unions", {
  output: z.object({ title: z.string(), sections: z.array(z.string()).length(3) }),
});
outcome.output.sections; // string[]
```

Typed output works on both clients without server-side session settings, and through
`launchSession`:

```ts theme={null}
import { z } from "zod";

const { turn } = await devin.launchSession("What is 6 times 7?", {
  turn: { output: z.object({ answer: z.number() }) },
});
const { output } = await turn; // { answer: number }
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.