@ai2070/l0
Version:
L0: The Missing Reliability Substrate for AI
88 lines • 2.5 kB
JavaScript
import { hasMeaningfulContent } from "../utils/tokens";
const PUNCTUATION_ONLY = /^[^\w\s]+$/;
const REPEATED_CHARS = /^(.)\1+$/;
const ALPHANUMERIC = /[a-zA-Z0-9]/;
export function isZeroOutput(content) {
if (!content || content.length === 0) {
return true;
}
return !hasMeaningfulContent(content);
}
export 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;
}
export 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,
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;
}
export function zeroOutputRule() {
return {
name: "zero-output",
description: "Detects zero or meaningless output",
streaming: true,
severity: "error",
recoverable: false,
check: (context) => {
return validateZeroOutput(context);
},
};
}
export class ZeroOutputGuardrail {
rule;
constructor() {
this.rule = zeroOutputRule();
}
check(context) {
return this.rule.check(context);
}
get name() {
return this.rule.name;
}
}
//# sourceMappingURL=zeroOutput.js.map