---
title: Output
description: An output schema controls the value a caller receives.
---

An output schema checks a handler's return value and controls which fields reach the caller.

<Diagram caption="The registry parses the handler's return value through output before it returns the result.">
  <Flow>
    <Node title="handler" subtitle="Returns the booking row" />
    <Arrow n={1} />
    <Node title="output" subtitle="Keeps the selected fields" tone="accent" />
    <Arrow n={2} />
    <Node title="Caller" subtitle="Receives the parsed result" />
  </Flow>
</Diagram>

```ts twoslash
import { init } from "logic-sdk";
import { z } from "zod";

const { query } = init<{ scope: { accountId: string } }>();
const anyone = () => true;
const findBooking = async (ctx: { scope: { accountId: string } }, id: string) => ({ id, accountId: ctx.scope.accountId });
// ---cut---
/** Get a booking. */
export const get = query({
  input: z.object({ bookingId: z.uuid() }),
  authorize: anyone,
  output: z.object({ id: z.uuid() }),
  async handler(ctx, { bookingId }) {
    return findBooking(ctx, bookingId);
  },
});
```

- **Return value (1).** The handler returns the full row. The Zod object in this example strips unknown keys, including `accountId`.
- **Parsed result (2).** Callers get the parsed value and type, or the handler's full result if you omit `output`.
- **Public contract.** Set an output schema that keeps only the fields you intend to publish. For a Drizzle table, you can derive it with `createSelectSchema` from `drizzle-orm/zod`.
- **Validation.** Any Standard Schema works. Invalid output throws an unexpected error. In a mutation, that failure rolls back the transaction.

## See also

[Functions](/docs/concepts/functions), [Authorization](/docs/concepts/authorization), [oRPC](/docs/guides/orpc)
