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.
Data problems and their effects
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.
Choosing the validation tool
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.
| Tool | Best for | Output |
|---|---|---|
| Glue Data Quality | Rule-based checks on tables in pipelines | Rule results, scores, anomalies, pipeline stop |
| SageMaker Data Wrangler | Exploratory checks and visual fixes on tabular data | Data quality and insights reports |
| Lambda functions | Custom checks on documents and JSONL | Accept, quarantine, metrics |
| CloudWatch metrics and alarms | Tracking validation results over time | Alerts and dashboards |
The following diagram shows the checks and where each file ends up.

A document validation function
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.
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.