Skip to main content

Variable: Output

const Output: object

Defined in: packages/core/src/utils/output.ts:43

The shapes a bot's output can take.

Type Declaration​

array()​

array<T>(__namedParameters): OutputConfig<T[]>

An array of items. schema describes one item.

Type Parameters​

T​

T

Parameters​

__namedParameters​
schema​

ZodType<T>

Returns​

OutputConfig<T[]>

Example​

import { Output } from '@baleybots/core';
import { z } from 'zod';

const itemSchema = z.object({
title: z.string(),
url: z.url(),
});

const bot = new Baleybot({
name: 'link-extractor',
goal: 'Extract links from text',
output: Output.array({ schema: itemSchema }),
});

const result = await bot.process('...');
// result is typed as { title: string, url: string }[]

choice()​

choice<T>(choices): OutputConfig<T>

One of a fixed set of strings.

Type Parameters​

T​

T extends string

Parameters​

choices​

readonly T[]

Returns​

OutputConfig<T>

Example​

import { Output } from '@baleybots/core';

const bot = new Baleybot({
name: 'classifier',
goal: 'Classify the sentiment',
output: Output.choice(['positive', 'negative', 'neutral']),
});

const result = await bot.process('I love this!');
// result is typed as 'positive' | 'negative' | 'neutral'

json()​

json(options?): OutputConfig<unknown>

Any JSON value, with no schema: AI SDK Output.json(), the provider's JSON mode (an OpenAI-compatible response_format: json_object). The bot answers with the parsed value.

Parameters​

options?​

JsonOutputOptions = {}

Returns​

OutputConfig<unknown>

Example​

const bot = new Baleybot({ name: 'tagger', goal: 'Tag the text as JSON', output: Output.json() });

jsonSchema()​

jsonSchema<T, I>(__namedParameters): OutputConfig<I extends "text" ? string | T : T>

Define an object output by JSON Schema, for a schema that arrives as data (an OpenAI-compatible response_format, a stored definition).

It wraps AI SDK jsonSchema() and is never converted to Zod: the schema reaches the provider as given. validate checks a value and throws to reject it (AI SDK's structured output receives what it returns); without it the value is trusted as the provider's structured output returned it. With onInvalid: 'text' a reply that does not parse or validate is the answer as text, and the value type widens to T | string.

Type Parameters​

T​

T = unknown

I​

I extends "text" | "fail" = "fail"

Parameters​

__namedParameters​

JsonOutputOptions & object

Returns​

OutputConfig<I extends "text" ? string | T : T>

Example​

const bot = new Baleybot({
name: 'extractor',
goal: 'Extract the invoice',
output: Output.jsonSchema<{ total: number }>({
name: 'invoice',
schema: { type: 'object', properties: { total: { type: 'number' } }, required: ['total'] },
}),
});

object()​

object<T>(__namedParameters): OutputConfig<T>

A structured object.

Type Parameters​

T​

T

Parameters​

__namedParameters​
schema​

ZodType<T>

Returns​

OutputConfig<T>

Example​

import { Output } from '@baleybots/core';
import { z } from 'zod';

const bot = new Baleybot({
name: 'summarizer',
goal: 'Summarize text',
output: Output.object({
schema: z.object({
summary: z.string(),
keyPoints: z.array(z.string()),
wordCount: z.number(),
}),
}),
});

const result = await bot.process('...');
// result is typed as { summary: string, keyPoints: string[], wordCount: number }

value()​

value<T>(__namedParameters): OutputConfig<T>

Define one schema-shaped value, including a primitive root.

AI SDK structured-output providers generally require an object at the wire boundary. value() keeps that workaround internal: the adapter sends { value: <schema> }, then Baleybot unwraps it before validating and returning the caller's declared value.

Type Parameters​

T​

T

Parameters​

__namedParameters​
schema​

ZodType<T>

Returns​

OutputConfig<T>