TechByteByByte

Data Engineering for AI

Level 7 begins here: AI applications are data-dependent — ingestion pipelines, validation, versioning, lineage, and governance for the data that feeds retrieval, evaluation, and feedback loops.

#AI Engineering#Data Engineering#Level 7

Begin with the problem

AI output quality depends on the data entering prompts, indexes, evaluations, and feedback loops. Bad or ungoverned data silently becomes bad system behavior.

sources → validate/clean → version + metadata → ingest/index → monitor freshness and lineage

What you will learn

  • Build ingestion pipelines with validation, metadata, lineage, and versioning.
  • Separate source documents, derived chunks, indexes, and evaluation data.
  • Protect the knowledge base from stale, unauthorized, or poisoned content.

Current production grounding: The OWASP Top 10 for LLM Applications documents risks including prompt injection, sensitive-information disclosure, and excessive agency.

These links document current public features and practices. They do not reveal a provider’s private implementation or guarantee that every product uses identical defaults.

1. The Engineering Problem

Every module so far has quietly assumed the data going into your system — documents for RAG, golden datasets for evaluation, feedback for improvement — is clean, current, and trustworthy. It usually isn’t, unless someone deliberately engineers it to be. This module covers the data pipeline discipline underneath every other AI Engineering practice this course has taught.


2. Why AI Applications Are Data-Dependent in a New Way

Traditional software: data flows THROUGH the system (a user's
                      order, a database record) -- the CODE'S logic
                      is independent of that data's
                      quality.

AI applications: data shapes behavior directly --
                 retrieved documents shape what RAG can answer
                 (Module 7), golden datasets shape what evaluation
                 can catch (Module 10), feedback data shapes what
                 gets improved (Module 20). Bad data doesn't just
                 produce a bad OUTPUT -- it degrades the SYSTEM'S
                 capability.

3. The Data Pipeline Types in an AI System

PipelineWhat It Feeds
Document ingestionRAG’s knowledge base (Module 7)
Golden dataset curationEvaluation (Module 10)
Feedback collectionModel/prompt improvement (Module 20)
Training data (if fine-tuning)Module 21’s fine-tuning discussion

Each needs the same underlying data engineering discipline: validation, cleaning, metadata, versioning, and lineage.


4. Data Validation and Cleaning — Before It Ever Reaches

Retrieval

Module 13's ingestion-scanning security discussion,
restated as a DATA QUALITY concern: a document with empty
content, missing source attribution, or obviously corrupted text
should be REJECTED at ingestion, not silently indexed and later
confusing retrieval.

5. Metadata and Lineage

METADATA: directly your RAG course's Module 9 -- document_id,
         section, access_control, created_at -- captured at ingestion, since it's often IMPOSSIBLE to reconstruct
         later.

DATA LINEAGE: tracking WHERE a piece of data came from
             and HOW it was transformed -- if a golden dataset
             example produces a surprising evaluation result, you
             need to trace it back to its ORIGINAL source
             to understand why.

6. Dataset Versioning

Module 5's prompt-versioning discipline, applied here to
DATA: your golden dataset (Module 10) and your RAG knowledge base
should be versioned artifacts -- when evaluation SCORES
change, you need to know whether the MODEL changed, the PROMPT
changed, or the underlying DATASET itself changed.

7. A Real-World Analogy — The Warehouse

A WAREHOUSE doesn't accept incoming shipments without checking them
against a manifest (VALIDATION), recording WHERE each item came
from and WHEN it arrived (METADATA/lineage), and tracking inventory
CHANGES over time (VERSIONING).

A warehouse that skips this discipline loses track of
what it actually has, where it came from and whether it's still
GOOD -- exactly the risk an AI system's data pipeline faces without
the same discipline.

8. Data Governance — Who Can Add, Change, or Remove Data

governance questions an AI data pipeline needs to answer:

  - WHO is authorized to add new documents to the knowledge base?
  - WHO can modify or REMOVE a golden dataset example?
  - Is SENSITIVE data (PII) flagged and handled per
    Module 13's security requirements?

Important clarification: Skipping governance is precisely how Module 13’s RAG-poisoning scenario happens — ANY process, including a user-submitted support ticket, that can add content to a retrievable knowledge base without review is a real, open door.

Why it matters: This shortcut removes a validation or control boundary, allowing an error to pass into later stages where it becomes harder and more expensive to detect.


9. A worked developer example

TechCorp’s document ingestion pipeline, showing validation catching a real problem before indexing:

DocumentValidation ResultOutcome
A well-formed policy document with a source attribution✅ PassedIndexed for retrieval
An empty file (a upload error)❌ Failed — empty contentRejected, never indexed
A document with no source attribution❌ Failed — missing metadataRejected — without a source, citations (your RAG course’s Module 23) would be impossible

