用验证反馈训练LLM,自动生成更安全的基础设施代码
TerraFormer: Automated Infrastructure-as-Code with LLMs Fine-Tuned via Policy-Guided Verifier Feedback
- 结合监督微调与验证引导的强化学习,提升代码生成准确性
- 在三大数据集上正确率比基础模型高15.9%至19.6%
- 适合关注云安全、自动化运维的研发人员
自动化基础设施即代码(IaC)面临挑战,大语言模型(LLMs)常从自然语言生成错误配置。我们提出TerraFormer,一种神经符号框架,通过形式化验证工具提供语法、可部署性及策略合规性反馈,结合监督微调与验证引导的强化学习。我们构建了两个高质量的自然语言到IaC数据集:TF-Gen(15.2万条)和TF-Mutn(5.2万条),通过多阶段验证与迭代式LLM自纠错获得。评估对比17个先进LLM,包括规模大50倍的Sonnet 3.7、DeepSeek-R1和GPT-4.1,TerraFormer在IaC-Eval上正确率提升15.94%,在TF-Gen(测试集)上提升11.65%,在TF-Mutn(测试集)上提升19.60%。其表现超越更大模型,在两数据集上领先,IaC-Eval排名第三,并达到最佳实践与安全合规最高水平。
原文摘要 · Abstract (English)
Automating Infrastructure-as-Code (IaC) is challenging, and large language models (LLMs) often produce incorrect configurations from natural language (NL). We present TerraFormer, a neuro-symbolic framework for IaC generation and mutation that combines supervised fine-tuning with verifier-guided reinforcement learning, using formal verification tools to provide feedback on syntax, deployability, and policy compliance. We curate two large, high-quality NL-to-IaC datasets, TF-Gen (152k instances) and TF-Mutn (52k instances), via multi-stage verification and iterative LLM self-correction. Evaluations against 17 state-of-the-art LLMs, including ~50x larger models like Sonnet 3.7, DeepSeek-R1, and GPT-4.1, show that TerraFormer improves correctness over its base LLM by 15.94% on IaC-Eval, 11.65% on TF-Gen (Test), and 19.60% on TF-Mutn (Test). It outperforms larger models on both TF-Gen (Test) and TF-Mutn (Test), ranks third on IaC-Eval, and achieves top best-practices and security compliance.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。