/** * Structured output validation and repair. * * Ported from PSYCHE src/llm/structured_output.py. Implements a 3-tier * fallback pipeline: * Tier 1: validateStructuredOutput — direct schema parse * Tier 2: jsonrepair → JSON.parse → schema.parse * Tier 3: policy-driven: 'repair_then_empty' | 'raise' | 'repair_then_raise' * * The PromptRepresentation special-case from PSYCHE is replaced by the * generic `repairHook?` option for any pre-validation transforms. * * @task T1396 (T1386-W10) * @epic T1386 */ import type { z } from 'zod'; import type { CompletionResult } from './backend.js'; /** Policy for handling structured output failures after repair attempt. */ export type StructuredOutputFailurePolicy = 'raise' | 'repair_then_raise' | 'repair_then_empty'; /** Error thrown when structured output cannot be validated or repaired. */ export declare class StructuredOutputError extends Error { constructor(message: string); } /** * Validate that content conforms to the response schema. * * Accepts: Zod-parsed instance, raw string (JSON), or plain object. */ export declare function validateStructuredOutput(content: unknown, schema: z.ZodType): T; /** * Repair malformed / truncated JSON and validate against the schema. * * Optional `repairHook` allows callers to pre-process the repaired data * before schema validation (replaces PSYCHE's PromptRepresentation special-case). */ export declare function repairResponseModelJson(rawContent: string, schema: z.ZodType, _modelName: string, repairHook?: (data: unknown) => unknown): T; /** * Attempt structured output repair. Returns null if repair fails. */ export declare function attemptStructuredOutputRepair(content: unknown, schema: z.ZodType, modelName: string, repairHook?: (data: unknown) => unknown): T | null; /** * Produce an empty structured output for the schema (schema.parse({})). */ export declare function emptyStructuredOutput(schema: z.ZodType): T; /** * Execute a structured output call with 3-tier fallback. * * Tier 1: validate directly * Tier 2: repair via jsonrepair * Tier 3: policy-driven empty/raise */ export declare function executeStructuredOutputCall(executor: () => Promise, params: { schema: z.ZodType; modelName: string; failurePolicy?: StructuredOutputFailurePolicy; repairHook?: (data: unknown) => unknown; }): Promise; //# sourceMappingURL=structured-output.d.ts.map