10. How Is This Used in the Industry?

🤖 How Is This Used in the Industry?

Production AI teams treat data pipelines feeding RAG, evaluation, and feedback loops with software-engineering rigor — validation gates, versioned datasets, and lineage tracking, exactly the same discipline applied to any production data pipeline, because bad data degrades AI system quality in ways that are much harder to detect than a traditional application bug.


11. Common Mistakes

Incorrect idea: Indexing documents into a RAG knowledge base with no validation gate.

Why it is incorrect: As shown directly in Section 4 and 9, this allows corrupted or malicious content through.

Incorrect idea: Not capturing metadata at ingestion time.

Why it is incorrect: As shown directly in Section 5, this metadata is often impossible to reconstruct later.

Incorrect idea: No governance over who can add content to a retrievable knowledge base.

Why it is incorrect: As shown directly in Section 8, this is precisely how RAG poisoning (Module 13) becomes possible.


12. Code — A Document Ingestion Validation Gate

What this shows: a working validation gate that rejects malformed documents before they’re ever indexed — directly implementing Section 4’s validation principle and Section 9’s real developer example, catching exactly the kind of quality problem that would otherwise degrade RAG silently.

from dataclasses import dataclass
from enum import Enum
from datetime import datetime

class ValidationSeverity(Enum):
    ERROR = "error"
    WARNING = "warning"

@dataclass
class ValidationIssue:
    field: str
    severity: ValidationSeverity
    message: str

@dataclass
class DocumentRecord:
    doc_id: str
    content: str
    source: str
    ingested_at: str
    version: int = 1

class IngestionValidator:
    """A data validation gate (Section 4) -- checks
    structural and content quality BEFORE a document is indexed,
    directly connecting to Module 7's RAG poisoning concern and
    Module 13's ingestion scanning."""

    def validate(self, content: str, source: str) -> list:
        issues = []
        if not content or not content.strip():
            issues.append(ValidationIssue("content", ValidationSeverity.ERROR, "Document content is empty"))
        if len(content) > 0 and len(content) < 20:
            issues.append(ValidationIssue("content", ValidationSeverity.WARNING, "Content is suspiciously short"))
        if not source:
            issues.append(ValidationIssue("source", ValidationSeverity.ERROR, "Missing source attribution"))
        return issues

def ingest_document(content: str, source: str, validator: IngestionValidator) -> dict:
    """ingestion pipeline -- validates BEFORE creating a
    durable, versioned record (Section 6), never indexing
    unvalidated content."""
    issues = validator.validate(content, source)
    errors = [i for i in issues if i.severity == ValidationSeverity.ERROR]

    if errors:
        return {"ingested": False, "errors": [e.message for e in errors]}

    record = DocumentRecord(
        doc_id=f"doc_{hash(content) % 10000}",
        content=content, source=source,
        ingested_at=datetime.now().isoformat(),
    )
    return {"ingested": True, "record": record, "warnings": [i.message for i in issues if i.severity == ValidationSeverity.WARNING]}

validator = IngestionValidator()

# Exactly Section 9's first two rows
good_doc = ingest_document("International hotel reimbursement is limited to $200 per night.", "travel_policy_2026", validator)
empty_doc = ingest_document("", "unknown_source", validator)

print(f"Good document: ingested={good_doc['ingested']}")
print(f"Empty document: ingested={empty_doc['ingested']}, errors={empty_doc.get('errors')}")

Expected Output:

Good document: ingested=True
Empty document: ingested=False, errors=['Document content is empty']

What this confirms: the well-formed document is correctly accepted and indexed, while the empty document is rejected BEFORE ever reaching the retrievable knowledge base — exactly Section 9’s worked developer example, made into a working validation gate rather than trusting every uploaded document is automatically well-formed.


13. Production Considerations

  • Validation rules should evolve based on real ingestion failures observed in production — a fixed, never-updated rule set eventually misses new failure patterns
  • Store rejected documents (with their validation errors) for review — a high rejection rate for a specific source often signals an upstream data-quality problem worth fixing at the source

14. Trade-offs

  • Strict validation risks rejecting some legitimately unusual-but-valid documents (a very short but FAQ entry) — worth tuning thresholds against real data rather than defaults
  • Capturing comprehensive metadata and lineage adds real ingestion-pipeline complexity — worthwhile for the debugging and governance value it provides

15. Chapter Summary

AI applications are data-dependent in a deeper way than traditional software — data doesn’t just flow through the system, it directly shapes what the system can do (RAG’s knowledge, evaluation’s coverage, feedback’s improvement direction).

