When to reach for it
- Data is received from unstructured or unreliable environments.
- Cognitive data quality is essential to prevent hallucinations downstream.
Sanitize the percepts before reasoning touches them.
A validation pattern — a dedicated gate that validates all incoming information (percepts) for quality and consistency before it ever reaches the model.
In practiceA support agent's CRM lookup starts returning a `status` field that changed from a fixed enum to free text; the integrator rejects the payload against its schema and raises a typed error, instead of letting the model reason over a value it would silently misread.
Data from outside passes a gate before the model sees it. The gate checks form and plausibility, and what fails becomes a clear error instead of context.
1 · Define
2 · On every input
| Incoming record | Check | Reaches the model |
|---|---|---|
| Status “active”, updated 3 days ago | Schema and ranges pass | The record |
| Status “see notes field” | The status is not one of the known values | An error: unexpected status |
| Credit limit of minus 5,000 | A limit must not be negative | An error: implausible credit limit |
| Last update 14 months ago | Older than 12 months | The record, marked as stale |
from datetime import datetime, timedelta
from enum import Enum
from pydantic import BaseModel, ValidationError
class Status(str, Enum):
active = "active"
paused = "paused"
closed = "closed"
class Customer(BaseModel):
status: Status
credit_limit: float
updated: datetime
class PerceptError(Exception):
"""Raised instead of handing doubtful data to the model."""
def integrate(raw: dict) -> dict:
try:
customer = Customer.model_validate(raw)
except ValidationError as error:
raise PerceptError(f"CRM record rejected: {error.errors()[0]['loc']}") from error
if customer.credit_limit < 0:
raise PerceptError("CRM record rejected: implausible credit limit")
stale = datetime.now() - customer.updated > timedelta(days=365)
# only this reaches the model
return {**customer.model_dump(), "stale": stale}When to reach for it
When it backfires
The integrator flags a payload as invalid and the rest of the graph processes it anyway because the flag was never wired into the downstream router.
Countermeasure
Reify the verdict as a typed state field. Add a conditional edge that routes invalid payloads to an explicit error branch.
Each malformed payload tightens the schema a little further, until a legitimate variant the upstream system has always sent is rejected too — and the run dead-ends with no path forward.
Countermeasure
Version the schema against the upstream system's documented contract, not against the last bad payload you saw; log rejected payloads with their reason so an over-tight rule becomes visible.
Keep going
Search patterns, frameworks, and pages.