# prepare-chat-dataset

Turn raw chats into a clean fine-tune set: drop invalid rows, dedupe, strip PII (emails, phones, IDs, cards, IPs), render ChatML/Llama 3/Gemma templates and split train/valid JSONL.

- **Space:** llm-finetuning-public (https://github.com/Tech-Realm/space-llm-finetuning-public/tree/main/prepare-chat-dataset)
- **Level:** L2 (as the registry reports it)
- **Keys it needs (names only):** none
- **Tools:** python3
- **Routes:** python-stdlib; checks: 3
- **Uses:** new (no recorded use yet)
- **Install:** `logicpacks pack use llm-finetuning-public/prepare-chat-dataset` or MCP `get_pack llm-finetuning-public/prepare-chat-dataset`
- **Files:** CHANGELOG.md, code/make_fixture.py, code/prep.py, outcome/EVIDENCE.md, outcome/checks.yaml, outcome/results.json, pack.yaml, refs/refs.yaml, spec/SPEC.md, spec/source.md

## Purpose (spec/SPEC.md)

## Goal

A train.jsonl/valid.jsonl pair in messages format with no duplicates, no PII and only valid conversations, plus a rendered preview in the target model's chat template.

## Steps

1. Export the raw chats to JSONL: one {"messages": [...]} per conversation.
2. Run `python3 code/prep.py --in raw.jsonl --out data --template <chatml|llama3|gemma>` (pick the template of the base model).
3. Read the stats line: kept / dupes / invalid / pii. If invalid is high, fix the export, not the filter.
4. Open data/rendered.txt and check one example by eye (roles, special tokens).
5. Hand data/ to lora-finetune-mlx, qlora-finetune-4090 or hosted-finetune-apis.

## Edge cases

- Roman Urdu and Urdu script are kept as is; only PII patterns are replaced.
- Card numbers are replaced only when the Luhn check passes, so order numbers survive.
- Gemma has no system role: the system message is dropped in the Gemma preview only (the JSONL keeps it).

## Don'ts

- Don't train on WhatsApp/customer chats without running this first.
- Don't commit the real raw.jsonl or data/ to any repo; fixtures are synthetic.
- Don't trust the PII filter blindly for names and addresses: spot-check.



---

Canonical URL: https://logicpacks.io/packs/llm-finetuning-public/prepare-chat-dataset

Developed by TechRealm (techrealm.online), the software team. Operated by Al Jash Trading (Establishment), Abu Dhabi, since 1994, the legal entity that hosts and is responsible for the service. Economic licence CN-1030597, Abu Dhabi Registration Authority. Address: Office 5, Bani Yas West 4, Bani Yas, Abu Dhabi, UAE. Website: https://aljashtrading.com. Contact: hello@logicpacks.io, security@logicpacks.io, WhatsApp +1 713 632 2262 (https://wa.me/17136322262).

Machine-readable index: [/llms.txt](/llms.txt). Plain facts: [/about.md](/about.md). Safety: [/safety.md](/safety.md).
