By Sagar Shankaran, Founder of CallSphere
Build a data quality pipeline that validates incoming data, deduplicates records with fuzzy matching, normalizes schemas, and ensures your AI agent's knowledge base stays clean and accurate.
Key takeaways
Data quality problems in traditional software cause bugs. Data quality problems in AI agent systems cause hallucinations, wrong answers delivered with high confidence, and eroded user trust. An agent that retrieves a duplicate record with conflicting information will synthesize contradictory responses. An agent working with unnormalized dates or inconsistent naming conventions will fail at basic comparisons.
A data quality pipeline sits between ingestion and storage, acting as a gatekeeper that rejects, repairs, or flags problematic data before it reaches your agent's knowledge base.
The first line of defense is schema validation. Every record entering your pipeline should conform to an expected structure with typed fields and constraints.
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
flowchart LR
SRC[("Sources<br/>DB, S3, APIs")]
EXT["Extract<br/>CDC or batch"]
STAGE[("Raw zone")]
XFRM["Transform<br/>dbt models"]
QUAL["Quality checks<br/>Great Expectations"]
CURATED[("Curated zone")]
LOAD["Load to warehouse"]
DW[("Snowflake or BigQuery")]
ML[("Feature store")]
SRC --> EXT --> STAGE --> XFRM --> QUAL --> CURATED --> LOAD
LOAD --> DW
LOAD --> ML
style XFRM fill:#4f46e5,stroke:#4338ca,color:#fff
style QUAL fill:#f59e0b,stroke:#d97706,color:#1f2937
style DW fill:#059669,stroke:#047857,color:#fff
from pydantic import BaseModel, Field, field_validator
from typing import Optional, List
from datetime import datetime
from enum import Enum
class DataQuality(str, Enum):
VALID = "valid"
REPAIRED = "repaired"
REJECTED = "rejected"
class KnowledgeRecord(BaseModel):
source_id: str = Field(min_length=1, max_length=256)
title: str = Field(min_length=5, max_length=500)
content: str = Field(min_length=50)
source_url: Optional[str] = None
tags: List[str] = Field(default_factory=list)
published_at: Optional[datetime] = None
@field_validator("content")
@classmethod
def content_not_boilerplate(cls, v):
boilerplate_phrases = [
"lorem ipsum", "click here to subscribe",
"cookie policy", "javascript is required",
]
lower = v.lower()
for phrase in boilerplate_phrases:
if phrase in lower and len(v) < 200:
raise ValueError(
f"Content appears to be boilerplate: {phrase}"
)
return v
@field_validator("title")
@classmethod
def title_not_generic(cls, v):
generic = ["untitled", "page", "home", "index", "null"]
if v.strip().lower() in generic:
raise ValueError(f"Title is generic: {v}")
return v.strip()
class ValidationResult:
def __init__(self):
self.valid = []
self.repaired = []
self.rejected = []
def summary(self) -> dict:
total = len(self.valid) + len(self.repaired) + len(self.rejected)
return {
"total": total,
"valid": len(self.valid),
"repaired": len(self.repaired),
"rejected": len(self.rejected),
"rejection_rate": len(self.rejected) / max(total, 1),
}
Exact deduplication catches identical records, but real-world duplicates are messier. The same article might appear with slightly different titles, extra whitespace, or minor edits. Fuzzy matching catches these near-duplicates.
from rapidfuzz import fuzz
from typing import List, Tuple
import hashlib
class FuzzyDeduplicator:
def __init__(
self,
title_threshold: int = 85,
content_threshold: int = 90,
):
self.title_threshold = title_threshold
self.content_threshold = content_threshold
self.seen_titles: List[Tuple[str, str]] = []
self.content_hashes: dict = {}
def is_duplicate(self, record: KnowledgeRecord) -> Tuple[bool, str]:
# Stage 1: exact content hash
content_hash = hashlib.sha256(
record.content.encode()
).hexdigest()
if content_hash in self.content_hashes:
return True, f"Exact duplicate of {self.content_hashes[content_hash]}"
self.content_hashes[content_hash] = record.source_id
# Stage 2: fuzzy title match
for existing_id, existing_title in self.seen_titles:
title_score = fuzz.ratio(
record.title.lower(), existing_title.lower()
)
if title_score >= self.title_threshold:
# Confirm with content similarity on first 500 chars
return True, f"Fuzzy title match ({title_score}%) with {existing_id}"
self.seen_titles.append((record.source_id, record.title))
return False, ""
Inconsistent formats make retrieval unreliable. Dates, company names, currencies, and units all need standardization.
import re
from datetime import datetime
from typing import Optional
class DataNormalizer:
def normalize(self, record: dict) -> dict:
normalized = {}
for key, value in record.items():
if isinstance(value, str):
value = self._clean_text(value)
normalized[key] = value
if "published_at" in normalized:
normalized["published_at"] = self._normalize_date(
normalized["published_at"]
)
if "company" in normalized:
normalized["company"] = self._normalize_company(
normalized["company"]
)
return normalized
def _clean_text(self, text: str) -> str:
# Collapse whitespace
text = re.sub(r"\s+", " ", text).strip()
# Remove zero-width characters
text = re.sub(r"[\u200b-\u200d\ufeff]", "", text)
# Normalize quotes
text = text.replace("\u201c", '"').replace("\u201d", '"')
text = text.replace("\u2018", "'").replace("\u2019", "'")
return text
def _normalize_date(self, date_str) -> Optional[str]:
if isinstance(date_str, datetime):
return date_str.isoformat()
formats = [
"%Y-%m-%d", "%m/%d/%Y", "%d/%m/%Y",
"%B %d, %Y", "%b %d, %Y", "%Y-%m-%dT%H:%M:%S",
]
for fmt in formats:
try:
return datetime.strptime(date_str, fmt).isoformat()
except (ValueError, TypeError):
continue
return None
def _normalize_company(self, name: str) -> str:
suffixes = [
" Inc.", " Inc", " LLC", " Ltd.",
" Ltd", " Corp.", " Corp", " Co.",
]
cleaned = name.strip()
for suffix in suffixes:
if cleaned.endswith(suffix):
cleaned = cleaned[: -len(suffix)].strip()
return cleaned
Combine all stages into a single pipeline that processes records in sequence.
class DataQualityPipeline:
def __init__(self):
self.normalizer = DataNormalizer()
self.deduplicator = FuzzyDeduplicator()
self.results = ValidationResult()
def process(self, raw_records: List[dict]) -> List[KnowledgeRecord]:
clean_records = []
for raw in raw_records:
# Stage 1: normalize
normalized = self.normalizer.normalize(raw)
# Stage 2: validate
try:
record = KnowledgeRecord(**normalized)
except Exception as e:
self.results.rejected.append(
{"data": raw, "reason": str(e)}
)
continue
# Stage 3: deduplicate
is_dup, reason = self.deduplicator.is_duplicate(record)
if is_dup:
self.results.rejected.append(
{"data": raw, "reason": f"Duplicate: {reason}"}
)
continue
self.results.valid.append(record)
clean_records.append(record)
return clean_records
Implement a repair stage between validation and rejection. If a record fails on a non-critical field like published_at, set a default value and mark the record as "repaired" in its metadata. Only reject records when critical fields like content or source_id fail validation. Track repair rates — a spike in repairs often signals an upstream data source problem.
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
Start with 85% for titles and 90% for content. Lower thresholds catch more duplicates but increase false positives — merging distinct articles that happen to share similar language. Run the deduplicator on a sample of your actual data and manually review the matches at your chosen threshold to calibrate.
Track validation metrics per pipeline run: rejection rate, repair rate, duplicate rate, and records per source. Set alerts when the rejection rate exceeds your baseline by more than two standard deviations. A sudden spike usually means an upstream source changed its format or started returning error pages.
#DataQuality #Validation #Deduplication #DataPipelines #AIAgents #AgenticAI #LearnAI #AIEngineering

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
How we built a fault-tolerant HVAC emergency triage and tech-dispatch platform on Kubernetes — three-tier CQRS, 11 micro-agents on the OpenAI Agents SDK + LangGraph, NATS JetStream, DTMF/SMS/WebSocket acceptance, circuit breakers, and an evaluation pipeline that catches regressions before they wake a tech at 3 AM.
Head-to-head: OpenAI Frontier and Anthropic's managed agent stack — strengths, fit, and what each means for enterprise AI voice and chat deployment.
Meta is building Hatch, a consumer AI agent that operates DoorDash, Reddit, and other third-party apps — Meta's answer to OpenClaw and Google Remy.
OpenAI Frontier — the new enterprise platform announced this week for building, deploying, and managing AI agents that do real work.
Q1 2026 saw a record acquisition wave: Aircall bought Vogent (May), Meta acquired Manus and PlayAI, OpenAI closed six deals. The voice AI consolidation phase has begun.
Microsoft's Copilot for Sales shipped 2026 updates that knit Dynamics, Outlook, and Teams into a single agentic surface. Here's the playbook, the per-seat pricing.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco