Detect anomalies, investigate failures, and repair data pipelines using AI agents and AWS services.

Imagine your data pipeline processes millions of records every day.

Your AWS Glue jobs are running. Your Amazon S3 data lake is receiving files. Your analytics dashboards are refreshing successfully.

Everything looks healthy.

But one morning, your business team reports that the revenue dashboard is showing incorrect numbers.

After investigating, you discover duplicate transactions, missing customer IDs, and unexpected changes in the source data schema.

Your monitoring system detected a problem, but it couldn't explain what happened.

An engineer now needs to inspect logs, compare schemas, investigate failed jobs, identify problematic records, and determine how to recover the pipeline.

What if an AI agent could help with this entire investigation?

What if it could detect anomalies, understand failures, recommend corrective actions, and coordinate a controlled repair process?

That's the idea behind building a Data Quality Agent using Amazon Bedrock.

In this article, we'll explore an AWS architecture that combines AI agents with data quality monitoring and automated pipeline recovery.

Why Do We Need an AI-Powered Data Quality Agent?

Traditional data quality systems are good at identifying problems.

For example, AWS Glue Data Quality can detect missing values, duplicate records, and invalid column values.

However, identifying a problem and understanding its root cause are two different things.

Imagine an e-commerce platform that normally processes 500,000 orders every day.

One morning, the pipeline processes only 280,000 records.

A data quality alert reports an unexpected reduction in record count.

But what caused it?

Perhaps an upstream application failed to deliver files. Maybe a source schema changed. It could also be an ingestion problem or an incorrect transformation.

An engineer must investigate the available evidence before taking action.

An AI-powered data quality agent can help bridge this gap by gathering information from AWS services, interpreting the evidence, and recommending a recovery strategy.

Understanding the Architecture

Our solution uses Amazon Bedrock as the intelligence layer and AWS services to handle data processing, orchestration, remediation, and monitoring.

The architecture follows this flow:

 DATA SOURCES | v Amazon S3 | v AWS Glue ETL | v AWS Glue Data Quality | v Amazon EventBridge | v AWS Step Functions | v Amazon Bedrock AI Data Agent | +--------+--------+ | | | v v v Inspect Analyze Recommend Glue Logs Repair Plan Jobs | | | +--------+--------+ | v Human Approval | v AWS Lambda Repair Actions | v Data Revalidation | v Validated Data in S3 | v Amazon CloudWatch 

Amazon S3 stores the datasets, while AWS Glue processes them.

AWS Glue Data Quality evaluates the data and identifies violations.

Amazon EventBridge routes supported events into AWS Step Functions, which coordinates the investigation and recovery workflow.

Amazon Bedrock powers the AI agent that analyzes the incident.

AWS Lambda executes approved remediation operations, while Amazon CloudWatch provides monitoring and operational visibility.

The key design principle is to separate detection, reasoning, orchestration, and execution.

Step 1: Detect Data Quality Issues with AWS Glue

Before introducing AI, we need reliable data quality checks.

AWS Glue Data Quality supports Data Quality Definition Language (DQDL), which allows us to define validation rules for datasets.

Imagine an orders dataset with the following columns:

Column Description
order_id Unique order identifier
customer_id Customer identifier
order_amount Transaction amount
order_status Order status
order_timestamp Transaction timestamp

We want to ensure that order IDs are present and unique, customer IDs are not missing, and transaction amounts are positive.

We can define these rules using DQDL:

Rules = [ IsComplete "order_id", IsUnique "order_id", IsComplete "customer_id", ColumnValues "order_amount" > 0, ColumnValues "order_status" in ["PENDING", "PAID", "SHIPPED", "CANCELLED"], IsComplete "order_timestamp" ] 

AWS Glue Data Quality evaluates the dataset against these rules and reports the results.

We can also monitor statistical patterns such as record counts and data distributions.

For example, an unexpected reduction in daily records could indicate an ingestion problem.

This gives our agent a reliable starting point for investigating data quality incidents.

Step 2: Use Amazon Bedrock for Intelligent Investigation

Now let's introduce Amazon Bedrock.

When a data quality incident occurs, we can provide the agent with structured information about the affected pipeline.

For example:

{ "pipeline": "orders-etl-pipeline", "job_status": "FAILED", "dataset": "orders", "issues": [ "Duplicate order IDs detected", "Missing customer IDs", "Schema drift detected" ], "affected_column": "order_amount", "expected_type": "decimal", "actual_type": "string" } 

The agent can interpret this information and investigate the incident.

It might discover that an upstream application changed the order_amount field from a decimal value to a string.

