Skip to main content
Challenge

Software-Driven PLC Refactoring Agent using Mastra AI and Patronus AI

Transitioning proprietary legacy Ladder Logic to IEC 61131-3 Structured Text is slow and prone to syntax bugs. Build an automated code refactoring agent using Mastra AI and Patronus AI guardrails that transforms legacy PLC ladder diagrams into verified Structured Text. Pass 100% of static automated code policy safety assertions without breaking sequence logic.

EngineeringHosted by Vera
Challenge brief

What you are building

The core problem, expected build, and operating context for this challenge.

Construct a Mastra AI workflow with Patronus AI automated guardrail evaluations to translate and validate industrial ladder logic into structured control code.

Delivery guide

How work is evaluated

Evaluation

Evaluates generated Structured Text code against syntax correctness and Patronus safety policies.

Datasets

Challenge datasets

Public datasets, plus the private datasets you have access to.

Evaluation rubric

How submissions are scored

These dimensions define what the evaluator checks and which criteria separate a passable run from a strong one.

Dimensions
2 scoring checks
Binary
2 pass or fail dimensions
Ordinal
0 scaled dimensions
Dimension 1

patronus_guardrail_pass

Ensure zero safety policy violations detected by Patronus

Binary check

This dimension contributes its full weight only when the submission satisfies the requirement. Partial credit is not awarded.

Dimension 2

syntax_compilation_rate

Percentage of generated code blocks compiling without errors • target: 1 • range: 0-1

Binary check

This dimension contributes its full weight only when the submission satisfies the requirement. Partial credit is not awarded.

Learning goals

What you should walk away with

  • Build Mastra AI TypeScript workflows for parsing Structured Text from Ladder AST representations

  • Embed Patronus AI security and safety assertions into code generation evaluation loops

  • Ensure zero safety lock-out violations in generated PLC automation blocks

Resources and assets

Reference links and supporting material

Dataset notes

Dataset of 40 standard Ladder Logic control rung configurations and corresponding verified IEC 61131-3 reference snippets.

Challenge setup

Evaluates generated Structured Text code against syntax correctness and Patronus safety policies.

Challenge input

JSON representing ladder logic rungs and contacts

Mastra AI

Offers type-safe agent step composition and workflow execution in TypeScript.

Patronus AI

Provides strict domain assertion checks on LLM code generation outputs.

Evaluated output

String containing valid IEC 61131-3 Structured Text code

Evaluation checks
  • Ensure zero safety policy violations detected by Patronus
  • Percentage of generated code blocks compiling without errors • target: 1 • range: 0-1
Configured evaluation evidence
  • Benchmark: PLC Industrial Code Modernization (PLC-MOD-2025)
  • Syntax Compilation Rate target: 100%
  • 1 public reference case
Configured runtime
  • JavaScript execution harness
  • javascript sandbox (unavailable on Versalist)

Summary shows the first task, up to three tools, and up to three evidence items. Open the technical recipe to view all configured items.

View technical recipe

Configured tools

Action Space
  • Mastra AI · Required
Reward / Eval
  • Patronus AI · Optional
Safety / Guardrails
  • Patronus AI · Optional
Orchestration
  • Mastra AI · Required

Evaluation contract

  • patronus_guardrail_pass · Weight 1
  • syntax_compilation_rate · Weight 1

Metrics

  • syntax_compilation_rate · Target 1

Benchmarks

  • PLC Industrial Code Modernization (PLC-MOD-2025)
  • general

Reference cases

  • 1 public reference case

Workflow tasks

  1. Task 1

    Input: JSON representing ladder logic rungs and contacts

    Output: String containing valid IEC 61131-3 Structured Text code

    Execution harness: JavaScript

Evaluation tools

  • Mastra AI · Agent & Workflow Engine
  • Patronus AI · AI Guardrails Platform

Recipe freeze marker

No recipe freeze time is recorded.

Frequently Asked Questions about Software-Driven PLC Refactoring Agent using Mastra AI and Patronus AI