/** * G — Guards (output validation) namespace. * * Guards validate/transform the LLM response (after_model). * Compose with .pipe() to chain multiple guards. * * Usage: * agent.guard(G.length({ max: 500 })) * agent.guard(G.json().pipe(G.schema(myZodSchema))) * agent.guard(G.pii({ action: "redact" })) */ import type { CallbackFn, State } from "../core/types.js"; /** Descriptor for a single guard in the composite. */ export interface GuardSpec { name: string; check: CallbackFn; config?: Record; } /** A composable guard descriptor. */ export declare class GComposite { readonly guards: GuardSpec[]; constructor(guards: GuardSpec[]); /** Chain: add another guard. */ pipe(other: GComposite): GComposite; /** Convert to a flat guard array for passing to builder. */ toArray(): GuardSpec[]; } /** Error thrown when a guard check fails. */ export declare class GuardViolation extends Error { readonly guardName: string; readonly phase: string; constructor(guardName: string, phase: string, message: string); } /** PII detector interface. */ export interface PIIDetector { detect: (text: string) => Promise | string[]; } /** Content judge interface. */ export interface ContentJudge { judge: (text: string) => Promise<{ pass: boolean; reason?: string; }> | { pass: boolean; reason?: string; }; } /** * G namespace — guard factories. * * All 21 methods from the Python G namespace. */ export declare class G { /** Custom guard function. */ static guard(fn: CallbackFn): GComposite; /** Validate that output is valid JSON. */ static json(): GComposite; /** Enforce max/min response length. */ static length(opts: { min?: number; max?: number; }): GComposite; /** Block or redact text matching a regex pattern. */ static regex(pattern: string | RegExp, opts?: { action?: "block" | "redact"; replacement?: string; }): GComposite; /** Validate output against a schema (e.g., Zod). */ static schema(zodSchema: { safeParse: (v: unknown) => { success: boolean; error?: unknown; }; }): GComposite; /** Validate model output against a schema class. */ static output(schemaCls: unknown): GComposite; /** Validate model input against a schema class. */ static input(schemaCls: unknown): GComposite; /** Enforce token budget. */ static budget(opts?: { maxTokens?: number; }): GComposite; /** Enforce requests-per-minute limit. */ static rateLimit(opts?: { rpm?: number; }): GComposite; /** Enforce maximum conversation turns. */ static maxTurns(n: number): GComposite; /** Detect and handle PII in output. */ static pii(opts?: { action?: "block" | "redact"; detector?: PIIDetector; threshold?: number; replacement?: string; }): GComposite; /** Block toxic content above threshold. */ static toxicity(opts?: { threshold?: number; judge?: ContentJudge; }): GComposite; /** Block output discussing denied topics. */ static topic(opts: { deny: string[]; }): GComposite; /** Require output to be grounded in provided sources. */ static grounded(opts?: { sourcesKey?: string; }): GComposite; /** Detect hallucinated content. */ static hallucination(opts?: { threshold?: number; sourcesKey?: string; judge?: ContentJudge; }): GComposite; /** Validate LLM-generated A2UI output. */ static a2ui(opts?: { maxComponents?: number; allowedTypes?: string[]; denyTypes?: string[]; }): GComposite; /** Conditionally apply a guard. */ static when(predicate: (state: State) => boolean, guard: GComposite): GComposite; /** Create a Google Cloud DLP PII detector. */ static dlp(opts?: { project?: string; infoTypes?: string[]; location?: string; }): PIIDetector; /** Create a regex-based PII detector. */ static regexDetector(patterns: (string | RegExp)[]): PIIDetector; /** Combine multiple PII detectors. */ static multi(...detectors: PIIDetector[]): PIIDetector; /** Wrap an async callable as a PII detector. */ static custom(fn: (text: string) => Promise | string[]): PIIDetector; /** Create an LLM-based content judge. */ static llmJudge(opts?: { model?: string; }): ContentJudge; /** Wrap an async callable as a content judge. */ static customJudge(fn: (text: string) => Promise<{ pass: boolean; reason?: string; }> | { pass: boolean; reason?: string; }): ContentJudge; } //# sourceMappingURL=guards.d.ts.map