UNPKG

llm-json-fix

Version:

Fix malformed JSON outputs from Large Language Models (LLMs)

43 lines 1.58 kB
/** * Patterns for detecting and handling LLM-specific JSON issues */ /** * Detects markdown code blocks and extracts the content * @param text Input text that may contain markdown code blocks * @returns The content of the first JSON code block, or null if none found */ export declare function extractJsonFromMarkdown(text: string): string | null; /** * Removes explanatory text that LLMs often include before/after JSON output */ export declare function stripExplanatoryText(text: string): string; /** * Fixes code block annotations that may have been erroneously included in the output */ export declare function stripCodeBlockAnnotations(text: string): string; /** * Removes trailing ellipses, which are often used by LLMs to indicate truncation * or continuation that isn't actual JSON data */ export declare function removeEllipses(text: string): string; /** * Remove explanations that LLMs sometimes insert as comments */ export declare function stripLLMComments(text: string): string; /** * Handle partial property names or incomplete strings at the end of the text */ export declare function fixTruncatedContent(text: string): string; /** * Try to balance JSON by fixing unclosed brackets */ export declare function balanceJsonStructure(text: string): string; /** * Fix incorrect handling of nested JSON strings */ export declare function fixNestedJsonStrings(text: string): string; /** * Main function to apply all LLM-specific fixes */ export declare function applyLLMSpecificFixes(text: string): string; //# sourceMappingURL=llmPatterns.d.ts.map