Validator
The AIPCValidator checks LLM-generated narrative text against contract rules. It catches prohibited phrases, data reformatting, suppressed data leakage, and tone violations.
Why validate narrative?
Even with deterministic rendering (L2), the LLM still generates free-form narrative text. This narrative could inadvertently violate contract rules — using a prohibited phrase, re-stating a data value in a different format, or leaking a suppressed field. The Validator is the safety net that catches these violations before the response reaches the user.
The validate() API
The validate() method takes a ValidationInput and returns a ValidationResult:
import { AIPCValidator } from '@aipc/runtime';
const validator = new AIPCValidator();
const result = validator.validate({
narrativeText: llmGeneratedText,
validatedOutput: validatedOutput,
renderedOutput: renderedOutput,
narrativeContext: renderedOutput.narrativeContext
});
if (result.passed) {
// Narrative is compliant
} else {
// result.violations — array of Violation objects
// result.warnings — array of Warning objects
}
The 7 checks
The Validator runs seven checks against the LLM narrative, in order:
| # | Check | What it detects | Severity |
|---|---|---|---|
| 1 | Prohibited phrases | Exact match against the contract's prohibited phrase list triggers critical. Fuzzy match (stemming, synonyms) triggers major. | critical / major |
| 2 | Prohibited framing | Pattern-based detection of prohibited framing types (recommendation, advice, endorsement, comparison). | major |
| 3 | Editorial restrictions | Detects superlatives, urgency language, and personalized advice when the contract's editorial restrictions forbid them. | major |
| 4 | Data reformatting | Detects when the LLM re-states a formatted data value in a different format (e.g., writing "12.5%" when the deterministic block says "+12.47%"). | critical |
| 5 | Suppressed data leakage | Detects when suppressed fields appear in the narrative. The LLM should not have access to suppressed data, but this catches edge cases. | critical |
| 6 | Verbatim reproduction | Warns when the LLM duplicates text that already appears in deterministic blocks (disclosures, attribution). Redundancy, not a violation. | minor |
| 7 | Tone consistency | Checks the overall tone of the narrative against the contract's framing directive. Detects promotional language when informational is required. | major |
Severity and actions
Each violation has a severity level that maps to an enforcement action:
| Severity | Action | Description |
|---|---|---|
critical | suppress | The narrative is suppressed entirely. Only deterministic blocks are shown. |
major | redact / retry | The offending text is redacted, or the LLM is asked to regenerate with feedback. |
minor | pass with warning | The narrative is included but a warning is added to the audit trail. |
Fail behavior modes
The Validator's severity-to-action mapping can be adjusted using the contract's fail behavior:
strict— All major violations are escalated to critical. Any non-trivial violation suppresses the narrative.standard— The default matrix shown above. Critical suppresses, major redacts/retries, minor passes.lenient— Major violations are downgraded to minor. Only critical violations suppress the narrative.
Usage example
import { AIPCValidator } from '@aipc/runtime';
const validator = new AIPCValidator({ failBehavior: 'standard' });
const result = validator.validate({
narrativeText: llmNarrative,
validatedOutput: validatedOutput,
renderedOutput: rendered,
narrativeContext: rendered.narrativeContext
});
for (const v of result.violations) {
console.log(`[${v.severity}] ${v.check}: ${v.message}`);
// e.g., "[critical] prohibited_phrases: Found exact match 'guaranteed returns'"
}
for (const w of result.warnings) {
console.log(`[warning] ${w.check}: ${w.message}`);
}