Skip to content

askStructured

askStructured<T>(schema, opts): Promise<AskStructuredResult<T>>

Defined in: _worktrees/docs-release/gaunt-sloth/packages/core/src/runtime/askStructured.ts:181

Ask the configured model for a single schema-validated object — a non-agentic structured-output call that mirrors their mechanism (see the module doc) and never throws.

  • No usable model (config.llm missing or lacking withStructuredOutput) → { ok: false, error: 'No usable model configured.' }.
  • Timeout → ok: false with the error structuredCallTimedOutError builds for that budget.
  • Output that fails schema.safeParse{ ok: false, error: {@link STRUCTURED_CALL_UNPARSEABLE_ERROR} }.
  • Any thrown error → { ok: false, error: <message> } — a provider rejection (e.g. OpenAI’s 400 on a strict json_schema), an auth or transport failure. Distinct from the two above BY CODE PATH, so a caller can classify a failure by comparing against those two exported texts.
  • Success → { ok: true, value } with the parsed data.

T

ZodType<T>

The Zod schema the model output must satisfy; <T> is inferred from it.

AskStructuredOptions

The model (via config.llm), the system/user message texts, and an optional timeout.

Promise<AskStructuredResult<T>>