规范驱动开发中的引用规范:LLM生成代码的输出确定性与自动幻觉检测的跨模型实证研究
Citation Discipline in Spec-Driven Development: A Cross-Model Empirical Study of Output Determinism and Automated Hallucination Detection in LLM-Generated Code
AI总结:
通过对比三种规范驱动开发框架,发现强制引用要求会降低输出确定性但能实现自动幻觉检测,该权衡在不同模型间一致。
摘要:
规范驱动开发(SDD)框架通过形式化规范指导大语言模型(LLM)生成代码,但它们在强制需求与生成代码之间可追溯性的方式上存在根本差异。本文通过两项受控实证研究比较了三种SDD框架:$traceSDD$,它使用分层REQ-XXX.Y.Z标识符强制每行需求引用;$Spec Kit$,通过用户故事和验收标准实现工件级可追溯性;以及$OpenSpec$,依赖事后外部追踪映射。我们在两个前沿LLM——Claude Sonnet 4.6(N=20,4个条件,240个实现)和GLM-5-turbo(N=50,4个条件,600个实现)上测量了两个主要结果:$输出确定性$(独立LLM会话间的词汇相似度)和$自动幻觉检测率$(TDR)。我们的预注册分析揭示了一个一致的、跨模型复现的权衡:无引用条件产生的确定性显著高于有引用条件(Claude:$d=-0.76$,$p=0.003$;GLM:$d=-0.72$,$p<0.001$),而只有有引用条件才能实现自动幻觉检测(TDR:Claude 86.4%,GLM 88.0%,所有替代方案为0%,两项研究FPR=0%)。traceSDD(有引用)在确定性上显著优于$Spec Kit$(Claude:$d=0.47$,$p=0.049$;GLM:$d=0.42$,$p=0.003$),但不优于OpenSpec(Claude:$d=0.18$,$p=0.44$;GLM:$d=0.14$,$p=0.32$)。这些发现表明,引用注释以确定性换取可验证性,且这种权衡在不同模型架构间普遍存在。
英文摘要:
Spec-Driven Development (SDD) frameworks guide Large Language Model (LLM)-powered code generation through formal specifications, yet they differ fundamentally in how they enforce traceability between requirements and generated code. This paper presents two controlled empirical studies comparing three SDD frameworks: $traceSDD$, which enforces mandatory per-line requirement citations using hierarchical REQ-XXX.Y.Z identifiers; $Spec Kit$, which uses artifact-level traceability through user stories and acceptance criteria; and $OpenSpec$, which relies on post-hoc external trace maps. We measure two primary outcomes across two frontier LLMs -- Claude Sonnet 4.6 (N=20, 4 conditions, 240 implementations) and GLM-5-turbo (N=50, 4 conditions, 600 implementations): $output$ $determinism$ (lexical similarity across independent LLM sessions) and $automated$ $hallucination$ $detection$ $rate$ (TDR). Our pre-registered analysis reveals a consistent, cross-model replicated trade-off: the uncited condition produces significantly higher determinism than the cited condition (Claude: $d=-0.76$, $p=0.003$; GLM: $d=-0.72$, $p<0.001$), while only the cited condition enables automated hallucination detection (TDR: Claude 86.4%, GLM 88.0%, vs 0% for all alternatives, FPR=0% across both studies). traceSDD (cited) significantly outperforms $Spec Kit$ on determinism (Claude: $d=0.47$, $p=0.049$; GLM: $d=0.42$, $p=0.003$) but not OpenSpec (Claude: $d=0.18$, $p=0.44$; GLM: $d=0.14$, $p=0.32$). These findings establish that citation annotations trade determinism for verifiability, and that this trade-off generalizes across model architectures.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。