import { TraceloopError } from "../errors"; /** * Core Guard type — any async function that takes a dict input and returns a boolean * or a GuardCallResult (pre-built guards return the raw API response alongside the bool). * * TInput declares the shape of the input dict this guard expects. * Defaults to Record (untyped) for simple guards and custom guards. * Complex pre-built guards (e.g. semanticSimilarityGuard) use a specific TInput so * TypeScript can enforce that a matching inputMapper is provided at the call site. */ export type Guard = Record> = ((input: TInput) => Promise) & { guardName?: string; }; /** * Maps the LLM function output to one guard input per guard. * Can return a list (index-matched to guards) or a dict (keyed by guard name). * * TOutput — the type of the LLM output being mapped (defaults to string | object). * TInput — the shape each guard expects as input (defaults to Record). */ export type InputMapper = string | Record, TInput extends Record = Record> = (output: TOutput, numGuards: number) => TInput[] | Record; /** Input required by semanticSimilarityGuard. */ export type SemanticSimilarityInput = { text: string; reference: string; }; /** Input required by instructionAdherenceGuard. */ export type InstructionAdherenceInput = { instructions: string; response: string; }; /** Input required by uncertaintyGuard. */ export type UncertaintyInput = { prompt: string; completion: string; }; /** * Passed to on_failure handlers when a guard fails. */ export interface GuardedResult { result: string | Record; guardInputs: Record[]; } /** * The result of a single guard's execution. */ export interface GuardResult { name: string; passed: boolean; duration: number; /** Raw API response fields, e.g. { similarity_score: 0.12 } or { is_safe: false }. */ output?: Record; } /** * Internal return type for pre-built guards that want to carry the raw API * response alongside the pass/fail boolean. Custom user guards still return * plain `boolean` — _runSingleGuard accepts both via a union check. */ export interface GuardCallResult { passed: boolean; output: Record; } export declare class FailFastGuardResult { readonly index: number; readonly name: string; readonly passed: false; readonly duration: number; readonly output?: Record | undefined; constructor(index: number, name: string, passed: false, duration: number, output?: Record | undefined); } export declare class GuardrailError extends TraceloopError { constructor(message: string); } export declare class GuardValidationError extends GuardrailError { output: GuardedResult; constructor(output: GuardedResult, message?: string); } export declare class GuardExecutionError extends GuardrailError { originalException: Error; guardInput: Record; guardIndex: number; constructor(originalException: Error, guardInput: Record, guardIndex: number); } export declare class GuardInputTypeError extends GuardrailError { guardIndex: number; expectedType: string; actualType: string; constructor(guardIndex: number, expectedType: string, actualType: string); } //# sourceMappingURL=model.d.ts.map