实现流式输出的精准安全拦截,确保释放后无法回溯违规内容。
Withholding the Completing Chunk: Exact Release-Boundary Equivalence for Production Streaming Guardrails
- 用有限状态机构建可持久化检测器,实时判断每段输出是否合规。
- 在10万+测试案例中零误判,64字符块下处理速度达97.3毫秒/次。
- 适合需要严格流式内容过滤的生产系统,如AI客服、实时审核场景。
流式语言模型输出形成一个执行边界:一旦释放包含违规模式的完整片段,就无法召回。我们研究了一种生产级策略,其中每个有序家族是两个正则语言谓词的合取。增量匹配是经典方法,但关键在于在任意分块边界(包括前缀末尾词边界)释放时实现精确组合。本文定义了显式基于ASCII的策略语法,将每个谓词编译为持久化非确定有限自动机(NFA),区分稳定与临时断言状态,应用文档顺序家族优先级,并在每段释放前进行决策验证。结果表明,该监控器对声明语法中的任何策略都与吸收性累积预言机在释放边界上等价。生产级Python和TypeScript实现经101,653个分块案例及100,345个公开模拟案例验证,均未出现预言机、跨运行时或预期家族不一致。在冻结中性输出配置下,64字符块时增量与原生正则累积斜率分别为0.973和1.976;16,384字符块时增量中位延迟为30.2毫秒,原生累计扫描为96.6毫秒。原生正则在512字符块仍更快(12.4对比29.4毫秒),暴露常数因子交叉点而非掩盖。共享每流缓存上限与129符号字母表优化状态,测试峰值达4,096中364无绕过。结果是确定性回退下的策略合规,非语义安全或策略完备性的证据。
原文摘要 · Abstract (English)
Streaming language-model output creates an enforcement boundary: a control that detects a prohibited pattern after releasing its completing chunk cannot recall it. We study a production policy in which each ordered family is the conjunction of two regular-language predicates. Incremental matching is classical. The problem is exact composition at release time across arbitrary chunk partitions, including end-of-prefix word boundaries that can change on extension. We define an ASCII-explicit policy grammar, compile each predicate to a persistent nondeterministic finite automaton (NFA), distinguish stable from provisional assertion state, apply document-order family priority, and check the decision before releasing each chunk. We show that the resulting monitor is release-boundary equivalent to an absorbing cumulative oracle for every policy in the declared grammar. Production Python and TypeScript implementations were evaluated on 101,653 partitioned cases; a public surrogate added 100,345 cases. Both campaigns produced zero oracle, cross-runtime, or intended-family mismatches. In a frozen neutral-output profile, the memoized incremental and native-regex cumulative slopes at 64-character chunks were 0.973 and 1.976. At 16,384 characters the incremental median was 30.2 ms versus 96.6 ms for native cumulative scanning at that chunk size. Native regex remained faster at 512-character chunks (12.4 versus 29.4 ms), exposing the constant-factor crossover rather than hiding it. A shared per-stream cache cap and 129-symbol alphabet bound optimization state; the campaign peaked at 364 of 4,096 without bypass. The result is policy conformance for a deterministic backstop, not evidence of semantic safety or policy completeness.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。