Validating Fine-Tuning Data Before Customization
This lesson explains how fine-tuning and distillation datasets are validated before any customisation job, since errors, toxic content, personal data or poisoned examples in them are learned and reproduced.
Learning outcomes
After completing this lesson, you will be able to:
- Validate the structure of prompt-response records.
- Validate content for correctness and consistency.
- Screen examples for toxic content and personal data.
Structural validation of prompt-response pairs
Bedrock customisation jobs expect JSONL files in a precise format, such as records with prompt and completion fields or conversational records with a system prompt and alternating user and assistant messages. A single malformed line can fail the job. Validation should check that every line is valid JSON, that required fields and roles are present and correctly ordered, that token counts fit the model's limits, and that the number of records is within the job's minimum and maximum.
{"system": "You are a support assistant for Acme routers.",
"messages": [{"role": "user", "content": "How do I reset my router?"},
{"role": "assistant", "content": "Hold the reset button for 10 seconds..."}]}The following diagram shows the validation steps for a support chatbot's fine-tuning dataset and what each step removed.

A broken fine-tuning file
Content validation
Fine-tuning data must be validated for content as well as structure, because a model learns whatever the examples show. Correctness matters most: responses should be verified against source documents or by experts, because a model trained on wrong answers will repeat them confidently. Consistency matters too: the same question should not have contradictory answers, or the model learns to be unpredictable.
Duplicates over-weight some behaviours, so repeated examples are removed. Balance ensures that task types and topics are represented in proportion to real use, so the model does not become good at rare tasks and poor at common ones.
Check the content
Content safety screening
Screen every example for toxic or harmful content and for personal data. Amazon Comprehend detects PII entities and provides toxicity detection for text; the Bedrock ApplyGuardrail API evaluates text against a guardrail's content filters, denied topics and sensitive information filters without invoking a model; and an FM reviewer can flag policy violations at scale. Keep provenance metadata (source, date, licence) so that data found to be poisoned, unlicensed or subject to a deletion request can be removed and the model retrained.
The following table summarises the checks.
| Check | Tool or method |
|---|---|
| Valid JSONL, fields and roles | Schema validation script in the pipeline |
| Token limits | Tokenizer counts per record |
| PII | Comprehend PII detection, Macie for S3, Guardrails sensitive information filters |
| Toxicity and policy | Comprehend toxicity detection, ApplyGuardrail, LLM review |
| Correctness | Expert review or comparison with source documents |
| Duplicates | Exact and near-duplicate detection |
Screen the training data
A support-bot fine-tuning set
A team exports 40,000 resolved support chats to fine-tune a model. Before training, a validation pipeline runs in AWS Step Functions.
- A Lambda function validates JSONL structure and rejects 312 records with missing assistant turns.
- Comprehend PII detection finds email addresses and phone numbers in 6% of chats; they are masked.
- ApplyGuardrail flags 85 chats with abusive customer language as assistant replies quoted it; those are removed.
- Near-duplicate detection removes 9,000 copies of the same password-reset conversation to rebalance topics.
Without the rebalancing step, the fine-tuned model over-recommended password resets for unrelated problems, which shows that integrity covers distribution as well as safety.
How can text be checked against guardrail policies without calling a model?
Show answer
With the ApplyGuardrail API.
Exam Tips
Remember for the exam
- Validate JSONL structure and roles before starting a customisation job.
- Screen fine-tuning data for PII and toxicity.
- ApplyGuardrail evaluates text without calling a model.
- Remove near-duplicates to keep topics balanced.
- Keep provenance so poisoned or unlicensed data can be removed.