This change could cause downstream transformations to fail.

The agent can then recommend a solution that normalizes valid values, quarantines invalid records, and reprocesses the affected data.

Amazon Bedrock provides access to foundation models that can power this reasoning process.

For agent development, we can also explore Amazon Bedrock AgentCore for deploying and operating agents and the Strands Agents SDK for building tool-using agents.

Step 3: Give the Agent Tools to Investigate AWS Resources

An AI agent becomes much more useful when it can retrieve information from the systems responsible for the pipeline.

We can expose controlled tools that retrieve AWS Glue job status, inspect CloudWatch logs, access data quality results, compare schemas, and analyze dataset metrics.

For example, let's create a Python function using Boto3 to retrieve AWS Glue job execution details.

import boto3 glue = boto3.client("glue") def get_glue_job_status(job_name, run_id): response = glue.get_job_run( JobName=job_name, RunId=run_id, PredecessorsIncluded=False ) job_run = response["JobRun"] return { "job_name": job_name, "run_id": run_id, "status": job_run.get("JobRunState"), "error_message": job_run.get("ErrorMessage"), "started_on": str(job_run.get("StartedOn")), "completed_on": str(job_run.get("CompletedOn")) } 

The agent can call this tool when it needs additional information about a failed Glue job.

We can create similar tools for CloudWatch log retrieval, data quality inspection, and schema comparison.

Each tool should have a clearly defined purpose and restricted IAM permissions.

The agent should not have unrestricted access to production resources.

Step 4: Investigate Schema Drift

Let's look at a realistic scenario.

Our original dataset contains:

{ "order_id": "ORD-1001", "customer_id": "CUST-101", "order_amount": 249.99 } 

The order_amount field is numeric, so our ETL pipeline processes it correctly.

Now the upstream application changes its output:

{ "order_id": "ORD-1002", "customer_id": "CUST-102", "order_amount": "249.99 USD" } 

The field is now a string containing a currency suffix.

Our downstream transformation expects a decimal value, so the Glue job fails.

The Data Quality Agent investigates the schema difference and identifies the unexpected data type.

It can recommend normalizing valid values and quarantining records that cannot be converted safely.

Here is a simplified Python transformation:

from decimal import Decimal, InvalidOperation def normalize_order_amount(value): try: cleaned_value = str(value).replace(" USD", "").strip() amount = Decimal(cleaned_value) if amount < 0: raise ValueError("Negative order amount") return { "status": "VALID", "order_amount": str(amount) } except (InvalidOperation, ValueError): return { "status": "QUARANTINE", "original_value": str(value) } 

This is an illustrative transformation. A production implementation should also validate currency, precision, scale, locale-specific formats, and business rules.

Original source data should remain unchanged.

Valid records can move through the approved transformation, while invalid records remain available for investigation.

The AI agent recommends the repair, but controlled application code performs the transformation.

Step 5: Generate a Structured Repair Plan

After investigating the incident, the agent should produce a structured repair plan.

For example:

{ "incident_id": "DQ-2026-001", "severity": "HIGH", "root_cause": "Unexpected schema change", "affected_dataset": "orders", "affected_column": "order_amount", "recommended_actions": [ "Preserve original source files", "Validate the new source schema", "Normalize valid currency values", "Quarantine invalid records", "Reprocess affected partitions", "Run data quality validation" ], "requires_approval": true } 

This makes the agent's output easier to validate and pass between AWS services.

It also provides a useful audit trail.

The repair plan should explain the suspected root cause, supporting evidence, affected datasets, proposed changes, expected impact, and validation requirements.

Not every repair should be executed automatically.

For example, normalizing a known and approved currency format might be automated. Deleting production records or changing financial values should require human review.

Step 6: Orchestrate the Workflow with AWS Step Functions

After generating the repair plan, we need a reliable way to coordinate the recovery process.

AWS Step Functions can manage the entire workflow.

The process starts when a data quality incident is received.

Step Functions collects the available evidence and invokes the Bedrock agent.

The agent investigates the issue and generates a repair plan.

The workflow then checks whether human approval is required.

If approval is rejected, the incident can be escalated without executing the repair.

If approval is granted, Step Functions invokes the appropriate Lambda function.

After remediation, AWS Glue Data Quality evaluates the affected dataset again.

If validation succeeds, the workflow can allow the validated data to move forward.

If validation fails, the data remains quarantined and the incident is escalated.

Step Functions supports callback task patterns that allow a workflow to wait for an external human approval before continuing.

This approach is especially useful when remediation could affect financial reports, customer records, or production analytics.

Step 7: Add Organizational Knowledge with Amazon Bedrock Knowledge Bases