This makes data validation, metadata capture, versioning, lineage tracking, and governance engineering requirements, not optional data-hygiene nice-to-haves — directly underlying the RAG, evaluation, and feedback practices covered throughout this course.


16. Visual Cheat Sheet

Document -> VALIDATE (reject malformed/empty) -> capture METADATA
(Module 9 of your RAG course) -> VERSION -> index for retrieval

Bad data doesn't just produce a bad OUTPUT -- it degrades the
SYSTEM'S capability (RAG knowledge, eval coverage, feedback
direction).

17. Top Takeaways

  1. AI applications are data-dependent in a deeper way than traditional software — data directly shapes system capability, not just individual outputs.
  2. Document validation at ingestion should reject malformed or empty content before it’s indexed.
  3. Metadata should be captured at ingestion time — it’s often impossible to reconstruct later.
  4. Datasets (golden sets, knowledge bases) should be versioned, the same discipline as prompt versioning (Module 5).
  5. Governance — who can add or modify retrievable content — is a necessary control against RAG poisoning (Module 13).

18. Interview Questions

Q: 1. Why does bad data in an AI system cause a different kind of problem than bad data in traditional software?**

Ans: In traditional software, data flows through independent, deterministic logic — a bad record produces a bad result for that specific request, but doesn’t change the system’s underlying capability.

In an AI system, data directly shapes what the system can do — corrupted or malicious content in a RAG knowledge base degrades what questions can be answered correctly for EVERY future user, not just the request that ingested it.

  • Why it matters: This makes data validation a higher-stakes, systemic concern for AI systems specifically.
  • Real-world example: Directly connects to Module 13’s RAG poisoning scenario — one bad document can affect many future requests.
  • Common mistake: Treating data quality as a routine hygiene task rather than a systemic risk factor.
  • Interviewer is testing: Whether the candidate understands data’s structural role in AI systems, not just its presence.
  • Likely follow-up: “How would you catch a data quality problem before it affects users?” → Validation gates at ingestion (Section 12), plus evaluation (Module 10) monitoring for quality regressions.

Q: 2. What data governance controls would you put in place for a RAG knowledge base that accepts content from multiple internal teams?**

Ans: I’d require authorization for who can add content (not open, unreviewed submission), validate every submission against Section 4’s quality gate before indexing, capture full metadata and lineage (who submitted it, when, from what source) for every document, and scan new content for injection patterns (Module 13) before it’s ever indexed as retrievable knowledge.

  • Why it matters: Without these controls, a RAG knowledge base becomes an open door for both accidental data-quality problems and deliberate poisoning attacks.
  • Real-world example: Module 13’s scenario of a user-submitted ticket poisoning a “resolved tickets” knowledge base.
  • Common mistake: Assuming internal-only content sources don’t need the same governance rigor as external ones.
  • Interviewer is testing: Whether the candidate connects data governance directly to the security risks covered earlier in this course.
  • Likely follow-up: “How would you handle a legitimate need for fast, low-friction content updates alongside this governance?” → Tiered review — lightweight automated validation for routine updates, human review for anything touching sensitive or high-visibility content.

19. Scenario-Based Question

Scenario: TechCorp’s evaluation scores (Module 10) for their support assistant unexpectedly dropped after what the team believed was a routine, unrelated infrastructure change. Investigation eventually reveals the golden dataset used for evaluation was silently modified — three examples were removed by an engineer testing something unrelated, with no record of the change.

  • Problem Analysis: Section 6’s warning — no dataset versioning meant the team couldn’t distinguish “the model or prompt changed” from “the dataset itself changed.”
  • How to Think: This wasted significant investigation time chasing a model/prompt regression that didn’t exist — the dataset itself was the actual variable that changed.
  • Investigation: Compare the current golden dataset against a historical record — but without versioning, this comparison is only possible because the team happened to notice missing examples manually.
  • Root Cause: No dataset versioning or access control (Section 6, 8) — any engineer could modify the golden dataset with no tracked history.
  • Solution: Version the golden dataset the same way prompts are versioned (Module 5) — every change tracked, attributed, and reversible; restrict write access to authorized changes with review.
  • Trade-offs: Adding versioning and access control introduces real process friction for legitimate dataset updates — a worthwhile trade-off given the alternative is exactly this kind of hard-to-diagnose false regression.
  • Production Considerations: This scenario directly illustrates why Section 15 treats dataset versioning as equally important to prompt versioning — an unversioned, unprotected dataset is a blind spot in an otherwise well-evaluated system.

20. Next Step

Next: Module 19 — AI Application Memory — different types of memory (short-term, long-term, semantic, episodic), and when memory is useful versus when it adds unnecessary complexity.

Author
TechByteByByte Editorial Team
Reviewed by
TechByteByByte Admin
Published
Last reviewed