Audit logs for AI bots that the bot cannot rewrite
If the bot box is ever involved in an incident, you need to show exactly what it saw, said and did. Design the logs so the bot itself can't edit them.
1. Log every exchange
Wrap calls to the local model so each prompt, response, model file hash and user is written as one JSON line.
import json, hashlib, time, getpass
def log(prompt, reply, model_sha):
rec = {"ts": time.time(), "user": getpass.getuser(), "model": model_sha,
"prompt": prompt, "reply": reply}
with open("/var/log/botaudit/chat.jsonl", "a") as f:
f.write(json.dumps(rec) + "\n")2. Make the file append-only
Root can set the append-only attribute; the bot's user then can add lines but not change or delete them.
sudo mkdir -p /var/log/botaudit && sudo touch /var/log/botaudit/chat.jsonl
sudo chown llm: /var/log/botaudit/chat.jsonl
sudo chattr +a /var/log/botaudit/chat.jsonl
lsattr /var/log/botaudit/chat.jsonl # shows the 'a' flag3. Chain the hashes
Each day, hash the log with the previous day's hash and write it down somewhere else (a printed logbook works). Any edit breaks the chain.
prev=$(tail -1 /var/log/botaudit/chain.txt | cut -f2)
today=$( (echo "$prev"; cat /var/log/botaudit/chat.jsonl) | sha256sum | cut -d' ' -f1)
echo -e "$(date -I)\t$today" | sudo tee -a /var/log/botaudit/chain.txt4. Watch with auditd
Record who touches the bot's config, model files and scripts:
sudo auditctl -w /opt/models -p wa -k bot_models
sudo auditctl -w /etc/systemd/system/llama.service -p wa -k bot_config
sudo ausearch -k bot_modelsPut the rules in /etc/audit/rules.d/ to persist them.
5. Ship copies off the box
Forward logs one-way to the site log server or SIEM in the same zone, so a compromised bot box can't erase history.
Where these facts come from
- ISA/IEC 62443 series: zones, conduits and security levels for industrial automation
- NIST SP 800-82 Rev. 3: Guide to Operational Technology (OT) security
- CISA: Industrial Control Systems: advisories and recommended practices
- Modbus Organization specifications: function codes and the TCP transport
- OPC Foundation: OPC UA specifications and security modes
- llama.cpp on GitHub: building and running local GGUF models on Linux
Checked Oct 29, 2026. Tutorials are educational. Follow your site's safety procedures, management-of-change process and the equipment maker's manual. Never test against live production equipment without authorization.
Industrial control with bots: all lessons → Next: 8. Human-in-the-loop: approval gates before anything moves →