⚖️ AI Regulation & Ethics

Data Quality Management

Data Quality Management

A process that ensures the accuracy, completeness, and timeliness of AI training data. A key requirement for high-risk AI under the EU AI Act.

Detailed Explanation

Data Quality Management (DQM) is a systematic process for defining, measuring, monitoring, and improving data quality. Article 10(2) of the EU AI Act mandates "appropriate data governance and management practices" for the training data of high-risk AI, and quality management is a core part of these.

The DQM process consists of six stages: defining quality requirements, measuring quality (profiling), evaluating quality (against thresholds), root cause analysis, quality improvement actions, and continuous monitoring. In AI projects, these stages must be built into the training data preprocessing pipeline.

The EU AI Act specifies requirements of "relevance, representativeness, freedom from errors, and completeness" for the training data of high-risk AI (Article 10(3)). To meet them, data quality measurement results and improvement history must be documented and be available for submission upon request from market surveillance authorities.

In practice, a data quality dashboard is built to monitor real-time quality metrics. The circuit breaker pattern is recommended, which sends automatic alerts and halts the pipeline when quality degrades. Data that falls below the quality score threshold must be automatically excluded from model training.

Code Example

# 데이터 품질 관리 파이프라인 예제
from great_expectations.core import ExpectationSuite
from great_expectations.dataset import PandasDataset
import pandas as pd
from datetime import datetime
from typing import Dict, List
import json

class AIDataQualityManager:
    """EU AI Act 준수를 위한 데이터 품질 관리 시스템"""

    def __init__(self, quality_threshold: float = 0.8):
        self.quality_threshold = quality_threshold
        self.quality_history: List[Dict] = []

    def create_ai_act_expectations(self) -> ExpectationSuite:
        """EU AI Act 제10조 요구사항 기반 품질 규칙 생성"""
        suite = ExpectationSuite("ai_act_compliance")

        # 완전성 (Completeness) - 결측치 제한
        suite.add_expectation({
            "expectation_type": "expect_column_values_to_not_be_null",
            "kwargs": {"column": "*", "mostly": 0.95}
        })

        # 고유성 (Uniqueness) - 중복 제한
        suite.add_expectation({
            "expectation_type": "expect_compound_columns_to_be_unique",
            "kwargs": {"column_list": ["record_id"]}
        })

        # 유효성 (Validity) - 데이터 타입 및 범위
        suite.add_expectation({
            "expectation_type": "expect_column_values_to_be_between",
            "kwargs": {"column": "age", "min_value": 0, "max_value": 120}
        })

        return suite

    def validate_dataset(self, df: pd.DataFrame,
                          dataset_name: str) -> Dict:
        """데이터셋 품질 검증"""
        ge_df = PandasDataset(df)

        # 품질 차원별 측정
        quality_scores = {
            "completeness": 1 - df.isnull().sum().sum() / df.size,
            "uniqueness": 1 - df.duplicated().sum() / len(df),
            "validity": self._check_validity(df),
            "timeliness": 0.95,  # 실제로는 수집 시점 기반 계산
        }

        # 대표성 검사 (AI 특화)
        if "protected_attribute" in df.columns:
            quality_scores["representativeness"] = self._check_representativeness(df)

        # 종합 점수
        overall = sum(quality_scores.values()) / len(quality_scores)

        result = {
            "dataset_name": dataset_name,
            "timestamp": datetime.now().isoformat(),
            "record_count": len(df),
            "quality_scores": quality_scores,
            "overall_score": round(overall, 3),
            "ai_act_compliant": overall >= self.quality_threshold,
            "threshold": self.quality_threshold
        }

        self.quality_history.append(result)
        return result

    def _check_validity(self, df: pd.DataFrame) -> float:
        """유효성 검사 (커스텀 규칙 기반)"""
        valid_count = 0
        total_checks = 0

        for col in df.select_dtypes(include=['number']).columns:
            # 이상치 검사 (IQR 기반)
            Q1 = df[col].quantile(0.25)
            Q3 = df[col].quantile(0.75)
            IQR = Q3 - Q1
            outliers = ((df[col] < Q1 - 1.5*IQR) | (df[col] > Q3 + 1.5*IQR)).sum()
            valid_count += len(df) - outliers
            total_checks += len(df)

        return valid_count / total_checks if total_checks > 0 else 1.0

    def _check_representativeness(self, df: pd.DataFrame) -> float:
        """대표성 검사 (보호 속성 분포)"""
        # 이상적 분포와 실제 분포 비교
        ideal_dist = {"M": 0.5, "F": 0.5}
        actual_dist = df["protected_attribute"].value_counts(normalize=True)

        divergence = sum(
            abs(actual_dist.get(k, 0) - v)
            for k, v in ideal_dist.items()
        ) / 2

        return 1 - divergence

    def generate_compliance_report(self) -> str:
        """EU AI Act 감사용 컴플라이언스 보고서"""
        report = {
            "report_type": "EU_AI_Act_Article_10_Compliance",
            "generated_at": datetime.now().isoformat(),
            "quality_threshold": self.quality_threshold,
            "validation_history": self.quality_history,
            "overall_compliance_rate": sum(
                1 for h in self.quality_history if h["ai_act_compliant"]
            ) / len(self.quality_history) if self.quality_history else 0
        }
        return json.dumps(report, indent=2, ensure_ascii=False)

    def should_proceed_with_training(self, validation_result: Dict) -> bool:
        """학습 진행 여부 결정 (Circuit Breaker)"""
        if not validation_result["ai_act_compliant"]:
            print(f"[품질 차단] 품질 점수 {validation_result['overall_score']} < "
                  f"임계치 {self.quality_threshold}. 학습이 차단되었습니다.")
            return False
        print(f"[품질 통과] 학습을 진행합니다.")
        return True

# 사용 예시
dqm = AIDataQualityManager(quality_threshold=0.8)

df = pd.DataFrame({
    "record_id": [1, 2, 3, 4, 5],
    "age": [25, 30, 35, 40, 45],
    "income": [50000, None, 55000, 60000, 65000],
    "protected_attribute": ["M", "F", "M", "F", "M"]
})

result = dqm.validate_dataset(df, "training_data_v1")
print(f"품질 점수: {result['quality_scores']}")

if dqm.should_proceed_with_training(result):
    # model.fit(df)  # 학습 진행
    pass

Practical Conversation

CTO: We need to establish a data quality management framework before the EU AI Act takes effect. What is the current status?

DBA: We're only doing basic missing-value checks. Quality scoring and history management aren't in place.

Senior: I suggest adopting Great Expectations. It enables automatic blocking based on quality thresholds and audit log generation, and it integrates well into MLOps pipelines.

Interviewer: How did you implement data quality management in your AI project?

Candidate: I applied a six-stage DQM process. First, I defined quality requirements with domain experts, and implemented automated quality measurement with Great Expectations. If quality falls below the 80% threshold, the Airflow DAG is automatically halted and a Slack notification is sent. All quality measurement results are recorded as metrics in MLflow, enabling tracking by version, and reports for EU AI Act audits are also generated automatically.

Senior: The quality validation logic is mixed into the training code. It needs to be separated.

Junior: Where would be a good place to put it?

Senior: Validate right after data loading and before preprocessing. If quality falls short, throw an exception or return False so that subsequent steps are not executed. And be sure to log the validation results.

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

Cautions

Learn More