Skip to content
Français

defineJsonResponse

import { defineJsonResponse } from "@elie-laloum/outpost/core";

Declare a JSON response with automatic tagged final-answer instructions and an input JSON Schema. Converts Standard JSON Schema input automatically unless jsonSchema is explicit; missing, failed or non-lossless schemas fail with code configuration. Reads the last complete tag, accepts JSON code fences and validates with schema; rejected content fails with ResponseError. Exact injected text and customization limits.

Complete example and detailed rules.

The fields below cover all variants; the signature specifies their allowed combinations.

  • optionsRequired
    JsonResponseOptions<T>
    Tag, validator, input JSON Schema when automatic conversion is unavailable, and allowed repair turns.
  • options.tagRequired
    string
    Tag name without angle brackets: a letter followed by letters, digits, _ or -. Another form fails with code configuration.
  • options.repairsOptional
    number | undefined
    Correction turns allowed after an invalid answer, default 0; must be a nonnegative integer. Above 0, the agent must be able to resume its conversation. Exact injected text and customization limits.
  • options.schemaRequired
    StandardJsonSchema<T> | StandardValidator<T> | ((input: unknown) => T | Promise<T>)
    Standard Schema validator or a function receiving parsed JSON as unknown and returning the typed value, possibly transformed. Issues or thrown errors reject the answer. Automatic input-schema conversion requires Standard JSON Schema; otherwise jsonSchema is required.
  • options.jsonSchemaVariant-dependent
    Readonly<Record<string, unknown>> | undefined | Readonly<Record<string, unknown>>
    Explicit input JSON Schema object included in automatic final-answer instructions. Required unless schema supports Standard JSON Schema conversion; takes precedence over conversion. Captured as a deeply frozen lossless JSON copy, excluding non-enumerable ~standard protocol metadata; schema remains the validator. No remote references are fetched.

ResponseSpec<T>

export declare function defineJsonResponse<T>(
  options: JsonResponseOptions<T>,
): ResponseSpec<T>;