Lesson 1 of 4 Data Validation and Processing for FMs

Validating Data Before Foundation Models Consume It

This lesson covers the AWS tools for validation workflows that stop incomplete, corrupt, duplicate or out-of-date data before it reaches a model, since what an FM reads determines the quality of what it produces.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify what to validate in FM data.
  • Validate structured data with Glue Data Quality and SageMaker Data Wrangler.
  • Build custom checks for unstructured content with Lambda and CloudWatch.

What to validate

Data for foundation models fails in characteristic ways, and each failure has a recognisable effect on the application. Documents may be empty, unreadable because they are scanned images with no text layer, in the wrong language, duplicated across sources, truncated, or outdated versions of current documents. In a RAG application these faults produce answers with no source, answers based on superseded policies, or the same passage retrieved several times, crowding out other relevant content.

Structured records may have missing fields, invalid values or inconsistent formats, such as dates written in several styles. Fine-tuning datasets fail in their own ways: malformed JSON Lines, wrong role names, examples longer than the model's limit, duplicated examples or simply incorrect answers, which the model will learn faithfully. Each failure mode needs a specific check, and the checks should run automatically before ingestion or training, so that bad data is rejected or quarantined with a reason rather than discovered later through poor answers.

Match the pairs

Data problems and their effects

Exam skills 1.3.1

Match each data problem with the effect it usually has on a generative AI application.

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

AWS Glue Data Quality and SageMaker Data Wrangler

AWS Glue Data Quality evaluates rulesets written in Data Quality Definition Language (DQDL) against Data Catalog tables or inside Glue ETL jobs. Rules cover completeness, uniqueness, column values and lengths, freshness, referential integrity and custom SQL. Glue can recommend rules from data statistics, detect anomalies over time, and a job can stop or route failing records when a ruleset fails. Results are published to CloudWatch and EventBridge.

Rules = [
    IsComplete "document_id",
    IsUnique "document_id",
    ColumnLength "body" > 200,
    ColumnValues "language" in ["en", "de", "fr"],
    DataFreshness "last_modified" <= 30 days
]

SageMaker Data Wrangler, available in SageMaker Canvas, generates data quality and insights reports showing missing values, duplicates, outliers and distributions, and applies visual transformations to fix them. It suits exploratory validation of tabular data that will be summarised or used in prompts.

Scenario questions

Choosing the validation tool

Exam skills 1.3.1

Choose the validation tool that fits each data set.

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

Custom checks with Lambda and CloudWatch

Unstructured content usually needs custom checks. A Lambda function triggered by an S3 event can verify file type and size, extract text and reject documents with too little text, detect the language with Amazon Comprehend, compute a hash to find duplicates, validate JSONL lines against a schema and estimate token counts. Passing files move to a validated prefix that the knowledge base reads; failing files move to a quarantine prefix.

Each check publishes counts as CloudWatch metrics, for example DocumentsRejected by reason, using the embedded metric format in logs. Alarms on failure rates notify the data owner or stop the pipeline. The following table summarises the tools.

ToolBest forOutput
Glue Data QualityRule-based checks on tables in pipelinesRule results, scores, anomalies, pipeline stop
SageMaker Data WranglerExploratory checks and visual fixes on tabular dataData quality and insights reports
Lambda functionsCustom checks on documents and JSONLAccept, quarantine, metrics
CloudWatch metrics and alarmsTracking validation results over timeAlerts and dashboards

The following diagram shows the checks and where each file ends up.

Custom validation of documents on upload. An S3 event invokes a Lambda function that checks file type and size, extracted text, language, duplicates, JSONL schema and token count. Passing files move to the validated prefix that the knowledge base reads, failing files to a quarantine prefix, and rejection counts become CloudWatch metrics with alarms.
The prefix names are illustrative.
Put in order

A document validation function

Exam skills 1.3.1

Put the checks a Lambda validation function runs on each uploaded document in a sensible order.

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

Bad data in a knowledge base

A knowledge base answers poorly about some products. Investigation finds that 8% of uploaded PDFs are scanned images with no text, and many manuals exist in three outdated versions.

A validation step is missing. A Lambda function on upload extracts text, sends image-only files to a parsing path (for example Bedrock Data Automation or a foundation model parser), compares document IDs and versions to keep only the current version, and publishes metrics; an alarm notifies the content team when rejection rates rise. Only validated files reach the bucket prefix the knowledge base ingests.

Check yourself

Which service applies rule-based checks, written in DQDL, to tables in a data pipeline?

Show answer

AWS Glue Data Quality.

Exam Tips

Remember for the exam

  • Rule-based validation of tables in pipelines: Glue Data Quality with DQDL.
  • Exploratory data quality reports: SageMaker Data Wrangler.
  • Custom document and JSONL checks: Lambda with CloudWatch metrics.
  • Quarantine failing data before it is embedded or used for training.