Lesson 5 of 5 Data Quality, Cleaning and Labeling

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.

The validation pipeline for the support-bot fine-tuning set, run in Step Functions. A structure check rejects 312 records missing assistant turns, Comprehend masks personal data in 6% of chats, ApplyGuardrail removes 85 chats quoting abusive language, and near-duplicate detection removes 9,000 copies of the same password-reset conversation, leaving a balanced, safe dataset.
The remaining count is approximate.
Spot the bug

A broken fine-tuning file

Exam skills 1.3.6 · 1.2.9

Find the three records that would fail or harm a conversational fine-tuning job.

Log in to try this activity Interactive activities are free with an account.

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.

Select all that apply

Check the content

Exam skills 1.3.6

Identify the checks that should run on prompt-response pairs before fine-tuning.

Log in to try this activity Interactive activities are free with an account.

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.

CheckTool or method
Valid JSONL, fields and rolesSchema validation script in the pipeline
Token limitsTokenizer counts per record
PIIComprehend PII detection, Macie for S3, Guardrails sensitive information filters
Toxicity and policyComprehend toxicity detection, ApplyGuardrail, LLM review
CorrectnessExpert review or comparison with source documents
DuplicatesExact and near-duplicate detection
Scenario questions

Screen the training data

Exam skills 1.3.6 · 4.3.9

Choose how to screen fine-tuning data for unsafe or sensitive content.

Log in to try this activity Interactive activities are free with an account.
Worked example

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.

Check yourself

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.