LLM-generated PLC code compiles but is unsafe, so this dev gated it behind a real compiler
hanuhanuhanuman · reddit · 2026-11-24
An engineer had LLM agents generate IEC 61131-3 PLC programs (ladder/FBD as PLCopen XML) and found "looks right" means little: raw output crashes the CODESYS importer (builds report 0 errors because nothing compiled), produces graph shapes real tools never make, or compiles yet is unsafe (set-dominant latches, re-triggering starts).
Four deterministic gates (the LLM never grades itself)
- Graph check: dangling refs, undeclared variables, missing power rails
- Safety audit: reset-dominant latch, rising-edge start, fail-safe (active-low) trip inputs
- Real compiler: headless CODESYS.exe (V3.5 SP21) import + build, must report 0 errors
- Scan-cycle tests: a test program on a CODESYS soft-PLC drives inputs scan by scan (e.g., start held while a trip clears → motor stays off)
Failures return as structured errors; passing programs get re-exported by CODESYS and indexed as retrieval examples. Two test programs (pump station ladder, conveyor FBD) pass all gates with 17- and 28-step tests; gates 1–2 take 1ms each. Known gap: the safety audit catches swapped latch types in FBD but not ladder.
Takeaway: for code with physical consequences, the vendor's own compiler and simulator beat any LLM-as-judge.
More from coding & agent
- AFK Pilot VS Code extension adds Gemini 4 Neon, hosts six coding agents — PawelHuryn · 2026-11-24
- Dev survey: 80% use terminal for coding agents, 50% merge code without second review — sergeykarayev · 2026-11-24
- Survey: 82% of engineers ship mostly agent-written code, 23% prompt from phones — sergeykarayev · 2026-11-24
- Weaviate Podcast #143 deep-dives AutoIndex and RAG retrieval optimization — CShorten30 · 2026-11-24
- Multica agents now report back: proactive results in the same chat, no polling — jiayuan_jy · 2026-11-24
- Routing strategy beats prompt tweaks: 40x impact on total LLM spend, plus a decision tree — rseroter · 2026-11-24