Skip to content

About

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).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

🧹 llm-data-cleaner

Universal Data Cleaner & Repair Engine for LLM Outputs (JSON & CSV)

npm version License: MIT Build Status

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).


⚡ Key Features

  • 🛠️ 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.
  • 📊 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" to boolean, and empty strings to null.
  • ⚡ Zero External Runtime Dependencies: Fast, lightweight string parsing engines.

📦 Installation

npm install llm-data-cleaner
# or
yarn add llm-data-cleaner
# or
pnpm add llm-data-cleaner

🚀 Quick Start Examples

1. Repairing Malformed LLM JSON Outputs

import { 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']
}
*/

2. Cleaning LLM CSV & Markdown Tables

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 }
]
*/

⚙️ Options Reference

CleanJSONOptions

  • stripMarkdown (boolean, default: true): Strip json ... code blocks.
  • fallback (any, default: undefined): Optional fallback value if repair fails.

CleanCSVOptions

  • 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 to null.
  • trimWhitespace (boolean, default: true): Trim whitespace from keys & values.

🧪 License

MIT © 2026

About

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).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages