typescript import { z } from 'zod'; const itemSchema = z.object({ id: z.string(), value: z.number().positive(), }); type Item = z.infer; function parseAndValidateWithRecovery( rawLLMOutput: string, schema: z.ZodSchema ): { data: any | null; errors: z.ZodError | string | null; partialData?: any[] } { let parsedJson: any; let error: string | null = null; try { // Attempt standard parse parsedJson = JSON.parse(rawLLMOutput); } catch (e: any) { // Fallback: Attempt heuristic repair console.warn('JSON parse failed. Attempting heuristic repair...'); try { // Simplified repair: e.g., trim markdown code blocks and attempt parse again const jsonRegex = /