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)

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.

Original post →

More from coding & agent

coding & agent channel →