/** * Zod Schema Integration Interfaces * Provides type-safe schema validation and structured extraction */ import { z, ZodSchema, ZodType, ZodError } from 'zod'; import { VisionParserResult } from '../interfaces'; /** * Options for structured parsing with Zod schema */ export interface StructuredParseOptions { /** Zod schema for validation */ schema: T; /** Whether to enable structured extraction mode */ structured: boolean; /** Number of retry attempts on validation failure (default: 2) */ maxRetries?: number; /** Whether to return partial results on validation errors */ allowPartial?: boolean; /** Custom prompt to guide schema extraction */ schemaPrompt?: string; } /** * Result of structured parsing with validation */ export interface StructuredParseResult { /** Parsed and validated data matching the schema */ data: T; /** Raw vision parser result */ raw: VisionParserResult; /** Whether validation was successful */ isValid: boolean; /** Validation errors if any */ validationErrors?: ZodError; /** Number of retry attempts made */ retryCount: number; } /** * Schema-guided extraction configuration */ export interface SchemaGuidedConfig { /** Whether to use schema to generate extraction prompts */ generatePromptFromSchema: boolean; /** Custom prompt template with schema placeholders */ promptTemplate?: string; } /** * Validation result with detailed error reporting */ export interface ValidationResult { /** Whether validation passed */ success: boolean; /** Validated data if successful */ data?: T; /** Validation errors with field-level feedback */ errors?: Array<{ path: string[]; message: string; code: string; }>; } /** * Common predefined Zod schemas for document parsing */ export declare class CommonSchemas { /** * Invoice schema */ static Invoice: z.ZodObject<{ invoiceNumber: z.ZodString; date: z.ZodString; dueDate: z.ZodOptional; vendor: z.ZodObject<{ name: z.ZodString; address: z.ZodOptional; taxId: z.ZodOptional; }, "strip", z.ZodTypeAny, { name: string; address?: string | undefined; taxId?: string | undefined; }, { name: string; address?: string | undefined; taxId?: string | undefined; }>; customer: z.ZodObject<{ name: z.ZodString; address: z.ZodOptional; }, "strip", z.ZodTypeAny, { name: string; address?: string | undefined; }, { name: string; address?: string | undefined; }>; items: z.ZodArray, "many">; subtotal: z.ZodNumber; tax: z.ZodOptional; total: z.ZodNumber; currency: z.ZodOptional; }, "strip", z.ZodTypeAny, { invoiceNumber: string; date: string; vendor: { name: string; address?: string | undefined; taxId?: string | undefined; }; customer: { name: string; address?: string | undefined; }; total: number; items: { description: string; quantity: number; unitPrice: number; total: number; }[]; subtotal: number; dueDate?: string | undefined; tax?: number | undefined; currency?: string | undefined; }, { invoiceNumber: string; date: string; vendor: { name: string; address?: string | undefined; taxId?: string | undefined; }; customer: { name: string; address?: string | undefined; }; total: number; items: { description: string; quantity: number; unitPrice: number; total: number; }[]; subtotal: number; dueDate?: string | undefined; tax?: number | undefined; currency?: string | undefined; }>; /** * Receipt schema */ static Receipt: z.ZodObject<{ merchant: z.ZodString; date: z.ZodString; items: z.ZodArray; price: z.ZodNumber; }, "strip", z.ZodTypeAny, { name: string; price: number; quantity?: number | undefined; }, { name: string; price: number; quantity?: number | undefined; }>, "many">; subtotal: z.ZodNumber; tax: z.ZodOptional; total: z.ZodNumber; paymentMethod: z.ZodOptional; }, "strip", z.ZodTypeAny, { date: string; total: number; items: { name: string; price: number; quantity?: number | undefined; }[]; subtotal: number; merchant: string; tax?: number | undefined; paymentMethod?: string | undefined; }, { date: string; total: number; items: { name: string; price: number; quantity?: number | undefined; }[]; subtotal: number; merchant: string; tax?: number | undefined; paymentMethod?: string | undefined; }>; /** * Business card schema */ static BusinessCard: z.ZodObject<{ name: z.ZodString; title: z.ZodOptional; company: z.ZodOptional; email: z.ZodOptional; phone: z.ZodOptional; website: z.ZodOptional; address: z.ZodOptional; }, "strip", z.ZodTypeAny, { name: string; address?: string | undefined; title?: string | undefined; company?: string | undefined; email?: string | undefined; phone?: string | undefined; website?: string | undefined; }, { name: string; address?: string | undefined; title?: string | undefined; company?: string | undefined; email?: string | undefined; phone?: string | undefined; website?: string | undefined; }>; /** * Contract schema */ static Contract: z.ZodObject<{ title: z.ZodString; parties: z.ZodArray; }, "strip", z.ZodTypeAny, { name: string; role: string; address?: string | undefined; }, { name: string; role: string; address?: string | undefined; }>, "many">; effectiveDate: z.ZodString; expirationDate: z.ZodOptional; terms: z.ZodArray; obligations: z.ZodOptional, "many">>; signatures: z.ZodOptional, "many">>; }, "strip", z.ZodTypeAny, { title: string; parties: { name: string; role: string; address?: string | undefined; }[]; effectiveDate: string; terms: string[]; expirationDate?: string | undefined; obligations?: { party: string; obligation: string; }[] | undefined; signatures?: { date: string; party: string; signed: boolean; }[] | undefined; }, { title: string; parties: { name: string; role: string; address?: string | undefined; }[]; effectiveDate: string; terms: string[]; expirationDate?: string | undefined; obligations?: { party: string; obligation: string; }[] | undefined; signatures?: { date: string; party: string; signed: boolean; }[] | undefined; }>; /** * Research paper schema */ static ResearchPaper: z.ZodObject<{ title: z.ZodString; authors: z.ZodArray; abstract: z.ZodString; keywords: z.ZodOptional>; sections: z.ZodArray, "many">; references: z.ZodOptional>; publishedDate: z.ZodOptional; doi: z.ZodOptional; }, "strip", z.ZodTypeAny, { title: string; authors: string[]; abstract: string; sections: { title: string; content: string; }[]; keywords?: string[] | undefined; references?: string[] | undefined; publishedDate?: string | undefined; doi?: string | undefined; }, { title: string; authors: string[]; abstract: string; sections: { title: string; content: string; }[]; keywords?: string[] | undefined; references?: string[] | undefined; publishedDate?: string | undefined; doi?: string | undefined; }>; /** * Form data schema */ static FormData: z.ZodObject<{ formTitle: z.ZodOptional; fields: z.ZodArray; }, "strip", z.ZodTypeAny, { fieldName: string; fieldValue: string; fieldType?: string | undefined; }, { fieldName: string; fieldValue: string; fieldType?: string | undefined; }>, "many">; submissionDate: z.ZodOptional; }, "strip", z.ZodTypeAny, { fields: { fieldName: string; fieldValue: string; fieldType?: string | undefined; }[]; formTitle?: string | undefined; submissionDate?: string | undefined; }, { fields: { fieldName: string; fieldValue: string; fieldType?: string | undefined; }[]; formTitle?: string | undefined; submissionDate?: string | undefined; }>; /** * Table extraction schema */ static Table: z.ZodObject<{ title: z.ZodOptional; headers: z.ZodArray; rows: z.ZodArray, "many">; pageNumber: z.ZodOptional; }, "strip", z.ZodTypeAny, { headers: string[]; rows: string[][]; title?: string | undefined; pageNumber?: number | undefined; }, { headers: string[]; rows: string[][]; title?: string | undefined; pageNumber?: number | undefined; }>; } /** * Schema builder utility for creating custom schemas */ export declare class SchemaBuilder { /** * Create a schema from a plain object structure */ static fromObject(obj: Record): ZodSchema; /** * Generate prompt text from Zod schema */ static generatePromptFromSchema(schema: ZodType, schemaName?: string): string; } //# sourceMappingURL=zod-interfaces.d.ts.map