Constitutional Sanitization and Fine-Tuning for Robustness to Prompt Injection in LLM-Based Log Analysis
Abstract
Large language models (LLMs) are increasingly used in log-analysis workflows to summarize operational logs, alerts, tickets, and other external records. Because these records are untrusted data, they may contain malicious instructions. This paper studies indirect prompt injection in a scoped LLM-based loganalysis task where the model must preserve forensic information while refusing instruction-like text embedded in logs. We evaluate Qwen2.5-7B-Instruct and Llama 3.1 8B Instruct under No Defense, Delimiter-based Datamarking, Constitutional Sanitization, and low-rank adaptation (LoRA)-based supervised fine-tuning (SFT) conditions. Evaluation uses a frozen 1,000-row external validation set with 600 attacks and 400 benign logs, with source-lineage and near-duplicate checks against the original training and pilot data. On this set, Qwen SFT plus Sanitization reduces attack success rate (ASR) from 519/600 (86.50%) to 251/600 (41.83%), while Llama Sanitization reduces ASR from 329/600 (54.83%) to 59/600 (9.83%). These gains are not cost-free: Llama Sanitization blocks or refuses 97/400 benign logs, and its explanation BERTScore, a metric based on Bidirectional Encoder Representations from Transformers (BERT), is 0.6492 versus 0.8561 for No Defense. The results support a scoped defense strategy: sanitize untrusted log content, report security and utility together, and treat residual ASR and benign blocking as deployment-relevant trade-offs rather than claims of absolute security.