LLM4SFC: Sequential Function Chart Generation via Large Language Models

Ofek Glick, Vladimir Tchuiev, Marah Ghoummaid, Michal Moshkovitz, Dotan Di CastroarXiv 2025 · DOI

Introduction

In industrial automation, Programmable Logic Controllers (PLCs) are the foundational hardware for controlling manufacturing processes. While text-based languages like Structured Text (ST) are common, engineers frequently utilize Sequential Function Charts (SFCs)—a graphical language resembling flowcharts—to model complex, state-based workflows.

Despite the power of Large Language Models (LLMs) in code generation, SFCs present a unique challenge. The industry-standard format, PLCopen XML, is extremely verbose and laden with metadata that obscures the underlying logic. Furthermore, industrial code is often proprietary, creating a significant data scarcity problem. LLM4SFC is the first framework designed to bridge this gap, enabling the generation of machine-executable SFCs directly from natural language descriptions.

The LLM4SFC Framework

LLM4SFC treats SFC generation as a structured translation task, employing a multi-stage pipeline to transform user prompts into vendor-compatible code.

Overview of the LLM4SFC pipeline from natural language prompt to executable PLC code.

Core Components

  • SFC Reduced Representation: To overcome XML verbosity, the framework uses a "reduced representation" that captures only essential topology: step names, actions (in ST), transition conditions, and jumps. This representation is deterministically convertible back to standard XML.
  • Subgraph Masking: A novel fine-tuning strategy where models are trained to reconstruct missing clusters of steps and transitions. This teaches the LLM the structural "grammar" of industrial workflows.
  • Structured Generation: To eliminate syntax hallucinations, the system uses finite-state machine (FSM) based logit manipulation during decoding, forcing the model to adhere to a valid SFC schema.
  • Retrieval-Augmented Generation (RAG): The pipeline retrieves semantically similar SFC examples from a local database to provide few-shot context, aligning the output with specific programming conventions.

Experimental Setup and Dataset

The study utilized a custom dataset of 2,390 real-world SFCs sourced from 34 industrial manufacturing projects. Each entry includes raw PLCopen XML, the reduced representation, and a natural language summary generated by GPT-4o to serve as the user prompt. The dataset was split 80/10/10 for training, validation, and testing.

Performance was measured using the Pass@k metric (success in the top $k$ attempts) and a Safety@k metric, which utilizes the NuXmv symbolic model checker to verify properties like reachability and the absence of illegal parallel activations.

Results and Analysis

The framework demonstrates that while proprietary models are currently superior out-of-the-box, fine-tuned open-source models paired with structured decoding show significant promise.

Performance comparison of various LLMs on SFC generation and safety metrics.

Key Findings

  • Top Performers: OpenAI’s o3-mini achieved a near-perfect 99.2% generation success rate and a 99.1% safety score.
  • Open-Source Gains: The Qwen2.5-Coder-14B model, after fine-tuning with the subgraph masking objective, reached an impressive 81.8% success rate.
  • The Necessity of Constraints: For open-source models, unconstrained generation was largely ineffective (success rates ~15%). Enforcing structure via FSMs boosted success rates to over 70%, highlighting that decoding constraints are non-negotiable for graphical logic generation.

Conclusion and Future Work

LLM4SFC proves that LLMs can effectively generate complex graphical PLC logic by focusing on structural representations rather than raw XML metadata. However, limitations remain: the generated charts may lack visual optimization (leading to "spaghetti" diagrams in IDEs), and the models are currently manufacturing-specific. Future research will explore multi-modal models that can interpret and generate graphical charts directly, potentially removing the need for intermediate textual representations.

Summary updated

BibTeX
@misc{glick2025llm,
  author = {Ofek Glick and Vladimir Tchuiev and Marah Ghoummaid and Michal Moshkovitz and Dotan Di Castro},
  title = {{LLM4SFC: Sequential Function Chart Generation via Large Language Models}},
  year = {2025},
  eprint = {2512.06787},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2512.06787},
}
Figure