An AI agent can make better recommendations when it understands the organization's data definitions and operational procedures.

Most enterprise data teams maintain data dictionaries, source-to-target mappings, data contracts, ETL runbooks, business validation rules, and historical incident reports.

These documents can be made available through Amazon Bedrock Knowledge Bases.

Imagine that a customer data pipeline fails because the customer_id field is missing.

The agent retrieves the relevant data contract and discovers that this field is mandatory.

It also learns that customer identifiers cannot be generated automatically because they must come from the customer management system.

Instead of inventing a value, the agent can recommend quarantining the affected records and notifying the upstream application team.

This is an example of Retrieval-Augmented Generation (RAG).

The agent combines operational evidence with organizational knowledge to generate more relevant recommendations.

Step 8: Monitor Everything with Amazon CloudWatch

Building an intelligent pipeline is not enough.

We also need to monitor the agent and its supporting services.

Amazon CloudWatch can help track data quality incidents, failed Glue jobs, validation failures, investigation duration, repair success rates, quarantined records, and pipeline recovery time.

A dashboard can show whether recurring incidents are decreasing over time.

It can also reveal whether human reviewers frequently reject the agent's recommendations.

These metrics help engineering teams understand whether the solution is actually improving operations.

Investigation outputs, approval decisions, remediation results, and execution identifiers should also be retained for auditing.

Security: Keep AI-Controlled Remediation Safe

An AI agent that can read datasets, modify records, restart pipelines, and interact with production resources must operate under strict security controls.

Each tool should have only the permissions it needs, following the principle of least privilege.

Original source data should never be overwritten during remediation. Invalid records should be quarantined instead of silently discarded.

Every repair should be validated before the resulting data is published.

Sensitive information should be protected, and unnecessary personal or confidential data should not be sent to the model.

Source files, logs, and retrieved documents must also be treated as untrusted data. Their contents must not override the agent's instructions or security policies.

Most importantly, every recommendation and execution should be auditable.

The objective is not to create an AI agent that can change everything.

The objective is to create an AI agent that can investigate intelligently and operate safely within clearly defined boundaries.

Where Can We Use This Architecture?

This architecture is not limited to e-commerce.

Banking and financial services organizations could use it to investigate missing financial records, unusual transaction patterns, and unexpected changes in reporting datasets.

Healthcare analytics platforms could use it to validate incoming datasets and identify missing fields or unexpected changes in clinical data structures.

IoT and manufacturing platforms could use it to investigate missing telemetry, abnormal sensor readings, and unexpected data distributions.

Enterprise data warehouses and data lakehouses could use the same approach to monitor ingestion pipelines, validate datasets, and investigate failed transformations.

The architecture can be adapted to different industries by changing the validation rules, investigation tools, organizational knowledge, and remediation workflows.

A Practical Implementation Roadmap

You don't need to implement the entire system at once.

Start by storing raw datasets in Amazon S3, creating AWS Glue ETL jobs, defining DQDL rules, and capturing validation results.

Next, connect supported data quality events to EventBridge and use Step Functions to coordinate incident processing.

Once the detection workflow is working, introduce Amazon Bedrock and give the agent read-only investigation tools.

Allow it to retrieve job information, inspect logs, compare schemas, and generate structured incident reports.

After the investigation process becomes reliable, introduce controlled remediation through Lambda functions.

Add human approval for high-impact operations, quarantine invalid records, and run data quality checks after every repair.

Finally, use CloudWatch to monitor the complete workflow and evaluate its performance.

This incremental approach makes it easier to introduce AI into existing data engineering systems without compromising production reliability.

Final Thoughts

Data quality has always been one of the most important responsibilities in data engineering.

But traditional monitoring often stops at identifying the problem.

The next step is to build systems that can investigate failures, understand their context, recommend solutions, and support controlled recovery.

By combining AWS Glue Data Quality, Amazon Bedrock, Step Functions, Lambda, S3, and CloudWatch, we can create an intelligent data quality architecture that helps engineering teams respond to pipeline incidents more effectively.

The most important design principle is simple:

Let AI investigate and recommend. Let controlled workflows execute. Let validation prove that the repair worked.

The future of data engineering isn't just about building pipelines that process data.

It's about building pipelines that can understand when something goes wrong — and help us fix it.

AWS Resources

Explore the official documentation to learn more about the services used in this architecture:

What would you automate first in your data pipeline: anomaly detection, root-cause investigation, or data repair?

Share your thoughts in the comments!

AWS #AmazonBedrock #AWSGlue #DataEngineering #GenerativeAI