UNPKG

@ai2070/l0

Version:

L0: The Missing Reliability Substrate for AI

98 lines (97 loc) 2.42 kB
import { hasMeaningfulContent } from "../utils/tokens"; const PUNCTUATION_ONLY = /^[^\w\s]+$/; const REPEATED_CHARS = /^(.)\1+$/; const ALPHANUMERIC = /[a-zA-Z0-9]/; function isZeroOutput(content) { if (!content || content.length === 0) { return true; } return !hasMeaningfulContent(content); } function isNoiseOnly(content) { if (!content || content.length === 0) { return true; } const trimmed = content.trim(); if (PUNCTUATION_ONLY.test(trimmed)) { return true; } if (REPEATED_CHARS.test(trimmed)) { return true; } if (trimmed.length < 3 && !ALPHANUMERIC.test(trimmed)) { return true; } return false; } function validateZeroOutput(context) { const { content, completed, tokenCount } = context; const violations = []; if (!completed && tokenCount < 5) { return violations; } if (isZeroOutput(content)) { violations.push({ rule: "zero-output", message: "No meaningful output generated (empty or whitespace only)", severity: "error", recoverable: true, // Transport/network issue - retry should help suggestion: "Retry - likely network or model initialization issue" }); return violations; } if (isNoiseOnly(content)) { violations.push({ rule: "zero-output", message: "Output contains only noise or filler characters", severity: "error", recoverable: true, suggestion: "Retry - output is not meaningful" }); return violations; } if (completed && content.trim().length < 1) { violations.push({ rule: "zero-output", message: "Output is empty", severity: "warning", recoverable: true, suggestion: "Retry - output may be truncated" }); } return violations; } function zeroOutputRule() { return { name: "zero-output", description: "Detects zero or meaningless output", streaming: true, severity: "error", recoverable: false, // Zero output is a transport issue, not model issue check: (context) => { return validateZeroOutput(context); } }; } class ZeroOutputGuardrail { rule; constructor() { this.rule = zeroOutputRule(); } check(context) { return this.rule.check(context); } get name() { return this.rule.name; } } export { ZeroOutputGuardrail, isNoiseOnly, isZeroOutput, validateZeroOutput, zeroOutputRule }; //# sourceMappingURL=zeroOutput.js.map