Universal Data Cleaner & Repair Engine for LLM Outputs (JSON & CSV)
llm-data-cleaner is a zero-dependency TypeScript package that safely parses, repairs, and normalizes messy or broken JSON and CSV/Tabular outputs generated by Large Language Models (OpenAI, Claude, Ollama, Llama, Gemini).
- 🛠️ LLM JSON Repair (
cleanJSON):- Strips markdown fences (
json ...) and conversational filler automatically. - Repairs truncated JSON (unclosed brackets
},], or open quotes") from streaming LLM responses. - Fixes single-quoted JSON properties and removes trailing commas.
- Strips markdown fences (
- 📊 LLM CSV & Markdown Table Cleaner (
cleanCSV):- Parses dirty CSV files and markdown tables (
| Col 1 | Col 2 |) into typed JS objects. - Normalizes header names automatically (
snake_case,camelCase,kebab-case). - Auto-casts numeric strings to
number,"true"/"false"toboolean, and empty strings tonull.
- Parses dirty CSV files and markdown tables (
- ⚡ Zero External Runtime Dependencies: Fast, lightweight string parsing engines.
npm install llm-data-cleaner
# or
yarn add llm-data-cleaner
# or
pnpm add llm-data-cleanerimport { cleanJSON } from 'llm-data-cleaner';
// Malformed string from an LLM stream with markdown fences, single quotes, and missing closing bracket
const rawLLMOutput = `\`\`\`json
{
'name': 'Ganesh',
'role': 'AI Backend Engineer',
'skills': ['TypeScript', 'Python',
\`\`\``;
const data = cleanJSON(rawLLMOutput);
console.log(data);
/*
Output (Clean, valid JavaScript object):
{
name: 'Ganesh',
role: 'AI Backend Engineer',
skills: ['TypeScript', 'Python']
}
*/import { cleanCSV } from 'llm-data-cleaner';
// Raw markdown table or CSV from an LLM output
const rawMarkdownTable = `
| Product Name | In Stock | Price |
|---|---|---|
| Mechanical Keyboard | true | 99.99 |
| Wireless Mouse | false | 29.50 |
`;
const rows = cleanCSV(rawMarkdownTable, {
headerCase: 'snake_case', // Formats headers to snake_case
autoCast: true, // Auto-casts "99.99" -> 99.99, "true" -> true
});
console.log(rows);
/*
Output (Typed JavaScript Array):
[
{ product_name: 'Mechanical Keyboard', in_stock: true, price: 99.99 },
{ product_name: 'Wireless Mouse', in_stock: false, price: 29.50 }
]
*/stripMarkdown(boolean, default:true): Stripjson ...code blocks.fallback(any, default:undefined): Optional fallback value if repair fails.
headerCase('snake_case' | 'camelCase' | 'kebab-case' | 'original', default:'snake_case')autoCast(boolean, default:true): Convert numeric/boolean strings to native types.emptyAsNull(boolean, default:true): Convert""fields tonull.trimWhitespace(boolean, default:true): Trim whitespace from keys & values.
MIT © 2026